Skip to content

Conversation

@skartikey
Copy link
Contributor

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:

  1. Maintains its own isolated process cache
  2. Has correct filter tags on all emitted metrics
  3. Correctly tracks and cleans up stale processes independently

Additional Fixes:

  1. Variable shadowing: In the original code, if running, err := gp.IsRunning() shadowed the outer running map variable. Renamed to isRunning.
  2. Nil pointer dereference: The original code called process.setTag("process_name", ...) before process was initialized (inside the if !found block, before process = &proc{...}). Fixed by setting tags["process_name"] directly in the tags map.

Performance Impact:

Negligible - one additional O(1) map lookup per filter per Gather() call. The filterProcs reference is cached outside the inner loop, so per-process lookup cost is unchanged.

Checklist

Related issues

resolves #18041

…lision

  When multiple filters match the same process (PID), each filter now
  maintains its own isolated process cache entry. This ensures metrics
  are emitted with the correct filter tag instead of reusing the cached
  process from the first matching filter.

  Additionally fixes:
  - Variable shadowing where inner `running` boolean shadowed outer
    `running` map in gatherNew()
  - Potential nil pointer dereference when ProcessName was configured
    in new-style filter mode (setTag called before process initialized)
@telegraf-tiger telegraf-tiger bot added area/procstat fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Dec 22, 2025
@telegraf-tiger
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/procstat fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[inputs.procstat] Multuple filter matching same process

3 participants