Skip to content

Commit 82d0a13

Browse files
Prevent panic in removeEmptySeries if series is nil and xFilesFactor is specified (#113)
* Prevent panic if nil series and xFilesFactor passed into removeBelowSeries * Add tests for preventing panic
1 parent 0edcffc commit 82d0a13

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

expr/functions/removeEmptySeries/function.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ func (f *removeEmptySeries) Do(ctx context.Context, e parser.Expr, from, until i
3737
if err != nil {
3838
return nil, err
3939
}
40+
if len(args) == 0 {
41+
return []*types.MetricData{}, nil
42+
}
4043

4144
if len(e.Args()) == 2 {
4245
xFilesFactor, err = e.GetFloatArgDefault(1, float64(args[0].XFilesFactor)) // If set by setXFilesFactor, all series in a list will have the same value

expr/functions/removeEmptySeries/function_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ func TestFunction(t *testing.T) {
137137
types.MakeMetricData("metric1", []float64{1, 2, -1, 7, 8, 20, 23, 12, 8, -2.3}, 1, now32),
138138
},
139139
},
140+
{
141+
"removeEmptySeries(metric*,0.5)", // Verify that passing in empty series with an xFilesFactor does not result in an error
142+
nil,
143+
[]*types.MetricData{},
144+
},
145+
{
146+
"removeZeroSeries(metric*,0.5)", // Verify that passing in empty series with an xFilesFactor does not result in an error
147+
nil,
148+
[]*types.MetricData{},
149+
},
140150
}
141151

142152
for _, tt := range tests {

0 commit comments

Comments
 (0)