Skip to content

Commit

Permalink
Refactor Shutdown into a separate interface to revert breaking change.
Browse files Browse the repository at this point in the history
  • Loading branch information
banks committed May 24, 2022
1 parent 5d4d6f5 commit 0b5fe61
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
4 changes: 0 additions & 4 deletions inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ func (i *InmemSink) AddSampleWithLabels(key []string, val float32, labels []Labe
agg.Ingest(float64(val), i.rateDenom)
}

func (i *InmemSink) Shutdown() {
// Do nothing. InmemSink does not have cleanup associated with shutdown.
}

// Data is used to retrieve all the aggregated metrics
// Intervals may be in use, and a read lock should be acquired
func (i *InmemSink) Data() []*IntervalMetrics {
Expand Down
6 changes: 4 additions & 2 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"time"

"github.com/hashicorp/go-immutable-radix"
iradix "github.com/hashicorp/go-immutable-radix"
)

type Label struct {
Expand Down Expand Up @@ -173,7 +173,9 @@ func (m *Metrics) UpdateFilterAndLabels(allow, block, allowedLabels, blockedLabe
}

func (m *Metrics) Shutdown() {
m.sink.Shutdown()
if ss, ok := m.sink.(ShutdownSink); ok {
ss.Shutdown()
}
}

// labelIsAllowed return true if a should be included in metric
Expand Down
4 changes: 0 additions & 4 deletions prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,6 @@ func (p *PrometheusSink) IncrCounterWithLabels(parts []string, val float32, labe
}
}

// Shutdown is not implemented. PrometheusSink is in memory storage.
func (p *PrometheusSink) Shutdown() {
}

// PrometheusPushSink wraps a normal prometheus sink and provides an address and facilities to export it to an address
// on an interval.
type PrometheusPushSink struct {
Expand Down
9 changes: 7 additions & 2 deletions sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type MetricSink interface {
// Samples are for timing information, where quantiles are used
AddSample(key []string, val float32)
AddSampleWithLabels(key []string, val float32, labels []Label)
}

type ShutdownSink interface {
MetricSink

// Shutdown the metric sink, flush metrics to storage, and cleanup resources.
// Called immediately prior to application exit. Implementations must block
Expand All @@ -39,7 +43,6 @@ 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) {}
func (*BlackholeSink) Shutdown() {}

// FanoutSink is used to sink to fanout values to multiple sinks
type FanoutSink []MetricSink
Expand Down Expand Up @@ -82,7 +85,9 @@ func (fh FanoutSink) AddSampleWithLabels(key []string, val float32, labels []Lab

func (fh FanoutSink) Shutdown() {
for _, s := range fh {
s.Shutdown()
if ss, ok := s.(ShutdownSink); ok {
ss.Shutdown()
}
}
}

Expand Down

0 comments on commit 0b5fe61

Please sign in to comment.