VictoriaMetrics/lib/protoparser/opentelemetry/firehose/parser_test.go

34 lines
13 KiB
Go
Raw Normal View History

package firehose
import (
"bytes"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/opentelemetry/stream"
"strings"
"testing"
)
func TestProcessRequestBody(t *testing.T) {
data := []byte(`{"requestId":"94885867-d282-4110-a3c5-4af3f9ce1150","timestamp":1709217414040,"records":[{"data":"oB0KnR0KuwEKFwoOY2xvdWQucHJvdmlkZXISBQoDYXdzCiIKEGNsb3VkLmFjY291bnQuaWQSDgoMNjc3NDM1ODkwNTk4ChsKDGNsb3VkLnJlZ2lvbhILCgl1cy1lYXN0LTEKXwoQYXdzLmV4cG9ydGVyLmFybhJLCklhcm46YXdzOmNsb3Vkd2F0Y2g6dXMtZWFzdC0xOjY3NzQzNTg5MDU5ODptZXRyaWMtc3RyZWFtL2N1c3RvbV9lYnNfbWV0cmljEtwbErEBCiNhbWF6b25hd3MuY29tL0FXUy9FQlMvVm9sdW1lUmVhZE9wcxoHe0NvdW50fVqAAQp+ChQKCU5hbWVzcGFjZRIHQVdTL0VCUwobCgpNZXRyaWNOYW1lEg1Wb2x1bWVSZWFkT3BzCiEKCFZvbHVtZUlkEhV2b2wtMDg2Y2ZjMTA4NTQwOGUwZGMRABjlKfhbuBcZAHAsIgZcuBchAQAAAAAAAAAyADIJCQAAAAAAAPA/ErEBCiNhbWF6b25hd3MuY29tL0FXUy9FQlMvVm9sdW1lUmVhZE9wcxoHe0NvdW50fVqAAQp+ChQKCU5hbWVzcGFjZRIHQVdTL0VCUwobCgpNZXRyaWNOYW1lEg1Wb2x1bWVSZWFkT3BzCiEKCFZvbHVtZUlkEhV2b2wtMDZkMDc4YWIxYmNjMDBlYzMRABjlKfhbuBcZAHAsIgZcuBchAQAAAAAAAAAyADIJCQAAAAAAAPA/ErEBCiNhbWF6b25hd3MuY29tL0FXUy9FQlMvVm9sdW1lUmVhZE9wcx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dW1lSWQSFXZvbC0wM2VlNzM1Y2VkZjFmNDZj
var totalTss []prompbmarshal.TimeSeries
err := stream.ParseStream(bytes.NewReader(data), false, ProcessRequestBody, func(tss []prompbmarshal.TimeSeries) error {
totalTss = append(totalTss, tss...)
for _, ts := range tss {
for _, label := range ts.Labels {
if label.Name == "__name__" {
if !strings.HasPrefix(label.Value, "amazonaws.com/AWS/EBS/VolumeReadOps") {
t.Fatalf("got %q, expected prefix amazonaws.com/AWS/EBS/VolumeReadOps", label.Value)
}
}
}
}
return nil
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(totalTss) == 0 {
t.Fatalf("unexpected number of series: %d", len(totalTss))
}
}