Code

graph: Sort group names after grouping to ensure consistent output.
authorSebastian Harl <sh@tokkee.org>
Thu, 14 May 2015 17:22:36 +0000 (19:22 +0200)
committerSebastian Harl <sh@tokkee.org>
Thu, 14 May 2015 17:22:36 +0000 (19:22 +0200)
graph/graph.go

index 2209671c9f88c270afc4268ce372ac30204bfbf3..17de57d8e48552d4672d6883e064b68e9c476041 100644 (file)
@@ -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