From 7b0aaf1ea2c8c7b4611892e1954a0daac415dad3 Mon Sep 17 00:00:00 2001 From: f41gh7 Date: Wed, 4 Sep 2024 15:20:32 +0200 Subject: [PATCH] follow-up after 01430a155c79a9306596b48e745e100d4ae98dca * properly check SeverityNumber at FormatSeverity function it could be negative, which could cause panic for victorialogs --- app/vlinsert/opentelemetry/opentelemetry_test.go | 4 +++- lib/protoparser/opentelemetry/pb/logs.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/vlinsert/opentelemetry/opentelemetry_test.go b/app/vlinsert/opentelemetry/opentelemetry_test.go index fa856af42..254d9f21b 100644 --- a/app/vlinsert/opentelemetry/opentelemetry_test.go +++ b/app/vlinsert/opentelemetry/opentelemetry_test.go @@ -60,13 +60,15 @@ func TestPushProtoOk(t *testing.T) { LogRecords: []pb.LogRecord{ {Attributes: []*pb.KeyValue{}, TimeUnixNano: 1234, SeverityNumber: 1, Body: pb.AnyValue{StringValue: ptrTo("log-line-message")}}, {Attributes: []*pb.KeyValue{}, TimeUnixNano: 1235, SeverityNumber: 21, Body: pb.AnyValue{StringValue: ptrTo("log-line-message-msg-2")}}, + {Attributes: []*pb.KeyValue{}, TimeUnixNano: 1236, SeverityNumber: -1, Body: pb.AnyValue{StringValue: ptrTo("log-line-message-msg-2")}}, }, }, }, }, }, - []int64{1234, 1235}, + []int64{1234, 1235, 1236}, `{"logger":"context","instance_id":"10","node_taints":"[{\"Key\":\"role\",\"Value\":{\"StringValue\":\"dev\",\"BoolValue\":null,\"IntValue\":null,\"DoubleValue\":null,\"ArrayValue\":null,\"KeyValueList\":null,\"BytesValue\":null}},{\"Key\":\"cluster_load_percent\",\"Value\":{\"StringValue\":null,\"BoolValue\":null,\"IntValue\":null,\"DoubleValue\":0.55,\"ArrayValue\":null,\"KeyValueList\":null,\"BytesValue\":null}}]","_msg":"log-line-message","severity":"Trace"} +{"logger":"context","instance_id":"10","node_taints":"[{\"Key\":\"role\",\"Value\":{\"StringValue\":\"dev\",\"BoolValue\":null,\"IntValue\":null,\"DoubleValue\":null,\"ArrayValue\":null,\"KeyValueList\":null,\"BytesValue\":null}},{\"Key\":\"cluster_load_percent\",\"Value\":{\"StringValue\":null,\"BoolValue\":null,\"IntValue\":null,\"DoubleValue\":0.55,\"ArrayValue\":null,\"KeyValueList\":null,\"BytesValue\":null}}]","_msg":"log-line-message-msg-2","severity":"Unspecified"} {"logger":"context","instance_id":"10","node_taints":"[{\"Key\":\"role\",\"Value\":{\"StringValue\":\"dev\",\"BoolValue\":null,\"IntValue\":null,\"DoubleValue\":null,\"ArrayValue\":null,\"KeyValueList\":null,\"BytesValue\":null}},{\"Key\":\"cluster_load_percent\",\"Value\":{\"StringValue\":null,\"BoolValue\":null,\"IntValue\":null,\"DoubleValue\":0.55,\"ArrayValue\":null,\"KeyValueList\":null,\"BytesValue\":null}}]","_msg":"log-line-message-msg-2","severity":"Unspecified"}`, ) diff --git a/lib/protoparser/opentelemetry/pb/logs.go b/lib/protoparser/opentelemetry/pb/logs.go index 6bbac31b2..3bbe6e478 100644 --- a/lib/protoparser/opentelemetry/pb/logs.go +++ b/lib/protoparser/opentelemetry/pb/logs.go @@ -250,7 +250,7 @@ func (lr *LogRecord) FormatSeverity() string { if lr.SeverityText != "" { return lr.SeverityText } - if lr.SeverityNumber > int32(len(logSeverities)-1) { + if lr.SeverityNumber < 0 || lr.SeverityNumber >= int32(len(logSeverities)) { return logSeverities[0] } return logSeverities[lr.SeverityNumber]