From 5cb0390dcdf81c2abe61317a90e2f714691468da Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 21 May 2024 14:45:24 +0200 Subject: [PATCH] wip --- lib/logstorage/stats_quantile.go | 11 +++++++---- lib/logstorage/stats_quantile_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/logstorage/stats_quantile.go b/lib/logstorage/stats_quantile.go index d7ac2352e..a9fcbdfb0 100644 --- a/lib/logstorage/stats_quantile.go +++ b/lib/logstorage/stats_quantile.go @@ -18,10 +18,11 @@ type statsQuantile struct { containsStar bool phi float64 + phiStr string } func (sq *statsQuantile) String() string { - return fmt.Sprintf("quantile(%g, %s)", sq.phi, fieldNamesString(sq.fields)) + return fmt.Sprintf("quantile(%s, %s)", sq.phiStr, fieldNamesString(sq.fields)) } func (sq *statsQuantile) updateNeededFields(neededFields fieldsSet) { @@ -186,12 +187,13 @@ func parseStatsQuantile(lex *lexer) (*statsQuantile, error) { } // Parse phi - phi, ok := tryParseFloat64(fields[0]) + phiStr := fields[0] + phi, ok := tryParseFloat64(phiStr) if !ok { - return nil, fmt.Errorf("phi arg in 'quantile' must be floating point number; got %q", fields[0]) + return nil, fmt.Errorf("phi arg in 'quantile' must be floating point number; got %q", phiStr) } if phi < 0 || phi > 1 { - return nil, fmt.Errorf("phi arg in 'quantile' must be in the range [0..1]; got %q", fields[0]) + return nil, fmt.Errorf("phi arg in 'quantile' must be in the range [0..1]; got %q", phiStr) } // Parse fields @@ -205,6 +207,7 @@ func parseStatsQuantile(lex *lexer) (*statsQuantile, error) { containsStar: slices.Contains(fields, "*"), phi: phi, + phiStr: phiStr, } return sq, nil } diff --git a/lib/logstorage/stats_quantile_test.go b/lib/logstorage/stats_quantile_test.go index f497258ad..8ce3847b6 100644 --- a/lib/logstorage/stats_quantile_test.go +++ b/lib/logstorage/stats_quantile_test.go @@ -5,6 +5,31 @@ import ( "testing" ) +func TestParseStatsQuantileSuccess(t *testing.T) { + f := func(pipeStr string) { + t.Helper() + expectParseStatsFuncSuccess(t, pipeStr) + } + + f(`quantile(0.3, *)`) + f(`quantile(1, a)`) + f(`quantile(0.99, a, b)`) +} + +func TestParseStatsQuantileFailure(t *testing.T) { + f := func(pipeStr string) { + t.Helper() + expectParseStatsFuncFailure(t, pipeStr) + } + + f(`quantile`) + f(`quantile(a)`) + f(`quantile(a, b)`) + f(`quantile(10, b)`) + f(`quantile(-1, b)`) + f(`quantile(0.5, b) c`) +} + func TestHistogramQuantile(t *testing.T) { f := func(a []float64, phi, qExpected float64) { t.Helper()