-
Notifications
You must be signed in to change notification settings - Fork 18
/
wrapper.go
52 lines (43 loc) · 1.44 KB
/
wrapper.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
package sfxclient
import (
"github.com/signalfx/golib/v3/datapoint"
)
// MultiCollector acts like a datapoint collector over multiple collectors.
type MultiCollector []Collector
// NewMultiCollector returns a collector that is the aggregate of every given collector. It can be
// used to turn multiple collectors into a single collector.
func NewMultiCollector(collectors ...Collector) Collector {
if len(collectors) == 1 {
return collectors[0]
}
return MultiCollector(collectors)
}
// Datapoints returns the datapoints from every collector.
func (m MultiCollector) Datapoints() []*datapoint.Datapoint {
ret := make([]*datapoint.Datapoint, 0)
for _, col := range m {
ret = append(ret, col.Datapoints()...)
}
return ret
}
var _ Collector = MultiCollector(nil)
// WithDimensions adds dimensions on top of the datapoints of a collector. This can be used to take
// an existing Collector and include extra dimensions.
type WithDimensions struct {
Dimensions map[string]string
Collector Collector
}
var _ Collector = &WithDimensions{}
// Datapoints calls datapoints and adds on Dimensions
func (w *WithDimensions) Datapoints() []*datapoint.Datapoint {
return w.appendDimensions(w.Collector.Datapoints())
}
func (w *WithDimensions) appendDimensions(dps []*datapoint.Datapoint) []*datapoint.Datapoint {
if len(w.Dimensions) == 0 {
return dps
}
for _, dp := range dps {
dp.Dimensions = datapoint.AddMaps(dp.Dimensions, w.Dimensions)
}
return dps
}