metrics: remove nil histograms

This commit is contained in:
Martin Holst Swende 2024-11-27 02:40:29 +01:00
parent abd76eee1e
commit 01cfef29ef
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -40,10 +40,7 @@ func GetOrRegisterHistogramLazy(name string, r Registry, s func() Sample) Histog
// NewHistogram constructs a new StandardHistogram from a Sample. // NewHistogram constructs a new StandardHistogram from a Sample.
func NewHistogram(s Sample) Histogram { func NewHistogram(s Sample) Histogram {
if !Enabled { return &StandardHistogram{s}
return NilHistogram{}
}
return &StandardHistogram{sample: s}
} }
// NewRegisteredHistogram constructs and registers a new StandardHistogram from // NewRegisteredHistogram constructs and registers a new StandardHistogram from
@ -57,13 +54,6 @@ func NewRegisteredHistogram(name string, r Registry, s Sample) Histogram {
return c return c
} }
// NilHistogram is a no-op Histogram.
type NilHistogram struct{}
func (NilHistogram) Clear() {}
func (NilHistogram) Snapshot() HistogramSnapshot { return (*emptySnapshot)(nil) }
func (NilHistogram) Update(v int64) {}
// StandardHistogram is the standard implementation of a Histogram and uses a // StandardHistogram is the standard implementation of a Histogram and uses a
// Sample to bound its memory use. // Sample to bound its memory use.
type StandardHistogram struct { type StandardHistogram struct {