Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Shutdown into a separate interface to revert breaking change. #135

Merged
merged 1 commit into from May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions inmem.go
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
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
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
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