Fix max measurements gauge test (#14024)

* make streamGaugesToSink batch size a const

* attempt to fix for timeout failures for TestGauge_MaximumMeasurements
This commit is contained in:
Chris Capurso 2022-02-23 13:36:25 -05:00 committed by GitHub
parent 35d3d4226d
commit 708cd96bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -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 {

View File

@ -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)
}