-
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.
* New metric holder * Rename metric.Ctl constructor * Fix prometheus import name * Fix build * Add tests * Refactor metric controller * Remove updateTime & beautify * Fix nowTime & tests * Refactor metric controller * Add xtime package * Use xtime in metric holder * Rework holder & wrappers * Rework * Fix go mod * Some performance optimizations to the MetricHolder (#568) * Some performance optimizations * Rename RenameReleaser -> MetricDeleter * Benchmark prometheus.MetricVec * Replace parallel benchmark with the loop * Fix string copy * Add tests for the HeldMetric * Fix naming & build (#569) * Fix naming & build * Rollback comment * Update MetricHolder test * Add metric_hold_duration to pipeline settings * go mod tidy * Fix tests * Fix after merge * Fix tests
- Loading branch information
Showing
44 changed files
with
859 additions
and
446 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
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
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
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
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: newHeldMetricsStore[prometheus.Counter](), | ||
} | ||
} | ||
|
||
func (h HeldCounterVec) WithLabelValues(lvs ...string) HeldCounter { | ||
return HeldCounter{ | ||
heldMetric: h.store.GetOrCreate(lvs, h.vec.WithLabelValues), | ||
} | ||
} | ||
|
||
func (h HeldCounterVec) DeleteOldMetrics(holdDuration time.Duration) { | ||
h.store.DeleteOldMetrics(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: newHeldMetricsStore[prometheus.Gauge](), | ||
} | ||
} | ||
|
||
func (h HeldGaugeVec) WithLabelValues(lvs ...string) HeldGauge { | ||
return HeldGauge{ | ||
heldMetric: h.store.GetOrCreate(lvs, h.vec.WithLabelValues), | ||
} | ||
} | ||
|
||
func (h HeldGaugeVec) DeleteOldMetrics(holdDuration time.Duration) { | ||
h.store.DeleteOldMetrics(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: newHeldMetricsStore[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) DeleteOldMetrics(holdDuration time.Duration) { | ||
h.store.DeleteOldMetrics(holdDuration, h.vec) | ||
} |
Oops, something went wrong.