Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions circonus/circonus.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ func (s *CirconusSink) Flush() {
s.metrics.Flush()
}

// SetGauge sets value for a gauge metric
func (s *CirconusSink) SetGauge(key []string, val float32) {
flatKey := s.flattenKey(key)
s.metrics.SetGauge(flatKey, int64(val))
}

// SetGaugeWithLabels sets value for a gauge metric with the given labels
func (s *CirconusSink) SetGaugeWithLabels(key []string, val float32, labels []metrics.Label) {
flatKey := s.flattenKeyLabels(key, labels)
Expand All @@ -73,24 +67,12 @@ func (s *CirconusSink) EmitKey(key []string, val float32) {
// NOP
}

// IncrCounter increments a counter metric
func (s *CirconusSink) IncrCounter(key []string, val float32) {
flatKey := s.flattenKey(key)
s.metrics.IncrementByValue(flatKey, uint64(val))
}

// IncrCounterWithLabels increments a counter metric with the given labels
func (s *CirconusSink) IncrCounterWithLabels(key []string, val float32, labels []metrics.Label) {
flatKey := s.flattenKeyLabels(key, labels)
s.metrics.IncrementByValue(flatKey, uint64(val))
}

// AddSample adds a sample to a histogram metric
func (s *CirconusSink) AddSample(key []string, val float32) {
flatKey := s.flattenKey(key)
s.metrics.RecordValue(flatKey, float64(val))
}

// AddSampleWithLabels adds a sample to a histogram metric with the given labels
func (s *CirconusSink) AddSampleWithLabels(key []string, val float32, labels []metrics.Label) {
flatKey := s.flattenKeyLabels(key, labels)
Expand Down
6 changes: 3 additions & 3 deletions circonus/circonus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestSetGauge(t *testing.T) {
}

go func() {
cs.SetGauge([]string{"foo", "bar"}, 1)
cs.SetGaugeWithLabels([]string{"foo", "bar"}, 1, nil)
cs.Flush()
}()

Expand Down Expand Up @@ -112,7 +112,7 @@ func TestIncrCounter(t *testing.T) {
}

go func() {
cs.IncrCounter([]string{"foo", "bar"}, 1)
cs.IncrCounterWithLabels([]string{"foo", "bar"}, 1, nil)
cs.Flush()
}()

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestAddSample(t *testing.T) {
}

go func() {
cs.AddSample([]string{"foo", "bar"}, 1)
cs.AddSampleWithLabels([]string{"foo", "bar"}, 1, nil)
cs.Flush()
}()

Expand Down
12 changes: 0 additions & 12 deletions datadog/dogstatsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,11 @@ func (s *DogStatsdSink) parseKey(key []string) ([]string, []metrics.Label) {

// Implementation of methods in the MetricSink interface

func (s *DogStatsdSink) SetGauge(key []string, val float32) {
s.SetGaugeWithLabels(key, val, nil)
}

func (s *DogStatsdSink) IncrCounter(key []string, val float32) {
s.IncrCounterWithLabels(key, val, nil)
}

// EmitKey is not implemented since DogStatsd does not provide a metric type that holds an
// arbitrary number of values
func (s *DogStatsdSink) EmitKey(key []string, val float32) {
}

func (s *DogStatsdSink) AddSample(key []string, val float32) {
s.AddSampleWithLabels(key, val, nil)
}

// The following ...WithLabels methods correspond to Datadog's Tag extension to Statsd.
// http://docs.datadoghq.com/guides/dogstatsd/#tags
func (s *DogStatsdSink) SetGaugeWithLabels(key []string, val float32, labels []metrics.Label) {
Expand Down
21 changes: 11 additions & 10 deletions datadog/dogstatsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ var MetricSinkTests = []struct {
PropagateHostname bool
Expected string
}{
{"SetGauge", []string{"foo", "bar"}, float32(42), EmptyTags, HostnameDisabled, "foo.bar:42|g"},
{"SetGauge", []string{"foo", "bar", "baz"}, float32(42), EmptyTags, HostnameDisabled, "foo.bar.baz:42|g"},
{"AddSample", []string{"sample", "thing"}, float32(4), EmptyTags, HostnameDisabled, "sample.thing:4.000000|ms"},
{"IncrCounter", []string{"count", "me"}, float32(3), EmptyTags, HostnameDisabled, "count.me:3|c"},

{"SetGauge", []string{"foo", "baz"}, float32(42), []metrics.Label{{"my_tag", ""}}, HostnameDisabled, "foo.baz:42|g|#my_tag"},
{"SetGauge", []string{"foo", "baz"}, float32(42), []metrics.Label{{"my tag", "my_value"}}, HostnameDisabled, "foo.baz:42|g|#my_tag:my_value"},
{"SetGauge", []string{"foo", "bar"}, float32(42), []metrics.Label{{"my_tag", "my_value"}, {"other_tag", "other_value"}}, HostnameDisabled, "foo.bar:42|g|#my_tag:my_value,other_tag:other_value"},
{"SetGauge", []string{"foo", "bar"}, float32(42), []metrics.Label{{"my_tag", "my_value"}, {"other_tag", "other_value"}}, HostnameEnabled, "foo.bar:42|g|#my_tag:my_value,other_tag:other_value,host:test_hostname"},
{"SetGaugeWithLabels", []string{"foo", "bar"}, float32(42), EmptyTags, HostnameDisabled, "foo.bar:42|g"},
{"SetGaugeWithLabels", []string{"foo", "bar", "baz"}, float32(42), EmptyTags, HostnameDisabled, "foo.bar.baz:42|g"},
{"AddSampleWithLabels", []string{"sample", "thing"}, float32(4), EmptyTags, HostnameDisabled, "sample.thing:4.000000|ms"},
{"IncrCounterWithLabels", []string{"count", "me"}, float32(3), EmptyTags, HostnameDisabled, "count.me:3|c"},

{"SetGaugeWithLabels", []string{"foo", "baz"}, float32(42), []metrics.Label{{"my_tag", ""}}, HostnameDisabled, "foo.baz:42|g|#my_tag"},
{"SetGaugeWithLabels", []string{"foo", "baz"}, float32(42), []metrics.Label{{"my tag", "my_value"}}, HostnameDisabled, "foo.baz:42|g|#my_tag:my_value"},
{"SetGaugeWithLabels", []string{"foo", "bar"}, float32(42), []metrics.Label{{"my_tag", "my_value"}, {"other_tag", "other_value"}}, HostnameDisabled, "foo.bar:42|g|#my_tag:my_value,other_tag:other_value"},
{"SetGaugeWithLabels", []string{"foo", "bar"}, float32(42), []metrics.Label{{"my_tag", "my_value"}, {"other_tag", "other_value"}}, HostnameEnabled, "foo.bar:42|g|#my_tag:my_value,other_tag:other_value,host:test_hostname"},
}

func mockNewDogStatsdSink(addr string, labels []metrics.Label, tagWithHostname bool) *DogStatsdSink {
Expand Down Expand Up @@ -117,7 +117,8 @@ func TestMetricSink(t *testing.T) {
method := reflect.ValueOf(dog).MethodByName(tt.Method)
method.Call([]reflect.Value{
reflect.ValueOf(tt.Metric),
reflect.ValueOf(tt.Value)})
reflect.ValueOf(tt.Value),
reflect.ValueOf([]metrics.Label{})})
assertServerMatchesExpected(t, server, buf, tt.Expected)
})
}
Expand Down
12 changes: 0 additions & 12 deletions inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ func NewInmemSink(interval, retain time.Duration) *InmemSink {
return i
}

func (i *InmemSink) SetGauge(key []string, val float32) {
i.SetGaugeWithLabels(key, val, nil)
}

func (i *InmemSink) SetGaugeWithLabels(key []string, val float32, labels []Label) {
k, name := i.flattenKeyLabels(key, labels)
intv := i.getInterval()
Expand All @@ -179,10 +175,6 @@ func (i *InmemSink) EmitKey(key []string, val float32) {
intv.Points[k] = append(vals, val)
}

func (i *InmemSink) IncrCounter(key []string, val float32) {
i.IncrCounterWithLabels(key, val, nil)
}

func (i *InmemSink) IncrCounterWithLabels(key []string, val float32, labels []Label) {
k, name := i.flattenKeyLabels(key, labels)
intv := i.getInterval()
Expand All @@ -202,10 +194,6 @@ func (i *InmemSink) IncrCounterWithLabels(key []string, val float32, labels []La
agg.Ingest(float64(val), i.rateDenom)
}

func (i *InmemSink) AddSample(key []string, val float32) {
i.AddSampleWithLabels(key, val, nil)
}

func (i *InmemSink) AddSampleWithLabels(key []string, val float32, labels []Label) {
k, name := i.flattenKeyLabels(key, labels)
intv := i.getInterval()
Expand Down
17 changes: 8 additions & 9 deletions inmem_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ func TestDisplayMetrics(t *testing.T) {
inm := NewInmemSink(interval, 50*time.Millisecond)

// Add data points
inm.SetGauge([]string{"foo", "bar"}, 42)
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 42, nil)
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 23, []Label{{"a", "b"}})
inm.EmitKey([]string{"foo", "bar"}, 42)
inm.IncrCounter([]string{"foo", "bar"}, 20)
inm.IncrCounter([]string{"foo", "bar"}, 22)
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 20, nil)
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 22, nil)
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 20, []Label{{"a", "b"}})
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 40, []Label{{"a", "b"}})
inm.AddSample([]string{"foo", "bar"}, 20)
inm.AddSample([]string{"foo", "bar"}, 24)
inm.AddSampleWithLabels([]string{"foo", "bar"}, 20, nil)
inm.AddSampleWithLabels([]string{"foo", "bar"}, 24, nil)
inm.AddSampleWithLabels([]string{"foo", "bar"}, 23, []Label{{"a", "b"}})
inm.AddSampleWithLabels([]string{"foo", "bar"}, 33, []Label{{"a", "b"}})

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestDisplayMetrics_RaceSetGauge(t *testing.T) {
go func() {
for {
time.Sleep(150 * time.Millisecond)
inm.SetGauge([]string{"foo", "bar"}, float32(42))
inm.SetGaugeWithLabels([]string{"foo", "bar"}, float32(42), nil)
}
}()

Expand Down Expand Up @@ -174,7 +174,7 @@ func TestDisplayMetrics_RaceAddSample(t *testing.T) {
go func() {
for {
time.Sleep(75 * time.Millisecond)
inm.AddSample([]string{"foo", "bar"}, float32(0.0))
inm.AddSampleWithLabels([]string{"foo", "bar"}, float32(0.0), nil)
}
}()

Expand Down Expand Up @@ -208,7 +208,7 @@ func TestDisplayMetrics_RaceIncrCounter(t *testing.T) {
go func() {
for {
time.Sleep(75 * time.Millisecond)
inm.IncrCounter([]string{"foo", "bar"}, float32(0.0))
inm.IncrCounterWithLabels([]string{"foo", "bar"}, float32(0.0), nil)
}
}()

Expand Down Expand Up @@ -272,4 +272,3 @@ func TestDisplayMetrics_RaceMetricsSetGauge(t *testing.T) {
got := <-result
verify.Values(t, "all", got, float32(42))
}

6 changes: 3 additions & 3 deletions inmem_signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func TestInmemSignal(t *testing.T) {
sig := NewInmemSignal(inm, syscall.SIGUSR1, buf)
defer sig.Stop()

inm.SetGauge([]string{"foo"}, 42)
inm.SetGaugeWithLabels([]string{"foo"}, 42, nil)
inm.EmitKey([]string{"bar"}, 42)
inm.IncrCounter([]string{"baz"}, 42)
inm.AddSample([]string{"wow"}, 42)
inm.IncrCounterWithLabels([]string{"baz"}, 42, nil)
inm.AddSampleWithLabels([]string{"wow"}, 42, nil)
inm.SetGaugeWithLabels([]string{"asdf"}, 42, []Label{{"a", "b"}})
inm.IncrCounterWithLabels([]string{"qwer"}, 42, []Label{{"a", "b"}})
inm.AddSampleWithLabels([]string{"zxcv"}, 42, []Label{{"a", "b"}})
Expand Down
14 changes: 7 additions & 7 deletions inmem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func TestInmemSink(t *testing.T) {
}

// Add data points
inm.SetGauge([]string{"foo", "bar"}, 42)
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 42, nil)
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 23, []Label{{"a", "b"}})
inm.EmitKey([]string{"foo", "bar"}, 42)
inm.IncrCounter([]string{"foo", "bar"}, 20)
inm.IncrCounter([]string{"foo", "bar"}, 22)
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 20, nil)
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 22, nil)
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 20, []Label{{"a", "b"}})
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 22, []Label{{"a", "b"}})
inm.AddSample([]string{"foo", "bar"}, 20)
inm.AddSample([]string{"foo", "bar"}, 22)
inm.AddSampleWithLabels([]string{"foo", "bar"}, 20, nil)
inm.AddSampleWithLabels([]string{"foo", "bar"}, 22, nil)
inm.AddSampleWithLabels([]string{"foo", "bar"}, 23, []Label{{"a", "b"}})

data = inm.Data()
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestInmemSink(t *testing.T) {

for i := 1; i < 10; i++ {
time.Sleep(10 * time.Millisecond)
inm.SetGauge([]string{"foo", "bar"}, 42)
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 42, nil)
data = inm.Data()
if len(data) != min(i+1, 5) {
t.Fatalf("bad: %v", data)
Expand All @@ -106,7 +106,7 @@ func TestInmemSink(t *testing.T) {

// Should not exceed 5 intervals!
time.Sleep(10 * time.Millisecond)
inm.SetGauge([]string{"foo", "bar"}, 42)
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 42, nil)
data = inm.Data()
if len(data) != 5 {
t.Fatalf("bad: %v", data)
Expand Down
12 changes: 0 additions & 12 deletions prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ func prometheusLabels(labels []metrics.Label) prometheus.Labels {
return l
}

func (p *PrometheusSink) SetGauge(parts []string, val float32) {
p.SetGaugeWithLabels(parts, val, nil)
}

func (p *PrometheusSink) SetGaugeWithLabels(parts []string, val float32, labels []metrics.Label) {
key, hash := p.flattenKey(parts, labels)
pg, ok := p.gauges.Load(hash)
Expand Down Expand Up @@ -179,10 +175,6 @@ func (p *PrometheusSink) SetGaugeWithLabels(parts []string, val float32, labels
}
}

func (p *PrometheusSink) AddSample(parts []string, val float32) {
p.AddSampleWithLabels(parts, val, nil)
}

func (p *PrometheusSink) AddSampleWithLabels(parts []string, val float32, labels []metrics.Label) {
key, hash := p.flattenKey(parts, labels)
ps, ok := p.summaries.Load(hash)
Expand Down Expand Up @@ -214,10 +206,6 @@ func (p *PrometheusSink) AddSampleWithLabels(parts []string, val float32, labels
func (p *PrometheusSink) EmitKey(key []string, val float32) {
}

func (p *PrometheusSink) IncrCounter(parts []string, val float32) {
p.IncrCounterWithLabels(parts, val, nil)
}

func (p *PrometheusSink) IncrCounterWithLabels(parts []string, val float32, labels []metrics.Label) {
key, hash := p.flattenKey(parts, labels)
pc, ok := p.counters.Load(hash)
Expand Down
18 changes: 0 additions & 18 deletions sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,29 @@ import (
// to an external system
type MetricSink interface {
// A Gauge should retain the last value it is set to
SetGauge(key []string, val float32)
SetGaugeWithLabels(key []string, val float32, labels []Label)

// Should emit a Key/Value pair for each call
EmitKey(key []string, val float32)

// Counters should accumulate values
IncrCounter(key []string, val float32)
IncrCounterWithLabels(key []string, val float32, labels []Label)

// Samples are for timing information, where quantiles are used
AddSample(key []string, val float32)
AddSampleWithLabels(key []string, val float32, labels []Label)
}

// BlackholeSink is used to just blackhole messages
type BlackholeSink struct{}

func (*BlackholeSink) SetGauge(key []string, val float32) {}
func (*BlackholeSink) SetGaugeWithLabels(key []string, val float32, labels []Label) {}
func (*BlackholeSink) EmitKey(key []string, val float32) {}
func (*BlackholeSink) IncrCounter(key []string, val float32) {}
func (*BlackholeSink) IncrCounterWithLabels(key []string, val float32, labels []Label) {}
func (*BlackholeSink) AddSample(key []string, val float32) {}
func (*BlackholeSink) AddSampleWithLabels(key []string, val float32, labels []Label) {}

// FanoutSink is used to sink to fanout values to multiple sinks
type FanoutSink []MetricSink

func (fh FanoutSink) SetGauge(key []string, val float32) {
fh.SetGaugeWithLabels(key, val, nil)
}

func (fh FanoutSink) SetGaugeWithLabels(key []string, val float32, labels []Label) {
for _, s := range fh {
s.SetGaugeWithLabels(key, val, labels)
Expand All @@ -54,20 +44,12 @@ func (fh FanoutSink) EmitKey(key []string, val float32) {
}
}

func (fh FanoutSink) IncrCounter(key []string, val float32) {
fh.IncrCounterWithLabels(key, val, nil)
}

func (fh FanoutSink) IncrCounterWithLabels(key []string, val float32, labels []Label) {
for _, s := range fh {
s.IncrCounterWithLabels(key, val, labels)
}
}

func (fh FanoutSink) AddSample(key []string, val float32) {
fh.AddSampleWithLabels(key, val, nil)
}

func (fh FanoutSink) AddSampleWithLabels(key []string, val float32, labels []Label) {
for _, s := range fh {
s.AddSampleWithLabels(key, val, labels)
Expand Down
Loading