Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: runtime error highest current #837

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions expr/functions/highestLowest/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func (f *highest) Do(ctx context.Context, eval interfaces.Evaluator, e parser.Ex
}
}

var results []*types.MetricData

// we have fewer arguments than we want result series
if len(arg) < n {
return arg, nil
Expand Down Expand Up @@ -100,6 +98,12 @@ func (f *highest) Do(ctx context.Context, eval interfaces.Evaluator, e parser.Ex
return nil, fmt.Errorf("unsupported function %v", e.Target())
}

var results []*types.MetricData

if n <= 0 {
return results, nil
}

if isHighest {
for i, a := range arg {
m := compute(a.Values)
Expand Down
33 changes: 33 additions & 0 deletions expr/functions/highestLowest/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ func TestHighest(t *testing.T) {
[]*types.MetricData{types.MakeMetricData("metricB", // NOTE(dgryski): not sure if this matches graphite
[]float64{2, 5, 5, 5, 5, 5}, 1, now32)},
},
{
"highestCurrent(metric1,0)",
map[parser.MetricRequest][]*types.MetricData{
parser.MetricRequest{Metric: "metric1", From: 0, Until: 1}: {
types.MakeMetricData("metricA", []float64{1, 1, 3, 3, 4, 12}, 1, now32),
types.MakeMetricData("metricB", []float64{1, 1, 3, 3, 4, 1}, 1, now32),
types.MakeMetricData("metricC", []float64{1, 1, 3, 3, 4, 15}, 1, now32),
},
},
[]*types.MetricData{},
},
{
"highest(metric1,\"max\")",
map[parser.MetricRequest][]*types.MetricData{
Expand All @@ -243,6 +254,28 @@ func TestHighest(t *testing.T) {
[]*types.MetricData{types.MakeMetricData("metricA",
[]float64{1, 1, 3, 3, 12, 11}, 1, now32)},
},
{
"highest(metric1, 0, \"max\")",
map[parser.MetricRequest][]*types.MetricData{
{Metric: "metric1", From: 0, Until: 1}: {
types.MakeMetricData("metricA", []float64{1, 1, 3, 3, 12, 11}, 1, now32),
types.MakeMetricData("metricB", []float64{1, 1, 3, 3, 4, 1}, 1, now32),
types.MakeMetricData("metricC", []float64{1, 1, 3, 3, 4, 10}, 1, now32),
},
},
[]*types.MetricData{},
},
{
"highest(metric1, -1, \"max\")",
map[parser.MetricRequest][]*types.MetricData{
{Metric: "metric1", From: 0, Until: 1}: {
types.MakeMetricData("metricA", []float64{1, 1, 3, 3, 12, 11}, 1, now32),
types.MakeMetricData("metricB", []float64{1, 1, 3, 3, 4, 1}, 1, now32),
types.MakeMetricData("metricC", []float64{1, 1, 3, 3, 4, 10}, 1, now32),
},
},
[]*types.MetricData{},
},
{
"lowest(metric1,\"max\")",
map[parser.MetricRequest][]*types.MetricData{
Expand Down
Loading