mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 08:26:19 +01:00
04d13f6149
- Document the ability to read OpenTelemetry data from Amazon Firehose at docs/CHANGELOG.md - Simplify parsing Firehose data. There is no need in trying to optimize the parsing with fastjson and byte slice tricks, since OpenTelemetry protocol is really slooow because of over-engineering. It is better to write clear code for better maintanability in the future. - Move Firehose parser from /lib/protoparser/firehose to lib/protoparser/opentelemetry/firehose, since it is used only by opentelemetry parser. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5893
40 lines
880 B
Go
40 lines
880 B
Go
package firehose
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// ProcessRequestBody converts Cloudwatch Stream protobuf metrics HTTP request body delivered via Firehose into OpenTelemetry protobuf message.
|
|
//
|
|
// See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Metric-Streams.html
|
|
//
|
|
// It joins decoded "data" fields from "record" list:
|
|
//
|
|
// {
|
|
// "requestId": "<uuid-string>",
|
|
// "timestamp": <int64-value>,
|
|
// "records": [
|
|
// {
|
|
// "data": "<base64-encoded-payload>"
|
|
// }
|
|
// ]
|
|
// }
|
|
func ProcessRequestBody(b []byte) ([]byte, error) {
|
|
var req struct {
|
|
Records []struct {
|
|
Data []byte
|
|
}
|
|
}
|
|
if err := json.Unmarshal(b, &req); err != nil {
|
|
return nil, fmt.Errorf("cannot unmarshal Firehose JSON in request body: %s", err)
|
|
}
|
|
|
|
var dst []byte
|
|
for _, r := range req.Records {
|
|
dst = append(dst, r.Data...)
|
|
}
|
|
|
|
return dst, nil
|
|
}
|