Skip to content

Commit

Permalink
Remove the useless metrics.DummySink
Browse files Browse the repository at this point in the history
It isn't used for anything except a few tests of questionable quality, but it's not even needed for them...
  • Loading branch information
na-- committed Jul 13, 2023
1 parent 2da7856 commit 4a39f17
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 34 deletions.
15 changes: 0 additions & 15 deletions metrics/sink.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package metrics

import (
"errors"
"fmt"
"math"
"sort"
Expand All @@ -13,7 +12,6 @@ var (
_ Sink = &GaugeSink{}
_ Sink = &TrendSink{}
_ Sink = &RateSink{}
_ Sink = &DummySink{}
)

type Sink interface {
Expand Down Expand Up @@ -180,16 +178,3 @@ func (r RateSink) Format(t time.Duration) map[string]float64 {

return map[string]float64{"rate": rate}
}

type DummySink map[string]float64

// IsEmpty indicates whether the DummySink is empty.
func (d DummySink) IsEmpty() bool { return len(d) == 0 }

func (d DummySink) Add(s Sample) {
panic(errors.New("you can't add samples to a dummy sink"))
}

func (d DummySink) Format(t time.Duration) map[string]float64 {
return map[string]float64(d)
}
10 changes: 0 additions & 10 deletions metrics/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,3 @@ func TestRateSink(t *testing.T) {
assert.Equal(t, map[string]float64{"rate": 0.5}, sink.Format(0))
})
}

func TestDummySinkAddPanics(t *testing.T) {
assert.Panics(t, func() {
DummySink{}.Add(Sample{})
})
}

func TestDummySinkFormatReturnsItself(t *testing.T) {
assert.Equal(t, map[string]float64{"a": 1}, DummySink{"a": 1}.Format(0))
}
4 changes: 0 additions & 4 deletions metrics/thresholds.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ func (ts *Thresholds) Run(sink Sink, duration time.Duration) (bool, error) {
if sinkImpl.Total > 0 {
ts.sinked["rate"] = float64(sinkImpl.Trues) / float64(sinkImpl.Total)
}
case DummySink:
for k, v := range sinkImpl {
ts.sinked[k] = v
}
default:
return false, fmt.Errorf("unable to run Thresholds; reason: unknown sink type")
}
Expand Down
10 changes: 5 additions & 5 deletions metrics/thresholds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ func TestThresholdsRun(t *testing.T) {
{
name: "Running thresholds of existing sink",
args: args{
sink: DummySink{"p(95)": 1234.5},
thresholdExpressions: []string{"p(95)<2000"},
sink: &CounterSink{Value: 1234.5},
thresholdExpressions: []string{"count<2000"},
duration: 0,
},
want: true,
Expand All @@ -666,8 +666,8 @@ func TestThresholdsRun(t *testing.T) {
{
name: "Running thresholds of existing sink but failing threshold",
args: args{
sink: DummySink{"p(95)": 3000},
thresholdExpressions: []string{"p(95)<2000"},
sink: &CounterSink{Value: 3000},
thresholdExpressions: []string{"count<2000"},
duration: 0,
},
want: false,
Expand All @@ -676,7 +676,7 @@ func TestThresholdsRun(t *testing.T) {
{
name: "Running threshold on non existing sink does not fail",
args: args{
sink: DummySink{"dummy": 0},
sink: &CounterSink{},
thresholdExpressions: []string{"p(95)<2000"},
duration: 0,
},
Expand Down

0 comments on commit 4a39f17

Please sign in to comment.