Skip to content

Commit

Permalink
PATCH: patches/com_github_scionproto_scion/metrics_reset_fix.patch
Browse files Browse the repository at this point in the history
Reset deleted all the timeseries irrespective of the labels set.
With this patch only the timeseries matching the labels are reset.

Reset for histograms is removed as prometheus client does not
implement reset on ObserverVec.
  • Loading branch information
sustrik authored and lukedirtwalker committed Jan 8, 2024
1 parent 8a71cb5 commit 5017744
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
9 changes: 0 additions & 9 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ type Gauge interface {
type Histogram interface {
With(labelValues ...string) Histogram
Observe(value float64)
Reset()
}

// CounterAdd increases the passed in counter by the amount specified.
Expand Down Expand Up @@ -174,11 +173,3 @@ func HistogramWith(h Histogram, labelValues ...string) Histogram {
}
return h.With(labelValues...)
}

// HistogramReset resets the passed in histogram.
// This is a no-op if h is nil.
func HistogramReset(h Histogram) {
if h != nil {
h.Reset()
}
}
9 changes: 2 additions & 7 deletions pkg/metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (g *gauge) Add(delta float64) {

// Reset deletes all metrics in this vector.
func (g *gauge) Reset() {
g.gv.Reset()
g.gv.MustCurryWith(makeLabels(g.lvs...)).Reset()
}

// newGauge wraps the GaugeVec and returns a usable Gauge object.
Expand Down Expand Up @@ -166,7 +166,7 @@ func (c *counter) Add(delta float64) {

// Reset deletes all metrics in this vector.
func (c *counter) Reset() {
c.cv.Reset()
c.cv.MustCurryWith(makeLabels(c.lvs...)).Reset()
}

// histogram implements Histogram via a Prometheus HistogramVec. The difference
Expand Down Expand Up @@ -205,11 +205,6 @@ func (h *histogram) Observe(value float64) {
h.hv.With(makeLabels(h.lvs...)).Observe(value)
}

// Reset deletes all metrics in this vector.
func (h *histogram) Reset() {
h.hv.Reset()
}

func makeLabels(labelValues ...string) prometheus.Labels {
labels := prometheus.Labels{}
for i := 0; i < len(labelValues); i += 2 {
Expand Down

0 comments on commit 5017744

Please sign in to comment.