From 2f2299a26c0723d23fdc2035b756caaa48beb517 Mon Sep 17 00:00:00 2001 From: Trevor Whitney Date: Fri, 11 Oct 2024 10:47:04 -0600 Subject: [PATCH 1/2] fix: always write detected_level when enabled, even if unknown --- pkg/distributor/distributor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index 30383bfcbbbd4..f5a57d0b9ddef 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -501,7 +501,7 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log } else { logLevel = detectLogLevelFromLogEntry(entry, structuredMetadata) } - if logLevel != constants.LogLevelUnknown && logLevel != "" { + if logLevel != "" { entry.StructuredMetadata = append(entry.StructuredMetadata, logproto.LabelAdapter{ Name: constants.LevelLabel, Value: logLevel, From ceee803c5a408110fd1337d1ab4bacc2771083a2 Mon Sep 17 00:00:00 2001 From: shantanualshi Date: Mon, 14 Oct 2024 11:34:46 +0530 Subject: [PATCH 2/2] Fix test when detected_level is unknown --- pkg/distributor/distributor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/distributor/distributor_test.go b/pkg/distributor/distributor_test.go index 785d6ce03d0c3..ea06eecd45154 100644 --- a/pkg/distributor/distributor_test.go +++ b/pkg/distributor/distributor_test.go @@ -1640,7 +1640,7 @@ func Test_DetectLogLevels(t *testing.T) { require.NoError(t, err) topVal := ingester.Peek() require.Equal(t, `{foo="bar"}`, topVal.Streams[0].Labels) - require.Len(t, topVal.Streams[0].Entries[0].StructuredMetadata, 0) + require.Len(t, topVal.Streams[0].Entries[0].StructuredMetadata, 1) }) t.Run("log level detection enabled and warn logs", func(t *testing.T) {