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 math operations on results of aggr #2306

Merged
merged 7 commits into from Sep 20, 2018
Merged
Diff settings

Always

Just for now

Next

Fix opentsdb tags in aggr function

Without this fix, math operations cause an error 'expr: opentsdb: bad tag: partner' to be returned
  • Loading branch information...
Herman Schaaf
Herman Schaaf committed Sep 6, 2018
commit c2cf1ffce3286f07d2cfff09ef4ca4736375d8fd
Copy path View file
@@ -58,7 +58,11 @@ func aggrFuncTags(args []parse.Node) (parse.Tags, error) {
return nil, errors.New("aggr: expect group to be string")
}
s := args[1].(*parse.StringNode).Text
return tagsFromString(s)
tags := strings.Split(s, ",")
for i := range tags {
tags[i] += "=*"
}
return tagsFromString(strings.Join(tags, ","))
}

func tagsFromString(text string) (parse.Tags, error) {
Copy path View file
@@ -453,6 +453,64 @@ func TestAggrWithGroups(t *testing.T) {
}
}

func TestAggrWithGroupsAndMathOperation(t *testing.T) {
seriesA := `series("color=blue,type=apple,name=bob", 0, 1)`
seriesB := `series("color=blue,type=apple", 1, 3)`
seriesC := `series("color=green,type=apple", 0, 5)`

// test aggregator with single group
err := testExpression(exprInOut{
fmt.Sprintf("aggr(merge(%v, %v, %v), \"color\", \"p.50\") * 2", seriesA, seriesB, seriesC),
Results{
Results: ResultSlice{
&Result{
Value: Series{
time.Unix(0, 0): 2,
time.Unix(1, 0): 6,
},
Group: opentsdb.TagSet{"color": "blue"},
},
&Result{
Value: Series{
time.Unix(0, 0): 10,
},
Group: opentsdb.TagSet{"color": "green"},
},
},
},
false,
})
if err != nil {
t.Error(err)
}

// test aggregator with multiple groups and math operation
err = testExpression(exprInOut{
fmt.Sprintf("aggr(merge(%v, %v, %v), \"color,type\", \"p.50\") * 2", seriesA, seriesB, seriesC),
Results{
Results: ResultSlice{
&Result{
Value: Series{
time.Unix(0, 0): 2,
time.Unix(1, 0): 6,
},
Group: opentsdb.TagSet{"color": "blue", "type": "apple"},
},
&Result{
Value: Series{
time.Unix(0, 0): 10,
},
Group: opentsdb.TagSet{"color": "green", "type": "apple"},
},
},
},
false,
})
if err != nil {
t.Error(err)
}
}

func TestAggrNaNHandling(t *testing.T) {
// test behavior when NaN is encountered.
seriesD := `series("foo=bar", 0, 0 / 0, 100, 1)`
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.