TestScrapeLoopCache: Display content of the appender (#10937)

This should help identifying windows tests flakiness.

Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
This commit is contained in:
Julien Pivotto 2022-07-01 14:28:56 +02:00 committed by GitHub
parent 02f3297719
commit 90583c8906
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View file

@ -15,7 +15,9 @@ package scrape
import ( import (
"context" "context"
"fmt"
"math/rand" "math/rand"
"strings"
"github.com/prometheus/prometheus/model/exemplar" "github.com/prometheus/prometheus/model/exemplar"
"github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/labels"
@ -106,3 +108,17 @@ func (a *collectResultAppender) Rollback() error {
} }
return a.next.Rollback() 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()
}

View file

@ -1125,7 +1125,7 @@ func TestScrapeLoopRunCreatesStaleMarkersOnFailedScrape(t *testing.T) {
// 1 successfully scraped sample, 1 stale marker after first fail, 5 report samples for // 1 successfully scraped sample, 1 stale marker after first fail, 5 report samples for
// each scrape successful or not. // 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.Equal(t, 42.0, appender.result[0].v, "Appended first sample not as expected")
require.True(t, value.IsStaleNaN(appender.result[6].v), 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)) "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 // 1 successfully scraped sample, 1 stale marker after first fail, 5 report samples for
// each scrape successful or not. // 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.Equal(t, 42.0, appender.result[0].v, "Appended first sample not as expected")
require.True(t, value.IsStaleNaN(appender.result[6].v), 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)) "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 // 1 successfully scraped sample, 1 stale marker after first fail, 5 report samples for
// each scrape successful or not. // 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) { func TestScrapeLoopCacheMemoryExhaustionProtection(t *testing.T) {
@ -1642,7 +1642,7 @@ func TestScrapeLoopAppendSampleLimit(t *testing.T) {
v: 1, 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() now = time.Now()
slApp = sl.appender(context.Background()) slApp = sl.appender(context.Background())
@ -1707,7 +1707,7 @@ func TestScrapeLoop_ChangingMetricString(t *testing.T) {
v: 2, 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) { func TestScrapeLoopAppendStaleness(t *testing.T) {
@ -1759,7 +1759,7 @@ func TestScrapeLoopAppendStaleness(t *testing.T) {
v: 42, 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) { func TestScrapeLoopAppendNoStalenessIfTimestamp(t *testing.T) {
@ -1800,7 +1800,7 @@ func TestScrapeLoopAppendNoStalenessIfTimestamp(t *testing.T) {
v: 1, 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) { func TestScrapeLoopAppendExemplar(t *testing.T) {
@ -2108,7 +2108,7 @@ func TestScrapeLoopAppendGracefullyIfAmendOrOutOfOrderOrOutOfBounds(t *testing.T
v: 1, 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, total)
require.Equal(t, 4, added) require.Equal(t, 4, added)
require.Equal(t, 1, seriesAdded) require.Equal(t, 1, seriesAdded)
@ -2410,7 +2410,7 @@ func TestScrapeLoop_RespectTimestamps(t *testing.T) {
v: 1, 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) { func TestScrapeLoop_DiscardTimestamps(t *testing.T) {
@ -2451,7 +2451,7 @@ func TestScrapeLoop_DiscardTimestamps(t *testing.T) {
v: 1, 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) { func TestScrapeLoopDiscardDuplicateLabels(t *testing.T) {