fix(inputs.procstat): Isolate process cache per filter to fix tag collision #18144
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.
Summary
The process cache was keyed only by PID
(map[pid]process). When multiple filters matched the same process, the second filter would find the cached process from the first filter and reuse it, emitting metrics with the wrong filter tag.Fix:
Changed the process cache to a nested map keyed by filter name and PID
(map[string]map[pid]process). Each filter now:Additional Fixes:
if running, err := gp.IsRunning()shadowed the outerrunningmap variable. Renamed toisRunning.process.setTag("process_name", ...)beforeprocesswas initialized (inside theif !foundblock, beforeprocess = &proc{...}). Fixed by settingtags["process_name"]directly in the tags map.Performance Impact:
Negligible - one additional O(1) map lookup per filter per Gather() call. The
filterProcsreference is cached outside the inner loop, so per-process lookup cost is unchanged.Checklist
Related issues
resolves #18041