Browse Source

TestScrapeLoopCache: Display content of the appender (#10937)

This should help identifying windows tests flakiness.

Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
pull/10958/head
Julien Pivotto 2 years ago committed by GitHub
parent
commit
90583c8906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      scrape/helpers_test.go
  2. 20
      scrape/scrape_test.go

16
scrape/helpers_test.go

@ -15,7 +15,9 @@ package scrape
import (
"context"
"fmt"
"math/rand"
"strings"
"github.com/prometheus/prometheus/model/exemplar"
"github.com/prometheus/prometheus/model/labels"
@ -106,3 +108,17 @@ func (a *collectResultAppender) Rollback() error {
}
return a.next.Rollback()
}
func (a *collectResultAppender) String() string {
var sb strings.Builder
for _, s := range a.result {
sb.WriteString(fmt.Sprintf("committed: %s %f %d\n", s.metric, s.v, s.t))
}
for _, s := range a.pendingResult {
sb.WriteString(fmt.Sprintf("pending: %s %f %d\n", s.metric, s.v, s.t))
}
for _, s := range a.rolledbackResult {
sb.WriteString(fmt.Sprintf("rolledback: %s %f %d\n", s.metric, s.v, s.t))
}
return sb.String()
}

20
scrape/scrape_test.go

@ -1125,7 +1125,7 @@ func TestScrapeLoopRunCreatesStaleMarkersOnFailedScrape(t *testing.T) {
// 1 successfully scraped sample, 1 stale marker after first fail, 5 report samples for
// each scrape successful or not.
require.Equal(t, 27, len(appender.result), "Appended samples not as expected")
require.Equal(t, 27, len(appender.result), "Appended samples not as expected:\n%s", appender)
require.Equal(t, 42.0, appender.result[0].v, "Appended first sample not as expected")
require.True(t, value.IsStaleNaN(appender.result[6].v),
"Appended second sample not as expected. Wanted: stale NaN Got: %x", math.Float64bits(appender.result[6].v))
@ -1189,7 +1189,7 @@ func TestScrapeLoopRunCreatesStaleMarkersOnParseFailure(t *testing.T) {
// 1 successfully scraped sample, 1 stale marker after first fail, 5 report samples for
// each scrape successful or not.
require.Equal(t, 17, len(appender.result), "Appended samples not as expected")
require.Equal(t, 17, len(appender.result), "Appended samples not as expected:\n%s", appender)
require.Equal(t, 42.0, appender.result[0].v, "Appended first sample not as expected")
require.True(t, value.IsStaleNaN(appender.result[6].v),
"Appended second sample not as expected. Wanted: stale NaN Got: %x", math.Float64bits(appender.result[6].v))
@ -1272,7 +1272,7 @@ func TestScrapeLoopCache(t *testing.T) {
// 1 successfully scraped sample, 1 stale marker after first fail, 5 report samples for
// each scrape successful or not.
require.Equal(t, 26, len(appender.result), "Appended samples not as expected")
require.Equal(t, 26, len(appender.result), "Appended samples not as expected:\n%s", appender)
}
func TestScrapeLoopCacheMemoryExhaustionProtection(t *testing.T) {
@ -1642,7 +1642,7 @@ func TestScrapeLoopAppendSampleLimit(t *testing.T) {
v: 1,
},
}
require.Equal(t, want, resApp.rolledbackResult, "Appended samples not as expected")
require.Equal(t, want, resApp.rolledbackResult, "Appended samples not as expected:\n%s", appender)
now = time.Now()
slApp = sl.appender(context.Background())
@ -1707,7 +1707,7 @@ func TestScrapeLoop_ChangingMetricString(t *testing.T) {
v: 2,
},
}
require.Equal(t, want, capp.result, "Appended samples not as expected")
require.Equal(t, want, capp.result, "Appended samples not as expected:\n%s", appender)
}
func TestScrapeLoopAppendStaleness(t *testing.T) {
@ -1759,7 +1759,7 @@ func TestScrapeLoopAppendStaleness(t *testing.T) {
v: 42,
},
}
require.Equal(t, want, app.result, "Appended samples not as expected")
require.Equal(t, want, app.result, "Appended samples not as expected:\n%s", appender)
}
func TestScrapeLoopAppendNoStalenessIfTimestamp(t *testing.T) {
@ -1800,7 +1800,7 @@ func TestScrapeLoopAppendNoStalenessIfTimestamp(t *testing.T) {
v: 1,
},
}
require.Equal(t, want, app.result, "Appended samples not as expected")
require.Equal(t, want, app.result, "Appended samples not as expected:\n%s", appender)
}
func TestScrapeLoopAppendExemplar(t *testing.T) {
@ -2108,7 +2108,7 @@ func TestScrapeLoopAppendGracefullyIfAmendOrOutOfOrderOrOutOfBounds(t *testing.T
v: 1,
},
}
require.Equal(t, want, app.result, "Appended samples not as expected")
require.Equal(t, want, app.result, "Appended samples not as expected:\n%s", appender)
require.Equal(t, 4, total)
require.Equal(t, 4, added)
require.Equal(t, 1, seriesAdded)
@ -2410,7 +2410,7 @@ func TestScrapeLoop_RespectTimestamps(t *testing.T) {
v: 1,
},
}
require.Equal(t, want, capp.result, "Appended samples not as expected")
require.Equal(t, want, capp.result, "Appended samples not as expected:\n%s", appender)
}
func TestScrapeLoop_DiscardTimestamps(t *testing.T) {
@ -2451,7 +2451,7 @@ func TestScrapeLoop_DiscardTimestamps(t *testing.T) {
v: 1,
},
}
require.Equal(t, want, capp.result, "Appended samples not as expected")
require.Equal(t, want, capp.result, "Appended samples not as expected:\n%s", appender)
}
func TestScrapeLoopDiscardDuplicateLabels(t *testing.T) {

Loading…
Cancel
Save