Skip to content

Commit

Permalink
[query] Implemented the Graphite sortByMinima function
Browse files Browse the repository at this point in the history
  • Loading branch information
teddywahle authored Sep 28, 2020
1 parent a7b499d commit 66b0b24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/query/graphite/native/builtin_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -2267,6 +2272,7 @@ func init() {
MustRegisterFunction(scale)
MustRegisterFunction(scaleToSeconds)
MustRegisterFunction(sortByMaxima)
MustRegisterFunction(sortByMinima)
MustRegisterFunction(sortByName)
MustRegisterFunction(sortByTotal)
MustRegisterFunction(squareRoot)
Expand Down
5 changes: 5 additions & 0 deletions src/query/graphite/native/builtin_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -3360,6 +3364,7 @@ func TestFunctionsRegistered(t *testing.T) {
"scale",
"scaleToSeconds",
"sortByMaxima",
"sortByMinima",
"sortByName",
"sortByTotal",
"squareRoot",
Expand Down

0 comments on commit 66b0b24

Please sign in to comment.