Skip to content

Commit

Permalink
support removeEmptySeries xFilesFactor
Browse files Browse the repository at this point in the history
  • Loading branch information
faceair authored and Civil committed Jan 15, 2021
1 parent 2243e28 commit 4348948
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
23 changes: 17 additions & 6 deletions expr/functions/removeEmptySeries/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,30 @@ func (f *removeEmptySeries) Do(ctx context.Context, e parser.Expr, from, until i
return nil, err
}

// TODO: implement xFilesFactor
factor, err := e.GetFloatArgDefault(1, 0)
if err != nil {
return nil, err
}

var results []*types.MetricData

for _, a := range args {
for _, v := range a.Values {
for _, arg := range args {
nonNull := 0.0
for _, v := range arg.Values {
if !math.IsNaN(v) {
if e.Target() == "removeEmptySeries" || (v != 0) {
results = append(results, a)
break
switch e.Target() {
case "removeEmptySeries":
nonNull++
case "removeZeroSeries":
if v != 0 {
nonNull++
}
}
}
}
if nonNull/float64(len(arg.Values)) >= factor {
results = append(results, arg)
}
}
return results, nil
}
Expand Down
46 changes: 45 additions & 1 deletion expr/functions/removeEmptySeries/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ func TestFunction(t *testing.T) {
},
[]*types.MetricData{
types.MakeMetricData("metric1", []float64{1, 2, -1, 7, 8, 20, 30, math.NaN()}, 1, now32),
types.MakeMetricData("metric2", []float64{math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 1, now32),
types.MakeMetricData("metric3", []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1, now32),
},
},
{
"removeZeroSeries(metric*)",
"removeEmptySeries(metric*,0.00001)",
map[parser.MetricRequest][]*types.MetricData{
{"metric*", 0, 1}: {
types.MakeMetricData("metric1", []float64{1, 2, -1, 7, 8, 20, 30, math.NaN()}, 1, now32),
Expand All @@ -51,6 +52,49 @@ func TestFunction(t *testing.T) {
},
[]*types.MetricData{
types.MakeMetricData("metric1", []float64{1, 2, -1, 7, 8, 20, 30, math.NaN()}, 1, now32),
types.MakeMetricData("metric3", []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1, now32),
},
},
{
"removeZeroSeries(metric*,0.000001)",
map[parser.MetricRequest][]*types.MetricData{
{"metric*", 0, 1}: {
types.MakeMetricData("metric1", []float64{1, 2, -1, 7, 8, 20, 30, math.NaN()}, 1, now32),
types.MakeMetricData("metric2", []float64{math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 1, now32),
types.MakeMetricData("metric3", []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1, now32),
},
},
[]*types.MetricData{
types.MakeMetricData("metric1", []float64{1, 2, -1, 7, 8, 20, 30, math.NaN()}, 1, now32),
},
},
{
"removeEmptySeries(metric*,0.8)",
map[parser.MetricRequest][]*types.MetricData{
{"metric*", 0, 1}: {
types.MakeMetricData("metric1", []float64{1, 2, -1, 7, 8, 20, 23, 12, 8, math.NaN()}, 1, now32),
types.MakeMetricData("metric2", []float64{1, 2, -1, 7, 8, 20, 23, 12, math.NaN(), math.NaN()}, 1, now32),
types.MakeMetricData("metric3", []float64{1, 2, -1, 7, 8, 20, 23, math.NaN(), math.NaN(), math.NaN()}, 1, now32),
types.MakeMetricData("metric4", []float64{math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 1, now32),
types.MakeMetricData("metric5", []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1, now32),
},
},
[]*types.MetricData{
types.MakeMetricData("metric1", []float64{1, 2, -1, 7, 8, 20, 23, 12, 8, math.NaN()}, 1, now32),
types.MakeMetricData("metric2", []float64{1, 2, -1, 7, 8, 20, 23, 12, math.NaN(), math.NaN()}, 1, now32),
types.MakeMetricData("metric5", []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1, now32),
},
},
{
"removeEmptySeries(metric*,1)",
map[parser.MetricRequest][]*types.MetricData{
{"metric*", 0, 1}: {
types.MakeMetricData("metric1", []float64{1, 2, -1, 7, 8, 20, 23, 12, 8, -2.3}, 1, now32),
types.MakeMetricData("metric2", []float64{1, 2, -1, 7, 8, 20, 23, 12, 8, math.NaN()}, 1, now32),
},
},
[]*types.MetricData{
types.MakeMetricData("metric1", []float64{1, 2, -1, 7, 8, 20, 23, 12, 8, -2.3}, 1, now32),
},
},
}
Expand Down

0 comments on commit 4348948

Please sign in to comment.