prometheus/util
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
..
almost [COMMENT] Improve comment on almost.Equal; add tests 2024-08-30 10:13:00 +01:00
annotations Corrects the behaviour of binary opperators between histogram and float (#14726) 2024-10-15 14:44:36 +02:00
convertnhcb convertnhcb: use CutSuffix instead of regex replace for histogram name 2024-10-14 16:50:05 +02:00
documentcli Add support for multiple listening addresses 2024-08-20 13:09:16 +02:00
fmtutil chore: Fix typos (#14868) 2024-09-10 22:32:03 +02:00
gate Move packages out of deprecated pkg directory 2021-11-09 08:03:10 +01:00
httputil golangci-lint: enable usestdlibvars linter 2024-04-08 19:26:23 +00:00
jsonutil Name float values as "floats", not as "values" 2023-04-13 19:25:24 +02:00
junitxml promtool: JUnit-Format XML Test Results (#14506) 2024-07-29 21:28:08 +10:00
logging fix!: stop unbounded memory usage from query log 2024-11-23 14:20:37 -05:00
netconnlimit Add support for multiple listening addresses 2024-08-20 13:09:16 +02:00
notifications Move notifications in utils 2024-10-04 10:11:56 +02:00
osutil Format Go source files using 'gofumpt -w -s -extra' 2021-11-02 19:52:34 +01:00
pool Move packages out of deprecated pkg directory 2021-11-09 08:03:10 +01:00
runtime chore: Fix typos (#14868) 2024-09-10 22:32:03 +02:00
runutil Append Created Timestamps (#12733) 2023-12-11 08:43:42 +00:00
stats Move from golang.org/x/exp/slices into slices now that we only support Go >= 1.21 2024-02-28 14:54:53 +01:00
strutil Implement SanitizeLabelName and Full variant 2023-02-03 15:28:33 +00:00
teststorage TSDB: Fix some edge cases when OOO is enabled (#14710) 2024-10-23 17:34:28 +02:00
testutil chore!: adopt log/slog, remove go-kit/log 2024-10-07 15:58:50 -04:00
treecache chore!: adopt log/slog, remove go-kit/log 2024-10-07 15:58:50 -04:00
zeropool chore: Fix typos (#14868) 2024-09-10 22:32:03 +02:00