Skip to content

Commit afd8928

Browse files
committed
Remove unused interface methods
With the addition of labels in #54 the Metrics struct only uses the new WithLabels methods on Sink. This change removes the unused methods.
1 parent 2bc64eb commit afd8928

File tree

15 files changed

+38
-218
lines changed

15 files changed

+38
-218
lines changed

circonus/circonus.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ func (s *CirconusSink) Flush() {
5656
s.metrics.Flush()
5757
}
5858

59-
// SetGauge sets value for a gauge metric
60-
func (s *CirconusSink) SetGauge(key []string, val float32) {
61-
flatKey := s.flattenKey(key)
62-
s.metrics.SetGauge(flatKey, int64(val))
63-
}
64-
6559
// SetGaugeWithLabels sets value for a gauge metric with the given labels
6660
func (s *CirconusSink) SetGaugeWithLabels(key []string, val float32, labels []metrics.Label) {
6761
flatKey := s.flattenKeyLabels(key, labels)
@@ -73,24 +67,12 @@ func (s *CirconusSink) EmitKey(key []string, val float32) {
7367
// NOP
7468
}
7569

76-
// IncrCounter increments a counter metric
77-
func (s *CirconusSink) IncrCounter(key []string, val float32) {
78-
flatKey := s.flattenKey(key)
79-
s.metrics.IncrementByValue(flatKey, uint64(val))
80-
}
81-
8270
// IncrCounterWithLabels increments a counter metric with the given labels
8371
func (s *CirconusSink) IncrCounterWithLabels(key []string, val float32, labels []metrics.Label) {
8472
flatKey := s.flattenKeyLabels(key, labels)
8573
s.metrics.IncrementByValue(flatKey, uint64(val))
8674
}
8775

88-
// AddSample adds a sample to a histogram metric
89-
func (s *CirconusSink) AddSample(key []string, val float32) {
90-
flatKey := s.flattenKey(key)
91-
s.metrics.RecordValue(flatKey, float64(val))
92-
}
93-
9476
// AddSampleWithLabels adds a sample to a histogram metric with the given labels
9577
func (s *CirconusSink) AddSampleWithLabels(key []string, val float32, labels []metrics.Label) {
9678
flatKey := s.flattenKeyLabels(key, labels)

circonus/circonus_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestSetGauge(t *testing.T) {
8484
}
8585

8686
go func() {
87-
cs.SetGauge([]string{"foo", "bar"}, 1)
87+
cs.SetGaugeWithLabels([]string{"foo", "bar"}, 1, nil)
8888
cs.Flush()
8989
}()
9090

@@ -112,7 +112,7 @@ func TestIncrCounter(t *testing.T) {
112112
}
113113

114114
go func() {
115-
cs.IncrCounter([]string{"foo", "bar"}, 1)
115+
cs.IncrCounterWithLabels([]string{"foo", "bar"}, 1, nil)
116116
cs.Flush()
117117
}()
118118

@@ -140,7 +140,7 @@ func TestAddSample(t *testing.T) {
140140
}
141141

142142
go func() {
143-
cs.AddSample([]string{"foo", "bar"}, 1)
143+
cs.AddSampleWithLabels([]string{"foo", "bar"}, 1, nil)
144144
cs.Flush()
145145
}()
146146

datadog/dogstatsd.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,11 @@ func (s *DogStatsdSink) parseKey(key []string) ([]string, []metrics.Label) {
8383

8484
// Implementation of methods in the MetricSink interface
8585

86-
func (s *DogStatsdSink) SetGauge(key []string, val float32) {
87-
s.SetGaugeWithLabels(key, val, nil)
88-
}
89-
90-
func (s *DogStatsdSink) IncrCounter(key []string, val float32) {
91-
s.IncrCounterWithLabels(key, val, nil)
92-
}
93-
9486
// EmitKey is not implemented since DogStatsd does not provide a metric type that holds an
9587
// arbitrary number of values
9688
func (s *DogStatsdSink) EmitKey(key []string, val float32) {
9789
}
9890

99-
func (s *DogStatsdSink) AddSample(key []string, val float32) {
100-
s.AddSampleWithLabels(key, val, nil)
101-
}
102-
10391
// The following ...WithLabels methods correspond to Datadog's Tag extension to Statsd.
10492
// http://docs.datadoghq.com/guides/dogstatsd/#tags
10593
func (s *DogStatsdSink) SetGaugeWithLabels(key []string, val float32, labels []metrics.Label) {

datadog/dogstatsd_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ var MetricSinkTests = []struct {
4949
PropagateHostname bool
5050
Expected string
5151
}{
52-
{"SetGauge", []string{"foo", "bar"}, float32(42), EmptyTags, HostnameDisabled, "foo.bar:42|g"},
53-
{"SetGauge", []string{"foo", "bar", "baz"}, float32(42), EmptyTags, HostnameDisabled, "foo.bar.baz:42|g"},
54-
{"AddSample", []string{"sample", "thing"}, float32(4), EmptyTags, HostnameDisabled, "sample.thing:4.000000|ms"},
55-
{"IncrCounter", []string{"count", "me"}, float32(3), EmptyTags, HostnameDisabled, "count.me:3|c"},
56-
57-
{"SetGauge", []string{"foo", "baz"}, float32(42), []metrics.Label{{"my_tag", ""}}, HostnameDisabled, "foo.baz:42|g|#my_tag"},
58-
{"SetGauge", []string{"foo", "baz"}, float32(42), []metrics.Label{{"my tag", "my_value"}}, HostnameDisabled, "foo.baz:42|g|#my_tag:my_value"},
59-
{"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"},
60-
{"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"},
52+
{"SetGaugeWithLabels", []string{"foo", "bar"}, float32(42), EmptyTags, HostnameDisabled, "foo.bar:42|g"},
53+
{"SetGaugeWithLabels", []string{"foo", "bar", "baz"}, float32(42), EmptyTags, HostnameDisabled, "foo.bar.baz:42|g"},
54+
{"AddSampleWithLabels", []string{"sample", "thing"}, float32(4), EmptyTags, HostnameDisabled, "sample.thing:4.000000|ms"},
55+
{"IncrCounterWithLabels", []string{"count", "me"}, float32(3), EmptyTags, HostnameDisabled, "count.me:3|c"},
56+
57+
{"SetGaugeWithLabels", []string{"foo", "baz"}, float32(42), []metrics.Label{{"my_tag", ""}}, HostnameDisabled, "foo.baz:42|g|#my_tag"},
58+
{"SetGaugeWithLabels", []string{"foo", "baz"}, float32(42), []metrics.Label{{"my tag", "my_value"}}, HostnameDisabled, "foo.baz:42|g|#my_tag:my_value"},
59+
{"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"},
60+
{"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"},
6161
}
6262

6363
func mockNewDogStatsdSink(addr string, labels []metrics.Label, tagWithHostname bool) *DogStatsdSink {
@@ -117,7 +117,8 @@ func TestMetricSink(t *testing.T) {
117117
method := reflect.ValueOf(dog).MethodByName(tt.Method)
118118
method.Call([]reflect.Value{
119119
reflect.ValueOf(tt.Metric),
120-
reflect.ValueOf(tt.Value)})
120+
reflect.ValueOf(tt.Value),
121+
reflect.ValueOf([]metrics.Label{})})
121122
assertServerMatchesExpected(t, server, buf, tt.Expected)
122123
})
123124
}

inmem.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ func NewInmemSink(interval, retain time.Duration) *InmemSink {
156156
return i
157157
}
158158

159-
func (i *InmemSink) SetGauge(key []string, val float32) {
160-
i.SetGaugeWithLabels(key, val, nil)
161-
}
162-
163159
func (i *InmemSink) SetGaugeWithLabels(key []string, val float32, labels []Label) {
164160
k, name := i.flattenKeyLabels(key, labels)
165161
intv := i.getInterval()
@@ -179,10 +175,6 @@ func (i *InmemSink) EmitKey(key []string, val float32) {
179175
intv.Points[k] = append(vals, val)
180176
}
181177

182-
func (i *InmemSink) IncrCounter(key []string, val float32) {
183-
i.IncrCounterWithLabels(key, val, nil)
184-
}
185-
186178
func (i *InmemSink) IncrCounterWithLabels(key []string, val float32, labels []Label) {
187179
k, name := i.flattenKeyLabels(key, labels)
188180
intv := i.getInterval()
@@ -202,10 +194,6 @@ func (i *InmemSink) IncrCounterWithLabels(key []string, val float32, labels []La
202194
agg.Ingest(float64(val), i.rateDenom)
203195
}
204196

205-
func (i *InmemSink) AddSample(key []string, val float32) {
206-
i.AddSampleWithLabels(key, val, nil)
207-
}
208-
209197
func (i *InmemSink) AddSampleWithLabels(key []string, val float32, labels []Label) {
210198
k, name := i.flattenKeyLabels(key, labels)
211199
intv := i.getInterval()

inmem_endpoint_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ func TestDisplayMetrics(t *testing.T) {
1212
inm := NewInmemSink(interval, 50*time.Millisecond)
1313

1414
// Add data points
15-
inm.SetGauge([]string{"foo", "bar"}, 42)
15+
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 42, nil)
1616
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 23, []Label{{"a", "b"}})
1717
inm.EmitKey([]string{"foo", "bar"}, 42)
18-
inm.IncrCounter([]string{"foo", "bar"}, 20)
19-
inm.IncrCounter([]string{"foo", "bar"}, 22)
18+
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 20, nil)
19+
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 22, nil)
2020
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 20, []Label{{"a", "b"}})
2121
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 40, []Label{{"a", "b"}})
22-
inm.AddSample([]string{"foo", "bar"}, 20)
23-
inm.AddSample([]string{"foo", "bar"}, 24)
22+
inm.AddSampleWithLabels([]string{"foo", "bar"}, 20, nil)
23+
inm.AddSampleWithLabels([]string{"foo", "bar"}, 24, nil)
2424
inm.AddSampleWithLabels([]string{"foo", "bar"}, 23, []Label{{"a", "b"}})
2525
inm.AddSampleWithLabels([]string{"foo", "bar"}, 33, []Label{{"a", "b"}})
2626

@@ -140,7 +140,7 @@ func TestDisplayMetrics_RaceSetGauge(t *testing.T) {
140140
go func() {
141141
for {
142142
time.Sleep(150 * time.Millisecond)
143-
inm.SetGauge([]string{"foo", "bar"}, float32(42))
143+
inm.SetGaugeWithLabels([]string{"foo", "bar"}, float32(42), nil)
144144
}
145145
}()
146146

@@ -174,7 +174,7 @@ func TestDisplayMetrics_RaceAddSample(t *testing.T) {
174174
go func() {
175175
for {
176176
time.Sleep(75 * time.Millisecond)
177-
inm.AddSample([]string{"foo", "bar"}, float32(0.0))
177+
inm.AddSampleWithLabels([]string{"foo", "bar"}, float32(0.0), nil)
178178
}
179179
}()
180180

@@ -208,7 +208,7 @@ func TestDisplayMetrics_RaceIncrCounter(t *testing.T) {
208208
go func() {
209209
for {
210210
time.Sleep(75 * time.Millisecond)
211-
inm.IncrCounter([]string{"foo", "bar"}, float32(0.0))
211+
inm.IncrCounterWithLabels([]string{"foo", "bar"}, float32(0.0), nil)
212212
}
213213
}()
214214

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

inmem_signal_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ func TestInmemSignal(t *testing.T) {
1616
sig := NewInmemSignal(inm, syscall.SIGUSR1, buf)
1717
defer sig.Stop()
1818

19-
inm.SetGauge([]string{"foo"}, 42)
19+
inm.SetGaugeWithLabels([]string{"foo"}, 42, nil)
2020
inm.EmitKey([]string{"bar"}, 42)
21-
inm.IncrCounter([]string{"baz"}, 42)
22-
inm.AddSample([]string{"wow"}, 42)
21+
inm.IncrCounterWithLabels([]string{"baz"}, 42, nil)
22+
inm.AddSampleWithLabels([]string{"wow"}, 42, nil)
2323
inm.SetGaugeWithLabels([]string{"asdf"}, 42, []Label{{"a", "b"}})
2424
inm.IncrCounterWithLabels([]string{"qwer"}, 42, []Label{{"a", "b"}})
2525
inm.AddSampleWithLabels([]string{"zxcv"}, 42, []Label{{"a", "b"}})

inmem_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ func TestInmemSink(t *testing.T) {
1717
}
1818

1919
// Add data points
20-
inm.SetGauge([]string{"foo", "bar"}, 42)
20+
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 42, nil)
2121
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 23, []Label{{"a", "b"}})
2222
inm.EmitKey([]string{"foo", "bar"}, 42)
23-
inm.IncrCounter([]string{"foo", "bar"}, 20)
24-
inm.IncrCounter([]string{"foo", "bar"}, 22)
23+
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 20, nil)
24+
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 22, nil)
2525
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 20, []Label{{"a", "b"}})
2626
inm.IncrCounterWithLabels([]string{"foo", "bar"}, 22, []Label{{"a", "b"}})
27-
inm.AddSample([]string{"foo", "bar"}, 20)
28-
inm.AddSample([]string{"foo", "bar"}, 22)
27+
inm.AddSampleWithLabels([]string{"foo", "bar"}, 20, nil)
28+
inm.AddSampleWithLabels([]string{"foo", "bar"}, 22, nil)
2929
inm.AddSampleWithLabels([]string{"foo", "bar"}, 23, []Label{{"a", "b"}})
3030

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

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

107107
// Should not exceed 5 intervals!
108108
time.Sleep(10 * time.Millisecond)
109-
inm.SetGauge([]string{"foo", "bar"}, 42)
109+
inm.SetGaugeWithLabels([]string{"foo", "bar"}, 42, nil)
110110
data = inm.Data()
111111
if len(data) != 5 {
112112
t.Fatalf("bad: %v", data)

prometheus/prometheus.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ func prometheusLabels(labels []metrics.Label) prometheus.Labels {
146146
return l
147147
}
148148

149-
func (p *PrometheusSink) SetGauge(parts []string, val float32) {
150-
p.SetGaugeWithLabels(parts, val, nil)
151-
}
152-
153149
func (p *PrometheusSink) SetGaugeWithLabels(parts []string, val float32, labels []metrics.Label) {
154150
key, hash := p.flattenKey(parts, labels)
155151
pg, ok := p.gauges.Load(hash)
@@ -179,10 +175,6 @@ func (p *PrometheusSink) SetGaugeWithLabels(parts []string, val float32, labels
179175
}
180176
}
181177

182-
func (p *PrometheusSink) AddSample(parts []string, val float32) {
183-
p.AddSampleWithLabels(parts, val, nil)
184-
}
185-
186178
func (p *PrometheusSink) AddSampleWithLabels(parts []string, val float32, labels []metrics.Label) {
187179
key, hash := p.flattenKey(parts, labels)
188180
ps, ok := p.summaries.Load(hash)
@@ -214,10 +206,6 @@ func (p *PrometheusSink) AddSampleWithLabels(parts []string, val float32, labels
214206
func (p *PrometheusSink) EmitKey(key []string, val float32) {
215207
}
216208

217-
func (p *PrometheusSink) IncrCounter(parts []string, val float32) {
218-
p.IncrCounterWithLabels(parts, val, nil)
219-
}
220-
221209
func (p *PrometheusSink) IncrCounterWithLabels(parts []string, val float32, labels []metrics.Label) {
222210
key, hash := p.flattenKey(parts, labels)
223211
pc, ok := p.counters.Load(hash)

sink.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,29 @@ import (
99
// to an external system
1010
type MetricSink interface {
1111
// A Gauge should retain the last value it is set to
12-
SetGauge(key []string, val float32)
1312
SetGaugeWithLabels(key []string, val float32, labels []Label)
1413

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

1817
// Counters should accumulate values
19-
IncrCounter(key []string, val float32)
2018
IncrCounterWithLabels(key []string, val float32, labels []Label)
2119

2220
// Samples are for timing information, where quantiles are used
23-
AddSample(key []string, val float32)
2421
AddSampleWithLabels(key []string, val float32, labels []Label)
2522
}
2623

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

30-
func (*BlackholeSink) SetGauge(key []string, val float32) {}
3127
func (*BlackholeSink) SetGaugeWithLabels(key []string, val float32, labels []Label) {}
3228
func (*BlackholeSink) EmitKey(key []string, val float32) {}
33-
func (*BlackholeSink) IncrCounter(key []string, val float32) {}
3429
func (*BlackholeSink) IncrCounterWithLabels(key []string, val float32, labels []Label) {}
35-
func (*BlackholeSink) AddSample(key []string, val float32) {}
3630
func (*BlackholeSink) AddSampleWithLabels(key []string, val float32, labels []Label) {}
3731

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

41-
func (fh FanoutSink) SetGauge(key []string, val float32) {
42-
fh.SetGaugeWithLabels(key, val, nil)
43-
}
44-
4535
func (fh FanoutSink) SetGaugeWithLabels(key []string, val float32, labels []Label) {
4636
for _, s := range fh {
4737
s.SetGaugeWithLabels(key, val, labels)
@@ -54,20 +44,12 @@ func (fh FanoutSink) EmitKey(key []string, val float32) {
5444
}
5545
}
5646

57-
func (fh FanoutSink) IncrCounter(key []string, val float32) {
58-
fh.IncrCounterWithLabels(key, val, nil)
59-
}
60-
6147
func (fh FanoutSink) IncrCounterWithLabels(key []string, val float32, labels []Label) {
6248
for _, s := range fh {
6349
s.IncrCounterWithLabels(key, val, labels)
6450
}
6551
}
6652

67-
func (fh FanoutSink) AddSample(key []string, val float32) {
68-
fh.AddSampleWithLabels(key, val, nil)
69-
}
70-
7153
func (fh FanoutSink) AddSampleWithLabels(key []string, val float32, labels []Label) {
7254
for _, s := range fh {
7355
s.AddSampleWithLabels(key, val, labels)

0 commit comments

Comments
 (0)