diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index ac815cbe82cdb..30383bfcbbbd4 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -1157,7 +1157,7 @@ func extractLogLevelFromLogLine(log string) string { return constants.LogLevelDebug case bytes.EqualFold(v, []byte("info")), bytes.EqualFold(v, []byte("inf")): return constants.LogLevelInfo - case bytes.EqualFold(v, []byte("warn")), bytes.EqualFold(v, []byte("wrn")): + case bytes.EqualFold(v, []byte("warn")), bytes.EqualFold(v, []byte("wrn")), bytes.EqualFold(v, []byte("warning")): return constants.LogLevelWarn case bytes.EqualFold(v, []byte("error")), bytes.EqualFold(v, []byte("err")): return constants.LogLevelError diff --git a/pkg/distributor/distributor_test.go b/pkg/distributor/distributor_test.go index 86afd0b1d659e..785d6ce03d0c3 100644 --- a/pkg/distributor/distributor_test.go +++ b/pkg/distributor/distributor_test.go @@ -1413,7 +1413,7 @@ func makeWriteRequestWithLabelsWithLevel(lines, size int, labels []string, level for j := 0; j < lines; j++ { // Construct the log line, honoring the input size - line := "msg=" + strconv.Itoa(j) + strings.Repeat("0", size) + " severity=" + level + line := "msg=an error occured " + strconv.Itoa(j) + strings.Repeat("0", size) + " severity=" + level stream.Entries = append(stream.Entries, logproto.Entry{ Timestamp: time.Now().Add(time.Duration(j) * time.Millisecond), @@ -1644,20 +1644,28 @@ func Test_DetectLogLevels(t *testing.T) { }) t.Run("log level detection enabled and warn logs", func(t *testing.T) { - limits, ingester := setup(true) - distributors, _ := prepare(t, 1, 5, limits, func(_ string) (ring_client.PoolClient, error) { return ingester, nil }) + for _, level := range []string{"warn", "Wrn", "WARNING"} { + limits, ingester := setup(true) + distributors, _ := prepare( + t, + 1, + 5, + limits, + func(_ string) (ring_client.PoolClient, error) { return ingester, nil }, + ) - writeReq := makeWriteRequestWithLabelsWithLevel(1, 10, []string{`{foo="bar"}`}, "warn") - _, err := distributors[0].Push(ctx, writeReq) - require.NoError(t, err) - topVal := ingester.Peek() - require.Equal(t, `{foo="bar"}`, topVal.Streams[0].Labels) - require.Equal(t, push.LabelsAdapter{ - { - Name: constants.LevelLabel, - Value: constants.LogLevelWarn, - }, - }, topVal.Streams[0].Entries[0].StructuredMetadata) + writeReq := makeWriteRequestWithLabelsWithLevel(1, 10, []string{`{foo="bar"}`}, level) + _, err := distributors[0].Push(ctx, writeReq) + require.NoError(t, err) + topVal := ingester.Peek() + require.Equal(t, `{foo="bar"}`, topVal.Streams[0].Labels) + require.Equal(t, push.LabelsAdapter{ + { + Name: constants.LevelLabel, + Value: constants.LogLevelWarn, + }, + }, topVal.Streams[0].Entries[0].StructuredMetadata, fmt.Sprintf("level: %s", level)) + } }) t.Run("log level detection enabled but log level already present in stream", func(t *testing.T) {