-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseries-data.go
54 lines (46 loc) · 1.34 KB
/
series-data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"github.com/prometheus/common/model"
)
const (
LabelName = "__name__"
LabelInstance = "instance"
)
type OrganizedForFile struct {
From string `yaml:"from" json:"from"`
To string `yaml:"to" json:"to"`
Step int `yaml:"step" json:"step"`
Data OrganizedServices `yaml:"data" json:"data"`
}
type OrganizedServices []OrganizedSeries
type OrganizedSeries struct {
Name string `yaml:"name" json:"name"`
Instance string `yaml:"instance" json:"instance"`
Set []model.LabelSet `yaml:"set" json:"set"`
Storage Storage `yaml:"storage" json:"storage"`
}
func splitToSeriesNameAndInstance(set []model.LabelSet, storage *Storage) OrganizedServices {
series := OrganizedServices{}
for _, labelSet := range set {
i := series.index(labelSet)
if i > -1 {
series[i].Set = append(series[i].Set, labelSet)
} else {
series = append(series, OrganizedSeries{
Name: string(labelSet[LabelName]),
Instance: string(labelSet[LabelInstance]),
Set: []model.LabelSet{labelSet},
Storage: *storage,
})
}
}
return series
}
func (s OrganizedServices) index(set model.LabelSet) int {
for i, series := range s {
if series.Name == string(set[LabelName]) && series.Instance == string(set[LabelInstance]) {
return i
}
}
return -1
}