Skip to content

Suppress RPC metrics for agent health check loopback calls - #6929

Merged
sorindumitru merged 1 commit into
spiffe:mainfrom
rausingh-rh:fix-health-check-metrics-pollution
May 18, 2026
Merged

sorindumitru merged 1 commit into
spiffe:mainfrom
rausingh-rh:fix-health-check-metrics-pollution

Conversation

@rausingh-rh

Copy link
Copy Markdown
Contributor

Pull Request check list

  • Commit conforms to CONTRIBUTING.md?
  • Proper tests/regressions included?
  • Documentation updated?

Affected functionality

Agent RPC metrics for Workload API calls made by the agent's own health check (both the gRPC Health/Check service and the HTTP /ready /live endpoints). These internal loopback calls no longer emit per-call RPC metrics (counter and elapsed_time). Connection metrics are unaffected. Metrics for calls from real workloads are unaffected.

Description of change

  • Added Discard() method to telemetry.CallCounter that marks the counter as done without emitting metrics
  • Added discardAgentCallMetrics postprocess middleware step in the agent endpoint middleware chain that checks the caller PID via peertracker; when the caller is the agent itself, the RPC call counter is discarded
  • Updated existing integration tests to reflect that agent-PID calls no longer emit RPC metrics
  • Added regression test TestAgentCallMetricsDiscarded with three cases: agent PID (suppressed), non-agent PID (emitted), and no peertracker (emitted)

Which issue this PR fixes

Fixes #5335

@rausingh-rh
rausingh-rh force-pushed the fix-health-check-metrics-pollution branch from b790366 to 8482381 Compare May 3, 2026 12:01
@sorindumitru sorindumitru self-assigned this May 7, 2026
@rausingh-rh
rausingh-rh force-pushed the fix-health-check-metrics-pollution branch 2 times, most recently from fcf42de to 2f1ae52 Compare May 11, 2026 17:02
The agent health check exercises the Workload API by making loopback
calls (FetchX509Context and FetchX509Bundles) to its own UDS socket.
These calls return PermissionDenied because the agent has no workload
registration entry for itself, which is expected and treated as healthy.
However, the RPC metrics middleware records these as
status="PermissionDenied", polluting metrics and making it impossible
to distinguish real workload permission errors from health check noise.

Add a Discard() method to CallCounter and a postprocess middleware step
that checks the caller PID via peertracker. When the caller is the
agent itself (os.Getpid()), the RPC call counter is discarded before
the metrics middleware can emit. This follows the existing pattern used
for log suppression in the workload handler (isAgent/quietLogging).

Fixes spiffe#5335

Signed-off-by: Raushan Singh <[email protected]>
@rausingh-rh
rausingh-rh force-pushed the fix-health-check-metrics-pollution branch from 2f1ae52 to 609b0db Compare May 18, 2026 08:50

@sorindumitru sorindumitru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @rausingh-rh!

@sorindumitru sorindumitru added this to the 1.15.1 milestone May 18, 2026
@sorindumitru
sorindumitru added this pull request to the merge queue May 18, 2026
Merged via the queue into spiffe:main with commit dcd2d62 May 18, 2026
50 checks passed
MikeZappa87 pushed a commit to MikeZappa87/spire that referenced this pull request May 29, 2026
The agent health check exercises the Workload API by making loopback
calls (FetchX509Context and FetchX509Bundles) to its own UDS socket.
These calls return PermissionDenied because the agent has no workload
registration entry for itself, which is expected and treated as healthy.
However, the RPC metrics middleware records these as
status="PermissionDenied", polluting metrics and making it impossible
to distinguish real workload permission errors from health check noise.

Add a Discard() method to CallCounter and a postprocess middleware step
that checks the caller PID via peertracker. When the caller is the
agent itself (os.Getpid()), the RPC call counter is discarded before
the metrics middleware can emit. This follows the existing pattern used
for log suppression in the workload handler (isAgent/quietLogging).

Fixes spiffe#5335

Signed-off-by: Raushan Singh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spire-agent health check report spire_agent_rpc_workload_api_fetch_x509_bundles{status="PermissionDenied"} metrics

2 participants