diff --git a/src/query/graphite/native/builtin_functions.go b/src/query/graphite/native/builtin_functions.go index c92e30cec7..2d71520ddd 100644 --- a/src/query/graphite/native/builtin_functions.go +++ b/src/query/graphite/native/builtin_functions.go @@ -94,6 +94,11 @@ func sortByMaxima(ctx *common.Context, series singlePathSpec) (ts.SeriesList, er return highestMax(ctx, series, len(series.Values)) } +// sortByMinima sorts timeseries by the minimum value across the time period specified. +func sortByMinima(ctx *common.Context, series singlePathSpec) (ts.SeriesList, error) { + return lowest(ctx, series, len(series.Values), "min") +} + type valueComparator func(v, threshold float64) bool func compareByFunction( @@ -2267,6 +2272,7 @@ func init() { MustRegisterFunction(scale) MustRegisterFunction(scaleToSeconds) MustRegisterFunction(sortByMaxima) + MustRegisterFunction(sortByMinima) MustRegisterFunction(sortByName) MustRegisterFunction(sortByTotal) MustRegisterFunction(squareRoot) diff --git a/src/query/graphite/native/builtin_functions_test.go b/src/query/graphite/native/builtin_functions_test.go index 837c8593c2..e9a206b0b0 100644 --- a/src/query/graphite/native/builtin_functions_test.go +++ b/src/query/graphite/native/builtin_functions_test.go @@ -191,6 +191,10 @@ func TestSortByMaxima(t *testing.T) { testSortingFuncs(t, sortByMaxima, []int{4, 0, 3, 2, 1}) } +func TestSortByMinima(t *testing.T) { + testSortingFuncs(t, sortByMinima, []int{1, 3, 2, 4, 0}) +} + func TestAbsolute(t *testing.T) { ctx := common.NewTestContext() defer ctx.Close() @@ -3360,6 +3364,7 @@ func TestFunctionsRegistered(t *testing.T) { "scale", "scaleToSeconds", "sortByMaxima", + "sortByMinima", "sortByName", "sortByTotal", "squareRoot",