MCPcopy
hub / github.com/grafana/k6 / TestCollectorCollectSample

Function TestCollectorCollectSample

output/cloud/expv2/collect_test.go:24–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestCollectorCollectSample(t *testing.T) {
25 t.Parallel()
26
27 r := metrics.NewRegistry()
28 m1, err := r.NewMetric("metric1", metrics.Counter)
29 require.NoError(t, err)
30
31 tags := r.RootTagSet().With("t1", "v1")
32 samples := metrics.Samples(make([]metrics.Sample, 3))
33
34 c := collector{
35 aggregationPeriod: 3 * time.Second,
36 waitPeriod: 1 * time.Second,
37 timeBuckets: make(map[int64]map[metrics.TimeSeries]metricValue),
38 nowFunc: func() time.Time {
39 return time.Unix(31, 0)
40 },
41 }
42 for i := range samples {
43 sample := metrics.Sample{
44 TimeSeries: metrics.TimeSeries{
45 Metric: m1,
46 Tags: tags,
47 },
48 Value: 1.0,
49 Time: time.Unix(int64((i+1)*10), 0), // 10, 20, 30
50 }
51 c.collectSample(sample)
52 }
53
54 assert.Len(t, c.timeBuckets, 3)
55}
56
57func TestCollectorCollectSampleAggregateNumbers(t *testing.T) {
58 t.Parallel()

Callers

nothing calls this directly

Calls 7

NewMetricMethod · 0.95
RootTagSetMethod · 0.95
collectSampleMethod · 0.95
NewRegistryFunction · 0.92
SamplesTypeAlias · 0.92
WithMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…