forked from grafana-cold-storage/metrictank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_scale.go
More file actions
55 lines (48 loc) · 1.22 KB
/
Copy pathfunc_scale.go
File metadata and controls
55 lines (48 loc) · 1.22 KB
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
55
package expr
import (
"fmt"
"github.com/raintank/metrictank/api/models"
"gopkg.in/raintank/schema.v1"
)
type FuncScale struct {
in GraphiteFunc
factor float64
}
func NewScale() GraphiteFunc {
return &FuncScale{}
}
func (s *FuncScale) Signature() ([]Arg, []Arg) {
return []Arg{
ArgSeriesList{val: &s.in},
ArgFloat{key: "factor", val: &s.factor},
}, []Arg{
ArgSeriesList{},
}
}
func (s *FuncScale) Context(context Context) Context {
return context
}
func (s *FuncScale) Exec(cache map[Req][]models.Series) ([]models.Series, error) {
series, err := s.in.Exec(cache)
if err != nil {
return nil, err
}
var outputs []models.Series
for _, serie := range series {
out := pointSlicePool.Get().([]schema.Point)
for _, v := range serie.Datapoints {
out = append(out, schema.Point{Val: v.Val * s.factor, Ts: v.Ts})
}
s := models.Series{
Target: fmt.Sprintf("scale(%s,%f)", serie.Target, s.factor),
QueryPatt: fmt.Sprintf("scale(%s,%f)", serie.QueryPatt, s.factor),
Datapoints: out,
Interval: serie.Interval,
Consolidator: serie.Consolidator,
QueryCons: serie.QueryCons,
}
outputs = append(outputs, s)
cache[Req{}] = append(cache[Req{}], s)
}
return outputs, nil
}