Skip to content

Commit 887db47

Browse files
committed
fix: level detection for warning level (#14444)
1 parent 5dadb6d commit 887db47

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

pkg/distributor/distributor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ func extractLogLevelFromLogLine(log string) string {
11571157
return constants.LogLevelDebug
11581158
case bytes.EqualFold(v, []byte("info")), bytes.EqualFold(v, []byte("inf")):
11591159
return constants.LogLevelInfo
1160-
case bytes.EqualFold(v, []byte("warn")), bytes.EqualFold(v, []byte("wrn")):
1160+
case bytes.EqualFold(v, []byte("warn")), bytes.EqualFold(v, []byte("wrn")), bytes.EqualFold(v, []byte("warning")):
11611161
return constants.LogLevelWarn
11621162
case bytes.EqualFold(v, []byte("error")), bytes.EqualFold(v, []byte("err")):
11631163
return constants.LogLevelError

pkg/distributor/distributor_test.go

+22-14
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ func makeWriteRequestWithLabelsWithLevel(lines, size int, labels []string, level
14131413

14141414
for j := 0; j < lines; j++ {
14151415
// Construct the log line, honoring the input size
1416-
line := "msg=" + strconv.Itoa(j) + strings.Repeat("0", size) + " severity=" + level
1416+
line := "msg=an error occured " + strconv.Itoa(j) + strings.Repeat("0", size) + " severity=" + level
14171417

14181418
stream.Entries = append(stream.Entries, logproto.Entry{
14191419
Timestamp: time.Now().Add(time.Duration(j) * time.Millisecond),
@@ -1644,20 +1644,28 @@ func Test_DetectLogLevels(t *testing.T) {
16441644
})
16451645

16461646
t.Run("log level detection enabled and warn logs", func(t *testing.T) {
1647-
limits, ingester := setup(true)
1648-
distributors, _ := prepare(t, 1, 5, limits, func(_ string) (ring_client.PoolClient, error) { return ingester, nil })
1647+
for _, level := range []string{"warn", "Wrn", "WARNING"} {
1648+
limits, ingester := setup(true)
1649+
distributors, _ := prepare(
1650+
t,
1651+
1,
1652+
5,
1653+
limits,
1654+
func(_ string) (ring_client.PoolClient, error) { return ingester, nil },
1655+
)
16491656

1650-
writeReq := makeWriteRequestWithLabelsWithLevel(1, 10, []string{`{foo="bar"}`}, "warn")
1651-
_, err := distributors[0].Push(ctx, writeReq)
1652-
require.NoError(t, err)
1653-
topVal := ingester.Peek()
1654-
require.Equal(t, `{foo="bar"}`, topVal.Streams[0].Labels)
1655-
require.Equal(t, push.LabelsAdapter{
1656-
{
1657-
Name: constants.LevelLabel,
1658-
Value: constants.LogLevelWarn,
1659-
},
1660-
}, topVal.Streams[0].Entries[0].StructuredMetadata)
1657+
writeReq := makeWriteRequestWithLabelsWithLevel(1, 10, []string{`{foo="bar"}`}, level)
1658+
_, err := distributors[0].Push(ctx, writeReq)
1659+
require.NoError(t, err)
1660+
topVal := ingester.Peek()
1661+
require.Equal(t, `{foo="bar"}`, topVal.Streams[0].Labels)
1662+
require.Equal(t, push.LabelsAdapter{
1663+
{
1664+
Name: constants.LevelLabel,
1665+
Value: constants.LogLevelWarn,
1666+
},
1667+
}, topVal.Streams[0].Entries[0].StructuredMetadata, fmt.Sprintf("level: %s", level))
1668+
}
16611669
})
16621670

16631671
t.Run("log level detection enabled but log level already present in stream", func(t *testing.T) {

0 commit comments

Comments
 (0)