(t *testing.T)
| 265 | } |
| 266 | |
| 267 | func TestUpdateMetrics_MetricsExpire(t *testing.T) { |
| 268 | t.Parallel() |
| 269 | |
| 270 | // given |
| 271 | registry := prometheus.NewRegistry() |
| 272 | metricsAggregator, err := prometheusmetrics.NewMetricsAggregator(slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}), registry, time.Millisecond, agentmetrics.LabelAll) |
| 273 | require.NoError(t, err) |
| 274 | |
| 275 | ctx, cancelFunc := context.WithCancel(context.Background()) |
| 276 | t.Cleanup(cancelFunc) |
| 277 | |
| 278 | closeFunc := metricsAggregator.Run(ctx) |
| 279 | t.Cleanup(closeFunc) |
| 280 | |
| 281 | given := []*agentproto.Stats_Metric{ |
| 282 | {Name: "a_counter_one", Type: agentproto.Stats_Metric_COUNTER, Value: 1}, |
| 283 | } |
| 284 | |
| 285 | // when |
| 286 | metricsAggregator.Update(ctx, testLabels, given) |
| 287 | |
| 288 | time.Sleep(time.Millisecond * 10) // Ensure that metric is expired |
| 289 | |
| 290 | // then |
| 291 | require.Eventually(t, func() bool { |
| 292 | var actual []prometheus.Metric |
| 293 | metricsCh := make(chan prometheus.Metric) |
| 294 | |
| 295 | done := make(chan struct{}, 1) |
| 296 | defer close(done) |
| 297 | go func() { |
| 298 | for m := range metricsCh { |
| 299 | actual = append(actual, m) |
| 300 | } |
| 301 | done <- struct{}{} |
| 302 | }() |
| 303 | metricsAggregator.Collect(metricsCh) |
| 304 | close(metricsCh) |
| 305 | <-done |
| 306 | return len(actual) == 0 |
| 307 | }, testutil.WaitShort, testutil.IntervalFast) |
| 308 | } |
| 309 | |
| 310 | func TestLabelsAggregation(t *testing.T) { |
| 311 | t.Parallel() |
nothing calls this directly
no test coverage detected