-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea087c0
commit 03e5619
Showing
7 changed files
with
280 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package metric | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
type HeldCounter struct { | ||
*heldMetric[prometheus.Counter] | ||
} | ||
|
||
func (h HeldCounter) Inc() { | ||
h.metric.Inc() | ||
h.updateUsage() | ||
} | ||
|
||
func (h HeldCounter) Add(v float64) { | ||
h.metric.Add(v) | ||
h.updateUsage() | ||
} | ||
|
||
type HeldCounterVec struct { | ||
store *heldMetricsStore[prometheus.Counter] | ||
vec *prometheus.CounterVec | ||
} | ||
|
||
func NewHeldCounterVec(cv *prometheus.CounterVec) HeldCounterVec { | ||
return HeldCounterVec{ | ||
vec: cv, | ||
store: newHeldLabelsStore[prometheus.Counter](), | ||
} | ||
} | ||
|
||
func (h HeldCounterVec) WithLabelValues(lvs ...string) HeldCounter { | ||
return HeldCounter{ | ||
heldMetric: h.store.GetOrCreate(lvs, h.vec.WithLabelValues), | ||
} | ||
} | ||
|
||
func (h HeldCounterVec) ReleaseOldMetrics(holdDuration time.Duration) { | ||
h.store.ReleaseOldMetrics(holdDuration, h.vec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package metric | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
type HeldGauge struct { | ||
*heldMetric[prometheus.Gauge] | ||
} | ||
|
||
func (h HeldGauge) Set(v float64) { | ||
h.metric.Set(v) | ||
h.updateUsage() | ||
} | ||
|
||
func (h HeldGauge) Inc() { | ||
h.metric.Inc() | ||
h.updateUsage() | ||
} | ||
|
||
func (h HeldGauge) Dec() { | ||
h.metric.Dec() | ||
h.updateUsage() | ||
} | ||
|
||
func (h HeldGauge) Add(v float64) { | ||
h.metric.Add(v) | ||
h.updateUsage() | ||
} | ||
|
||
func (h HeldGauge) Sub(v float64) { | ||
h.metric.Sub(v) | ||
h.updateUsage() | ||
} | ||
|
||
type HeldGaugeVec struct { | ||
store *heldMetricsStore[prometheus.Gauge] | ||
vec *prometheus.GaugeVec | ||
} | ||
|
||
func NewHeldGaugeVec(gv *prometheus.GaugeVec) HeldGaugeVec { | ||
return HeldGaugeVec{ | ||
vec: gv, | ||
store: newHeldLabelsStore[prometheus.Gauge](), | ||
} | ||
} | ||
|
||
func (h HeldGaugeVec) WithLabelValues(lvs ...string) HeldGauge { | ||
return HeldGauge{ | ||
heldMetric: h.store.GetOrCreate(lvs, h.vec.WithLabelValues), | ||
} | ||
} | ||
|
||
func (h HeldGaugeVec) ReleaseOldMetrics(holdDuration time.Duration) { | ||
h.store.ReleaseOldMetrics(holdDuration, h.vec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package metric | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
type HeldHistogram struct { | ||
*heldMetric[prometheus.Histogram] | ||
} | ||
|
||
func (h HeldHistogram) Observe(v float64) { | ||
h.metric.Observe(v) | ||
h.updateUsage() | ||
} | ||
|
||
type HeldHistogramVec struct { | ||
store *heldMetricsStore[prometheus.Histogram] | ||
vec *prometheus.HistogramVec | ||
} | ||
|
||
func NewHeldHistogramVec(hv *prometheus.HistogramVec) HeldHistogramVec { | ||
return HeldHistogramVec{ | ||
vec: hv, | ||
store: newHeldLabelsStore[prometheus.Histogram](), | ||
} | ||
} | ||
|
||
func (h HeldHistogramVec) WithLabelValues(lvs ...string) HeldHistogram { | ||
return HeldHistogram{ | ||
heldMetric: h.store.GetOrCreate(lvs, func(s ...string) prometheus.Histogram { | ||
return h.vec.WithLabelValues(s...).(prometheus.Histogram) | ||
}), | ||
} | ||
} | ||
|
||
func (h HeldHistogramVec) ReleaseOldMetrics(holdDuration time.Duration) { | ||
h.store.ReleaseOldMetrics(holdDuration, h.vec) | ||
} |
Oops, something went wrong.