blob: 0c240c2c47ee8a5901df9d28393671b9ee62ddef [file] [log] [blame]
khenaidooac637102019-01-14 15:44:34 -05001package metrics
2
3// The MetricSink interface is used to transmit metrics information
4// to an external system
5type MetricSink interface {
6 // A Gauge should retain the last value it is set to
7 SetGauge(key []string, val float32)
8
9 // Should emit a Key/Value pair for each call
10 EmitKey(key []string, val float32)
11
12 // Counters should accumulate values
13 IncrCounter(key []string, val float32)
14
15 // Samples are for timing information, where quantiles are used
16 AddSample(key []string, val float32)
17}
18
19// BlackholeSink is used to just blackhole messages
20type BlackholeSink struct{}
21
22func (*BlackholeSink) SetGauge(key []string, val float32) {}
23func (*BlackholeSink) EmitKey(key []string, val float32) {}
24func (*BlackholeSink) IncrCounter(key []string, val float32) {}
25func (*BlackholeSink) AddSample(key []string, val float32) {}
26
27// FanoutSink is used to sink to fanout values to multiple sinks
28type FanoutSink []MetricSink
29
30func (fh FanoutSink) SetGauge(key []string, val float32) {
31 for _, s := range fh {
32 s.SetGauge(key, val)
33 }
34}
35
36func (fh FanoutSink) EmitKey(key []string, val float32) {
37 for _, s := range fh {
38 s.EmitKey(key, val)
39 }
40}
41
42func (fh FanoutSink) IncrCounter(key []string, val float32) {
43 for _, s := range fh {
44 s.IncrCounter(key, val)
45 }
46}
47
48func (fh FanoutSink) AddSample(key []string, val float32) {
49 for _, s := range fh {
50 s.AddSample(key, val)
51 }
52}