forked from grafana-cold-storage/metrictank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_aliasbynode.go
More file actions
53 lines (46 loc) · 1020 Bytes
/
Copy pathfunc_aliasbynode.go
File metadata and controls
53 lines (46 loc) · 1020 Bytes
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
package expr
import (
"strings"
"github.com/raintank/metrictank/api/models"
)
type FuncAliasByNode struct {
in GraphiteFunc
nodes []int64
}
func NewAliasByNode() GraphiteFunc {
return &FuncAliasByNode{}
}
func (s *FuncAliasByNode) Signature() ([]Arg, []Arg) {
return []Arg{
ArgSeriesList{val: &s.in},
ArgInts{val: &s.nodes},
}, []Arg{ArgSeries{}}
}
func (s *FuncAliasByNode) Context(context Context) Context {
return context
}
func (s *FuncAliasByNode) Exec(cache map[Req][]models.Series) ([]models.Series, error) {
series, err := s.in.Exec(cache)
if err != nil {
return nil, err
}
for i, serie := range series {
metric := extractMetric(serie.Target)
parts := strings.Split(metric, ".")
var name []string
for _, n64 := range s.nodes {
n := int(n64)
if n < 0 {
n += len(parts)
}
if n >= len(parts) || n < 0 {
continue
}
name = append(name, parts[n])
}
n := strings.Join(name, ".")
series[i].Target = n
series[i].QueryPatt = n
}
return series, nil
}