Skip to content

Commit

Permalink
Merge pull request #837 from AleksandrMatsko/fix/runtime-error-highes…
Browse files Browse the repository at this point in the history
…t-current

fix: runtime error highest current
  • Loading branch information
Civil authored Aug 6, 2024
2 parents 3bd2c2b + e28ace1 commit d23bc2b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
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

0 comments on commit d23bc2b

Please sign in to comment.