From 41c6b6c2c2f5f56ca76cf75ed05689564b9e9dcd Mon Sep 17 00:00:00 2001 From: Trevor Whitney Date: Tue, 15 Oct 2024 10:15:24 -0600 Subject: [PATCH] fix: always write detected_level when enabled, even if unknown (#14464) Co-authored-by: shantanualshi --- pkg/distributor/distributor.go | 2 +- pkg/distributor/distributor_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index 6f69f0e02a84e..892384bef60bf 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -502,7 +502,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, 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) {