Skip to content

Commit

Permalink
Add scrape loop test for disabling staleness marker.
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Gwizdala <17101802+thampiotr@users.noreply.github.com>
  • Loading branch information
thampiotr committed May 14, 2024
1 parent 3bb17ec commit 42dbced
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions scrape/scrape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3734,3 +3734,48 @@ scrape_configs:
require.Equal(t, expectedSchema, h.Schema)
}
}

func TestScrapeLoopDisableStalenessMarkerInjection(t *testing.T) {
var (
loopDone = make(chan struct{}, 1)
appender = &collectResultAppender{}
scraper = &testScraper{}
app = func(ctx context.Context) storage.Appender { return appender }
)

sl := newBasicScrapeLoop(t, context.Background(), scraper, app, 10*time.Millisecond)
// Count scrapes and terminate loop after 2 scrapes.
numScrapes, maxScrapes := 0, 2
scraper.scrapeFunc = func(ctx context.Context, w io.Writer) error {
numScrapes++
if numScrapes >= maxScrapes {
go sl.stop()
<-sl.ctx.Done()
}
if _, err := w.Write([]byte("metric_a 42\n")); err != nil {
return err
}
return ctx.Err()
}

go func() {
sl.run(nil)
loopDone <- struct{}{}
}()

// Disable end of run staleness markers.
sl.disableEndOfRunStalenessMarkers()

select {
case <-loopDone:
case <-time.After(5 * time.Second):
t.Fatalf("Scrape loop didn't stop.")
}

// No stale markers should be appended, since they were disabled.
for _, s := range appender.resultFloats {
if value.IsStaleNaN(s.f) {
t.Fatalf("Got stale NaN samples while end of run staleness is disabled: %x", math.Float64bits(s.f))
}
}
}

0 comments on commit 42dbced

Please sign in to comment.