From 708cd96bb8fb3c288d96dfcf5ff0868eafb8bf11 Mon Sep 17 00:00:00 2001 From: Chris Capurso Date: Wed, 23 Feb 2022 13:36:25 -0500 Subject: [PATCH] Fix max measurements gauge test (#14024) * make streamGaugesToSink batch size a const * attempt to fix for timeout failures for TestGauge_MaximumMeasurements --- helper/metricsutil/gauge_process.go | 6 ++++-- helper/metricsutil/gauge_process_test.go | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/helper/metricsutil/gauge_process.go b/helper/metricsutil/gauge_process.go index ce43d29d8..fd327bc68 100644 --- a/helper/metricsutil/gauge_process.go +++ b/helper/metricsutil/gauge_process.go @@ -197,16 +197,18 @@ func (p *GaugeCollectionProcess) collectAndFilterGauges() { p.streamGaugesToSink(values) } +// batchSize is the number of metrics to be sent per tick duration. +const batchSize = 25 + func (p *GaugeCollectionProcess) streamGaugesToSink(values []GaugeLabelValues) { // Dumping 500 metrics in one big chunk is somewhat unfriendly to UDP-based // transport, and to the rest of the metrics trying to get through. // Let's smooth things out over the course of a second. - // 1 second / 500 = 2 ms each, so we can send 25 per 50 milliseconds. + // 1 second / 500 = 2 ms each, so we can send 25 (batchSize) per 50 milliseconds. // That should be one or two packets. sendTick := p.clock.NewTicker(50 * time.Millisecond) defer sendTick.Stop() - batchSize := 25 for i, lv := range values { if i > 0 && i%batchSize == 0 { select { diff --git a/helper/metricsutil/gauge_process_test.go b/helper/metricsutil/gauge_process_test.go index 5e83e6fe4..89ef813a8 100644 --- a/helper/metricsutil/gauge_process_test.go +++ b/helper/metricsutil/gauge_process_test.go @@ -433,11 +433,11 @@ func TestGauge_MaximumMeasurements(t *testing.T) { 2000000*time.Hour) sink := NewClusterMetricSink("test", inmemSink) - sink.MaxGaugeCardinality = 500 + sink.MaxGaugeCardinality = 100 sink.GaugeInterval = 2 * time.Hour // Create a report larger than the default limit - excessGauges := 100 + excessGauges := 20 values := makeLabels(sink.MaxGaugeCardinality + excessGauges) rand.Shuffle(len(values), func(i, j int) { values[i], values[j] = values[j], values[i] @@ -468,9 +468,9 @@ func TestGauge_MaximumMeasurements(t *testing.T) { sendTicker := s.waitForTicker(t) numTicksSent := waitForDone(t, sendTicker.sender, done) - // 500 items, one delay after after each 25, means that - // 19 ticks are consumed, so 19 or 20 must be sent. - expectedTicks := sink.MaxGaugeCardinality/25 - 1 + // 100 items, one delay after each batchSize (25), means that + // 3 ticks are consumed, so 3 or 4 must be sent. + expectedTicks := sink.MaxGaugeCardinality/batchSize - 1 if numTicksSent < expectedTicks || numTicksSent > expectedTicks+1 { t.Errorf("Number of ticks = %v, expected %v.", numTicksSent, expectedTicks) }