mirror of
https://github.com/prometheus/prometheus.git
synced 2026-04-14 18:21:02 +02:00
* Adding scape on shutdown Signed-off-by: avilevy <avilevy@google.com> * scrape: replace skipOffsetting to make the test offset deterministic instead of skipping it entirely Signed-off-by: avilevy <avilevy@google.com> * renamed calculateScrapeOffset to getScrapeOffset Signed-off-by: avilevy <avilevy@google.com> * test(scrape): refactor time-based manager tests to use synctest Addresses PR feedback to remove flaky, time-based sleeping in the scrape manager tests. Add TestManager_InitialScrapeOffset and TestManager_ScrapeOnShutdown to use the testing/synctest package, completely eliminating real-world time.Sleep delays and making the assertions 100% deterministic. - Replaced httptest.Server with net.Pipe and a custom startFakeHTTPServer helper to ensure all network I/O remains durably blocked inside the synctest bubble. - Leveraged the skipOffsetting option to eliminate random scrape jitter, making the time-travel math exact and predictable. - Using skipOffsetting also safely bypasses the global singleflight DNS lookup in setOffsetSeed, which previously caused cross-bubble panics in synctest. - Extracted shared boilerplate into a setupSynctestManager helper to keep the test cases highly readable and data-driven. Signed-off-by: avilevy <avilevy@google.com> * Clarify use cases in InitialScrapeOffset comment Signed-off-by: avilevy <avilevy@google.com> * test(scrape): use httptest for mock server to respect context cancellation - Replaced manual HTTP string formatting over `net.Pipe` with `httptest.NewUnstartedServer`. - Implemented an in-memory `pipeListener` to allow the server to handle `net.Pipe` connections directly. This preserves `synctest` time isolation without opening real OS ports. - Added explicit `r.Context().Done()` handling in the mock HTTP handler to properly simulate aborted requests and scrape timeouts. - Validates that the request context remains active and is not prematurely cancelled during `ScrapeOnShutdown` scenarios. - Renamed `skipOffsetting` to `skipJitterOffsetting`. - Addressed other PR comments. Signed-off-by: avilevy <avilevy@google.com> * tmp Signed-off-by: bwplotka <bwplotka@gmail.com> * exp2 Signed-off-by: bwplotka <bwplotka@gmail.com> * fix Signed-off-by: bwplotka <bwplotka@gmail.com> * scrape: fix scrapeOnShutdown context bug and refactor test helpers The scrapeOnShutdown feature was failing during manager shutdown because the scrape pool context was being cancelled before the final shutdown scrapes could execute. Fix this by delaying context cancellation in scrapePool.stop() until after all scrape loops have stopped. In addition: - Added test cases to verify scrapeOnShutdown works with InitialScrapeOffset. - Refactored network test helper functions from manager_test.go to helpers_test.go. - Addressed other comments. Signed-off-by: avilevy <avilevy@google.com> * Update scrape/scrape.go Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com> Signed-off-by: avilevy18 <105948922+avilevy18@users.noreply.github.com> --------- Signed-off-by: avilevy <avilevy@google.com> Signed-off-by: bwplotka <bwplotka@gmail.com> Signed-off-by: avilevy18 <105948922+avilevy18@users.noreply.github.com> Co-authored-by: bwplotka <bwplotka@gmail.com>