From 54923060e9918db91d5984e4580f3d79ee197c10 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Thu, 14 May 2015 19:22:36 +0200 Subject: [PATCH] graph: Sort group names after grouping to ensure consistent output. --- graph/graph.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/graph/graph.go b/graph/graph.go index 2209671..17de57d 100644 --- a/graph/graph.go +++ b/graph/graph.go @@ -29,6 +29,7 @@ package graph import ( "fmt" + "sort" "strings" "time" @@ -146,17 +147,23 @@ func (g *Graph) group(c *client.Client, start, end time.Time) ([]Metric, error) return g.Metrics, nil } + names := make([]string, 0) groups := make(map[string][]Metric) for _, m := range g.Metrics { var key string for _, g := range g.GroupBy { key += "\x00" + m.Attributes[g] } + if _, ok := groups[key]; !ok { + names = append(names, key) + } groups[key] = append(groups[key], m) } + sort.Strings(names) var metrics []Metric - for name, group := range groups { + for _, name := range names { + group := groups[name] ts, err := queryTimeseries(c, group[0], g.Start, g.End) if err != nil { return nil, err -- 2.30.2