Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

groupByNode[s]: implement ordering like graphite does #1774

Merged
merged 2 commits into from
Apr 15, 2020
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
14 changes: 12 additions & 2 deletions expr/func_groupbynodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,21 @@ func (s *FuncGroupByNodes) Exec(dataMap DataMap) ([]models.Series, error) {
s []models.Series
m models.SeriesMeta
}

groups := make(map[string]Group)

// list of aggregation keys in order they were seen.
// we need to return series in this order
var keyList []string

// Group series by nodes, this is mostly similar to GroupByTags,
// except that the group keys are different.
for _, serie := range series {
key := aggKey(serie, s.nodes)
group := groups[key]
group, ok := groups[key]
if !ok {
keyList = append(keyList, key)
}
group.s = append(group.s, serie)
group.m = group.m.Merge(serie.Meta)
groups[key] = group
Expand All @@ -70,7 +79,8 @@ func (s *FuncGroupByNodes) Exec(dataMap DataMap) ([]models.Series, error) {
output := make([]models.Series, 0, len(groups))
aggFunc := getCrossSeriesAggFunc(s.aggregator)

for key, group := range groups {
for _, key := range keyList {
group := groups[key]
consolidator, queryConsolidator := summarizeCons(group.s)
outSeries := models.Series{
Target: key,
Expand Down
8 changes: 0 additions & 8 deletions expr/func_groupbynodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package expr

import (
"math"
"sort"
"strconv"
"testing"

Expand Down Expand Up @@ -241,13 +240,6 @@ func testGroupByNodes(name string, in []models.Series, expected []models.Series,
t.Fatalf("case %q: output length expected to be %d but got %d", name, len(expected), len(got))
}

sort.Slice(got, func(i, j int) bool {
return got[i].Target < got[j].Target
})
sort.Slice(expected, func(i, j int) bool {
return expected[i].Target < expected[j].Target
})

for i, g := range got {
o := expected[i]
if g.Target != o.Target {
Expand Down