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
728fb59e0d
commit
e575fb1aeb
2 changed files with 34 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
||||||
package firehose
|
package firehose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
@ -32,8 +33,18 @@ func ProcessRequestBody(b []byte) ([]byte, error) {
|
||||||
|
|
||||||
var dst []byte
|
var dst []byte
|
||||||
for _, r := range req.Records {
|
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
|
return dst, nil
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue