mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* metrics-generator: add custom registry * Redesign how series are stored, optimize writes over scrapes * lint & minor fixes * span-metrics: preallocate slice with label values * histogram: don't bother adding 0 to buckets * Introduce LabelValues to cache hashes; create dedicated counter and histogram types * Rename scrape -> metrics collection * fix e2e config * Tweak shutdown order of instance components * Add clarifying comment about max_active_series being a local limit * Replace __name__ with labels.MetricName * Extract duplicated logic when updating a series * Set onAddSeries and onRemoveSeries in the newX function * Remove commented code
36 lines
691 B
Go
36 lines
691 B
Go
package registry
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// job executes f every getInterval.
|
|
func job(ctx context.Context, f func(context.Context), getInterval func() time.Duration) {
|
|
currentInterval := getInterval()
|
|
ticker := time.NewTicker(currentInterval)
|
|
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
jobCtx, cancel := context.WithTimeout(ctx, currentInterval)
|
|
f(jobCtx)
|
|
cancel()
|
|
}
|
|
|
|
newInterval := getInterval()
|
|
if currentInterval != newInterval {
|
|
ticker = time.NewTicker(newInterval)
|
|
currentInterval = newInterval
|
|
}
|
|
}
|
|
}
|
|
|
|
func constantInterval(interval time.Duration) func() time.Duration {
|
|
return func() time.Duration {
|
|
return interval
|
|
}
|
|
}
|