Skip to content

otel: fix typeperf scrape mangled by cmd.exe quoting - #7

Merged
nficano merged 4 commits into
mainfrom
fix/otel-typeperf-cmd-quoting
Jun 5, 2026
Merged

otel: fix typeperf scrape mangled by cmd.exe quoting#7
nficano merged 4 commits into
mainfrom
fix/otel-typeperf-cmd-quoting

Conversation

@nficano

@nficano nficano commented Jun 5, 2026

Copy link
Copy Markdown
Owner

xpc otel export scraped host CPU/mem with a quoted typeperf counter path run through the agent's cmd.exe /c shell. cmd.exe mangles the % and spaces in \Processor(_Total)\% Processor Time, so typeperf receives it truncated at \%, reports No valid counters, and exits 0xF0000002 (4026531842). Every scrape failed → the VM was marked unreachable and no metrics were emitted (this showed up as ~5.9k ERROR logs/day in SigNoz from xpc-otel on mon-01).

The perf counters themselves are healthy (typeperf -q Processor lists them). Fix: run typeperf with an explicit argv via the python subprocess passthrough (buildSubprocessPy, shell=False) instead of cmd.exe — the same command-line quoting workaround already used for reg.exe in runRegPassthrough.

Verified against the live VM: returns valid PDH-CSV % Processor Time and Available Bytes.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced remote performance counter collection by improving command execution. The system now correctly handles counter paths containing special characters (% and spaces), preventing collection failures and data truncation, and ensuring reliable performance monitoring across all remote systems.

The otel export scraped host CPU/mem with:
  typeperf "\Processor(_Total)\% Processor Time" "\Memory\Available Bytes" -sc 1
run through the agent's cmd.exe /c shell. cmd.exe mangles the counter
path's '%' and spaces, so typeperf receives it truncated at '\%',
reports "No valid counters", and exits 0xF0000002 (4026531842). Every
scrape failed -> the VM was marked unreachable and no metrics were
emitted, even though the perf counters are healthy.

Run typeperf with an explicit argv via the python subprocess passthrough
(buildSubprocessPy, shell=False) instead of cmd.exe -- the same cmd.exe
command-line quoting workaround already used for reg.exe in
runRegPassthrough. Verified against the live VM: returns valid PDH-CSV
CPU% and Available Bytes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@nficano, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 3 minutes and 4 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8edde13a-d4d1-4d74-9055-21f4be820028

📥 Commits

Reviewing files that changed from the base of the PR and between abf302f and daeeb0f.

📒 Files selected for processing (2)
  • internal/cli/otel.go
  • internal/otel/provider.go
📝 Walkthrough

Walkthrough

The PR refactors the scrapeTypeperf function in internal/cli/otel.go to invoke typeperf via Python subprocess with explicit argv passthrough (shell=False) instead of a cmd-shell command string, with added comments explaining the prior quoting issues with counter paths containing % and spaces.

Changes

Typeperf subprocess execution refactor

Layer / File(s) Summary
Typeperf subprocess argv passthrough
internal/cli/otel.go
The remote typeperf invocation is changed from runRemoteCmd(..., cmdLine, "cmd") to runRemoteCmd(..., py, "python") using buildSubprocessPy(...) for explicit argv passthrough. Inline comments document the prior cmd.exe quoting issue with % and spaces in counter paths, and how argv passthrough prevents counter-path truncation/mangling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A shell once mangled paths with care,
Percent signs tangled in the air,
But Python's argv saves the day,
No more quoting leads astray!
Direct and true, the counters fly,
Typeperf runs, no more dry!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: fixing a typeperf issue caused by cmd.exe quoting that was mangling counter paths. It directly corresponds to the changeset's primary objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/otel-typeperf-cmd-quoting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

nficano and others added 3 commits June 5, 2026 11:43
The python passthrough's text-mode stdout on Windows rewrites typeperf's
\r\n line endings to \r\r\n. encoding/csv then fails to parse the data
row, so host.cpu.utilization / host.memory.available were never emitted
(scrape still 'succeeded' rc=0, so the VM showed reachable but with no
CPU/mem). Normalize by stripping all CRs before CSV parsing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… types)

eventquery.vbs renders the Type column in lower case on this XP build
("information"/"warning"/"error"), but isEventType and severityFor only
matched Title case. parseEventCSV therefore never located the type column,
returned zero entries, and EmitLogs was never called -- so the logs signal
emitted nothing (metrics were fine; reachable=1 with no event logs). Match
case-insensitively in both. Verified: parseEventCSV now returns entries for
lowercase eventquery output.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…time

eventquery.vbs reports event times in the host's local clock with no tz.
The collector parsed them as its own tz (UTC), so a Pacific VM's events
landed ~7h in the past -- invisible in normal SigNoz time windows even
though they were ingested fine. Use the scrape (observed) time as the
record timestamp for this near-real-time, no-backfill tailer, and keep the
host-local clock as an 'event.time' attribute.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nficano
nficano merged commit d5579ea into main Jun 5, 2026
5 checks passed
@nficano
nficano deleted the fix/otel-typeperf-cmd-quoting branch June 5, 2026 16:36
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.

1 participant