fix(loki-logger): prevent log_labels cross-request leakage#13326
Open
Adarsh879 wants to merge 1 commit intoapache:masterfrom
Open
fix(loki-logger): prevent log_labels cross-request leakage#13326Adarsh879 wants to merge 1 commit intoapache:masterfrom
Adarsh879 wants to merge 1 commit intoapache:masterfrom
Conversation
Signed-off-by: Adarsh879 <asadarsh879@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
loki-loggermutatesconf.log_labelsin place when substituting$variableplaceholders, then captures that shared table in thebatch-processor flush closure. The early return at
add_entrycausesall subsequent requests on the same worker to skip the resolution
block, so every later entry flushes with the first request's
resolved labels. Symptom: log entries where
log_labelsandlog_formatdisagree on the same line (#12485), or a stream labelthat carries a value from a different request than the one whose
body it accompanies.
The bug affects
loki-loggerat any scope where multiple requestsshare the same conf and a
$variableinlog_labelsresolves todifferent values per request — so it surfaces in real deployments
both at global-rule and at service scope.
Root cause (pre-fix)
Fix
conf.log_labels.entry.loki_labels).one Loki stream per group within the push (Loki's
streamsAPIalready supports this, so batching is preserved).
The change is fully contained to
apisix/plugins/loki-logger.lua—nothing in
plugin.lua,batch-processor-manager.lua, or otherplugins is touched.
Test
t/plugin/loki-logger.tTEST 17–19 (modeled on the existing TEST12–14 pattern):
log_labels: { custom_label: "$arg_X" }and
batch_max_size: 1./hello?X=alphathen/hello?X=beta.{custom_label="beta"}. Without the fix thesecond request's value never reaches Loki (the worker resolved
"alpha"once and reused it forever), so the assertion fails.With the fix, both stream labels exist.
Verified locally:
no entries with custom_label=betaWhich issue(s) this PR fixes:
Fixes #12485
Checklist