mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
opentelemetry: fix firehose message parsing (#5899)
Co-authored-by: Andrii Chubatiuk <wachy@Andriis-MBP-2.lan>
This commit is contained in:
parent
fdf0cc9f25
commit
bf9cb84575
2 changed files with 34 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
|||
package firehose
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
@ -32,8 +33,18 @@ func ProcessRequestBody(b []byte) ([]byte, error) {
|
|||
|
||||
var dst []byte
|
||||
for _, r := range req.Records {
|
||||
dst = append(dst, r.Data...)
|
||||
for len(r.Data) > 0 {
|
||||
messageLength, varIntLength := binary.Uvarint(r.Data)
|
||||
if varIntLength > binary.MaxVarintLen32 {
|
||||
return nil, fmt.Errorf("failed to parse OpenTelemetry message: invalid variant")
|
||||
}
|
||||
totalLength := varIntLength + int(messageLength)
|
||||
if totalLength > len(r.Data) {
|
||||
return nil, fmt.Errorf("failed to parse OpenTelementry message: insufficient length of buffer")
|
||||
}
|
||||
dst = append(dst, r.Data[varIntLength:totalLength]...)
|
||||
r.Data = r.Data[totalLength:]
|
||||
}
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue