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
50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package registry
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_job(t *testing.T) {
|
|
interval := durationPtr(200 * time.Millisecond)
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
var jobTimes []time.Duration
|
|
lastRun := time.Now()
|
|
|
|
go job(
|
|
ctx,
|
|
func(_ context.Context) {
|
|
diff := time.Since(lastRun)
|
|
lastRun = time.Now()
|
|
|
|
jobTimes = append(jobTimes, diff)
|
|
fmt.Println(diff)
|
|
|
|
*interval = *interval + (20 * time.Millisecond)
|
|
},
|
|
func() time.Duration {
|
|
return *interval
|
|
},
|
|
)
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
cancel()
|
|
|
|
require.Len(t, jobTimes, 4)
|
|
require.InDelta(t, 200*time.Millisecond, jobTimes[0], float64(10*time.Millisecond))
|
|
require.InDelta(t, 220*time.Millisecond, jobTimes[1], float64(10*time.Millisecond))
|
|
require.InDelta(t, 240*time.Millisecond, jobTimes[2], float64(10*time.Millisecond))
|
|
require.InDelta(t, 260*time.Millisecond, jobTimes[3], float64(10*time.Millisecond))
|
|
}
|
|
|
|
func durationPtr(d time.Duration) *time.Duration {
|
|
return &d
|
|
}
|