VictoriaMetrics/lib/logstorage/stats_row_max_test.go

287 lines
3.7 KiB
Go
Raw Normal View History

2024-05-22 21:01:20 +02:00
package logstorage
import (
"testing"
)
2024-05-30 16:19:23 +02:00
func TestParseStatsRowMaxSuccess(t *testing.T) {
2024-05-22 21:01:20 +02:00
f := func(pipeStr string) {
t.Helper()
expectParseStatsFuncSuccess(t, pipeStr)
}
2024-05-30 16:19:23 +02:00
f(`row_max(foo)`)
f(`row_max(foo, bar)`)
f(`row_max(foo, bar, baz)`)
2024-05-22 21:01:20 +02:00
}
2024-05-30 16:19:23 +02:00
func TestParseStatsRowMaxFailure(t *testing.T) {
2024-05-22 21:01:20 +02:00
f := func(pipeStr string) {
t.Helper()
expectParseStatsFuncFailure(t, pipeStr)
}
2024-05-30 16:19:23 +02:00
f(`row_max`)
f(`row_max()`)
f(`row_max(x) bar`)
2024-05-22 21:01:20 +02:00
}
2024-05-30 16:19:23 +02:00
func TestStatsRowMax(t *testing.T) {
2024-05-22 21:01:20 +02:00
f := func(pipeStr string, rows, rowsExpected [][]Field) {
t.Helper()
expectPipeResults(t, pipeStr, rows, rowsExpected)
}
2024-05-30 16:19:23 +02:00
f("stats row_max(a) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `54`},
},
}, [][]Field{
{
{"x", `{"a":"3","b":"54"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats row_max(foo) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `54`},
},
}, [][]Field{
{
{"x", `{}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats row_max(b, a) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `54`},
{"c", "1232"},
},
}, [][]Field{
{
{"x", `{"a":"3"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats row_max(b, a, x, b) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `54`},
{"c", "1232"},
},
}, [][]Field{
{
{"x", `{"a":"3","b":"54"}`},
2024-05-22 21:01:20 +02:00
},
})
2024-05-30 16:19:23 +02:00
f("stats row_max(a) if (b:*) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `54`},
},
}, [][]Field{
{
{"x", `{"a":"3","b":"54"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats by (b) row_max(a) if (b:*) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `-12.34`},
{"b", "3"},
},
{
{"a", `3`},
{"c", `54`},
},
}, [][]Field{
{
{"b", "3"},
{"x", `{"_msg":"abc","a":"2","b":"3"}`},
},
{
{"b", ""},
{"x", `{}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats by (a) row_max(b) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `1`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `5`},
},
{
{"a", `3`},
{"b", `7`},
},
}, [][]Field{
{
{"a", "1"},
{"x", `{"_msg":"abc","a":"1","b":"3"}`},
},
{
{"a", "3"},
{"x", `{"a":"3","b":"7"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats by (a) row_max(c) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `1`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"c", `foo`},
},
{
{"a", `3`},
{"b", `7`},
},
}, [][]Field{
{
{"a", "1"},
{"x", `{}`},
},
{
{"a", "3"},
{"x", `{"a":"3","c":"foo"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats by (a) row_max(b, c) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `1`},
{"b", `34`},
},
{
{"_msg", `def`},
{"a", `1`},
{"c", "3"},
},
{
{"a", `3`},
{"b", `5`},
{"c", "foo"},
},
{
{"a", `3`},
{"b", `7`},
{"c", "bar"},
},
}, [][]Field{
{
{"a", "1"},
{"x", `{}`},
2024-05-22 21:01:20 +02:00
},
{
{"a", "3"},
{"x", `{"c":"bar"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats by (a, b) row_max(c) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `1`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
{"c", "foo"},
},
{
{"a", `3`},
{"b", `5`},
{"c", "4"},
},
}, [][]Field{
{
{"a", "1"},
{"b", "3"},
{"x", `{}`},
},
{
{"a", "1"},
{"b", ""},
2024-05-25 21:36:16 +02:00
{"x", `{"_msg":"def","a":"1","c":"foo"}`},
2024-05-22 21:01:20 +02:00
},
{
{"a", "3"},
{"b", "5"},
{"x", `{"a":"3","b":"5","c":"4"}`},
},
})
}