prometheus/scrape
TJ Hoplock 3e24e84172 fix!: stop unbounded memory usage from query log
Resolves: #15433

When I converted prometheus to use slog in #14906, I update both the
`QueryLogger` interface, as well as how the log calls to the
`QueryLogger` were built up in `promql.Engine.exec()`. The backing
logger for the `QueryLogger` in the engine is a
`util/logging.JSONFileLogger`, and it's implementation of the `With()`
method updates the logger the logger in place with the new keyvals added
onto the underlying slog.Logger, which means they get inherited onto
everything after. All subsequent calls to `With()`, even in later
queries, would continue to then append on more and more keyvals for the
various params and fields built up in the logger. In turn, this causes
unbounded growth of the logger, leading to increased memory usage, and
in at least one report was the likely cause of an OOM kill. More
information can be found in the issue and the linked slack thread.

This commit does a few things:

- It was referenced in feedback in #14906 that it would've been better
  to not change the `QueryLogger` interface if possible, this PR
proposes changes that bring it closer to alignment with the pre-3.0
`QueryLogger` interface contract
- reverts `promql.Engine.exec()`'s usage of the query logger to the
  pattern of building up an array of args to pass at once to the end log
call. Avoiding the repetitious calls to `.With()` are what resolve the
issue with the logger growth/memory usage.
- updates the scrape failure logger to use the update `QueryLogger`
  methods in the contract.
- updates tests accordingly
- cleans up unused methods

Builds and passes tests successfully. Tested locally and confirmed I
could no longer reproduce the issue/it resolved the issue.

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
2024-11-23 14:20:37 -05:00
..
testdata Include test CA text info (#14699) 2024-08-20 19:41:02 +02:00
clientprotobuf.go lint: Revamp our linting rules, mostly around doc comments 2024-08-22 17:36:11 +02:00
helpers_test.go TSDB: Fix some edge cases when OOO is enabled (#14710) 2024-10-23 17:34:28 +02:00
manager.go Rename convert_classic_histograms to convert_classic_histograms_to_nhcb 2024-10-21 13:22:58 +02:00
manager_test.go chore!: adopt log/slog, remove go-kit/log 2024-10-07 15:58:50 -04:00
metrics.go Scraping: add metric for symbol table size 2024-07-05 10:16:22 +01:00
scrape.go fix!: stop unbounded memory usage from query log 2024-11-23 14:20:37 -05:00
scrape_test.go scrape: stop erroring on empty scrapes 2024-11-07 11:30:03 +00:00
target.go Remove no-default-scrape-port featureFlag 2024-09-25 10:13:19 -05:00
target_test.go Remove no-default-scrape-port featureFlag 2024-09-25 10:13:19 -05:00