Skip to content

Minor pcp-atop updates#2653

Merged
natoscott merged 3 commits into
performancecopilot:mainfrom
natoscott:pcp-atop-labels
Jul 13, 2026
Merged

Minor pcp-atop updates#2653
natoscott merged 3 commits into
performancecopilot:mainfrom
natoscott:pcp-atop-labels

Conversation

@natoscott

Copy link
Copy Markdown
Member

Add archive labels from the context, fix double compression of daily logs.

natoscott and others added 2 commits July 13, 2026 10:42
Add rawwrite_init_labels() which writes an {"atop": true} creator
label then copies all context-level labels from the live PMAPI context
(hostname, domain, machineid, etc.) into the PMI archive via
pmiPutLabel.

Updated qa/1089 to verify atop creator label in recorded archive.

Fixed pmiPutLabel to pass through already-valid JSON values (such
as quoted strings, numbers, true/false/null) verbatim rather than
double-quoting them.  Previously numbers became strings and quoted
strings got escaped quotes.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
The glob "$base".[0-9]* matched already-compressed .N.zst files
(e.g., .0.zst matches because [0-9]* covers "0.zst").  These were
renamed to .0.zst.tmp and re-compressed to .0.zst.zst.

Skip files with .zst or .xz suffixes in the rename loop so only
raw uncompressed volumes are staged for compression.

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

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: f05b7993-75c2-4f6f-99a1-92d5455f765b

📥 Commits

Reviewing files that changed from the base of the PR and between 361a673 and 5c112ff.

📒 Files selected for processing (1)
  • src/pcp/atop/various.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pcp/atop/various.c

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Archive metadata now includes an atop creator label and carries forward relevant context labels.
    • Label value handling now accepts JSON-formatted inputs (quoted strings, numbers, booleans, and null) rather than forcing everything to plain strings.
  • Bug Fixes

    • Daily archive staging now avoids re-processing volume files already compressed with Zstandard (.zst) or XZ (.xz).
    • Improved reliability of background compression and raw archive initialization.
  • Tests

    • Added post-run validation to confirm the expected atop creator label appears in generated archives.

Walkthrough

The PR expands PMI label encoding, adds raw-write archive label initialization, standardizes background compression, skips already-compressed volumes, and validates the atop archive label in QA.

Changes

pcp-atop archive updates

Layer / File(s) Summary
Label encoding and archive validation
src/libpcp_import/src/import.c, qa/1089
PMI labels preserve valid JSON strings, numbers, and literals while quoting plain strings; QA verifies the archive contains the atop label.
Raw-write archive initialization
src/pcp/atop/atop.h, src/pcp/atop/atop.c, src/pcp/atop/various.c
Raw-write startup uses rawwrite_init(), which writes atop=true, copies live context labels, and then initializes the sidecar.
Background archive compression
src/pcp/atop/various.c, src/pcp/atop/atop-daily.sh
A shared double-fork helper runs compression commands asynchronously, while daily processing skips .zst and .xz files.

Possibly related PRs

Suggested reviewers: kmcdonell, tallpsmith

Poem

I’m a rabbit with labels tucked neat in a file,
Watching raw archives hop into style.
JSON wears quotes, true and null gleam,
Compressed logs skip the zstd re-run dream.
“Atop!” says the archive, proud and bright—
Metadata grows tidy overnight.

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is too generic and doesn't clearly describe the main changes in archive labeling and daily log compression. Use a specific title such as "Add context labels to pcp-atop archives and prevent double compression of daily logs."
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description matches the main changes: context archive labels and double-compression fixes.
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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
src/pcp/atop/various.c (3)

1925-1957: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Unchecked context-switch return values.

pmiUseContext, pmUseContext, pmWhichContext, and pmGetContextLabels return values are not checked. If a context switch silently fails partway through, labels may be dropped without any diagnostic, and it becomes hard to tell copied-label failures apart from "no labels present". Consider checking saved >= 0 before restoring, and logging (e.g. via pmDebugOptions.appl1) when pmiUseContext/pmUseContext return an error.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pcp/atop/various.c` around lines 1925 - 1957, Validate the return values
of pmWhichContext, pmiUseContext, pmUseContext, and pmGetContextLabels in the
label-copying flow. Log context-switch failures through the existing
pmDebugOptions.appl1 mechanism, only restore contexts when saved is valid, and
distinguish retrieval errors from the legitimate zero-label case before freeing
label sets.

1760-1787: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Silent failure paths in run_background.

fork()/execv() failures (outer fork returning -1, inner fork returning -1, or execv failing) all fall through to _exit(0) / a plain return with no diagnostic. Background compression can silently stop working with no trace in logs.

🛠️ Suggested diagnostics
 	pid = fork();
+	if (pid < 0)
+	{
+		fprintf(stderr, "%s: run_background: fork failed: %s\n",
+			pmGetProgname(), osstrerror());
+		return;
+	}
 	if (pid == 0)
 	{
-		if (fork() == 0)
+		pid_t	gc = fork();
+		if (gc == 0)
 		{
 			alarm(0);
 			execv(abspath, argv);
+			fprintf(stderr, "%s: run_background: execv(%s) failed: %s\n",
+				pmGetProgname(), abspath, osstrerror());
 		}
 		_exit(0);
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pcp/atop/various.c` around lines 1760 - 1787, Update run_background to
report failures from the outer fork, inner fork, and execv instead of silently
exiting or returning. Add diagnostics for each failed operation, ensure the
child exits with an appropriate failure status after execv fails, and preserve
the existing successful background execution and wait behavior.

1794-1802: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Hardcoded /usr/bin/zstd path may not exist on all supported platforms.

execv requires an absolute path and performs no PATH lookup; if zstd is installed elsewhere on a given distro/platform, compression silently fails (compounded by the silent-failure issue in run_background). Consider resolving the path via PATH search (e.g. execvp-style) or a build/config-time detected location, similar to how atop-daily's path is resolved via pmGetConfig("PCP_BINADM_DIR") elsewhere in this file.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pcp/atop/various.c` around lines 1794 - 1802, Update
rawarchive_compress_volume to avoid hardcoding /usr/bin/zstd; resolve the zstd
executable through the configured PCP binary directory or an execvp-style PATH
lookup before calling run_background. Preserve the existing compression
arguments and ensure the resolved executable is used on platforms where zstd is
installed outside /usr/bin.
src/libpcp_import/src/import.c (1)

1178-1180: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Plain-string branch doesn't escape special characters.

Line 1180 wraps value (and name) in quotes without escaping embedded ", \, or control characters. If either contains a double quote (e.g. a value copied from an arbitrary context label), the resulting JSON fragment is malformed, and __pmAddLabels will most likely reject it. This path is now exercised more since rawwrite_init_labels() (various.c) copies arbitrary host context label values through pmiPutLabel.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/libpcp_import/src/import.c` around lines 1178 - 1180, The plain-string
branch in the label JSON construction must escape JSON-special characters in
both name and value before wrapping them in quotes. Update the code around
pmsprintf to use the existing JSON-escaping utility if available, or otherwise
add equivalent escaping for quotes, backslashes, and control characters, while
preserving the unquoted value branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/pcp/atop/various.c`:
- Around line 1922-1949: In the label reconstruction loop within the pmi context
setup, validate lp->namelen and lp->valuelen before formatting into nbuf and
vbuf. Skip the label when either length cannot fit its buffer, and emit a debug
warning identifying the rejected label; do not pass truncated strings to
pmiPutLabel.

---

Nitpick comments:
In `@src/libpcp_import/src/import.c`:
- Around line 1178-1180: The plain-string branch in the label JSON construction
must escape JSON-special characters in both name and value before wrapping them
in quotes. Update the code around pmsprintf to use the existing JSON-escaping
utility if available, or otherwise add equivalent escaping for quotes,
backslashes, and control characters, while preserving the unquoted value branch.

In `@src/pcp/atop/various.c`:
- Around line 1925-1957: Validate the return values of pmWhichContext,
pmiUseContext, pmUseContext, and pmGetContextLabels in the label-copying flow.
Log context-switch failures through the existing pmDebugOptions.appl1 mechanism,
only restore contexts when saved is valid, and distinguish retrieval errors from
the legitimate zero-label case before freeing label sets.
- Around line 1760-1787: Update run_background to report failures from the outer
fork, inner fork, and execv instead of silently exiting or returning. Add
diagnostics for each failed operation, ensure the child exits with an
appropriate failure status after execv fails, and preserve the existing
successful background execution and wait behavior.
- Around line 1794-1802: Update rawarchive_compress_volume to avoid hardcoding
/usr/bin/zstd; resolve the zstd executable through the configured PCP binary
directory or an execvp-style PATH lookup before calling run_background. Preserve
the existing compression arguments and ensure the resolved executable is used on
platforms where zstd is installed outside /usr/bin.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: ddca2357-6e25-4f9e-bbe5-dc52b9b83f6f

📥 Commits

Reviewing files that changed from the base of the PR and between 257a410 and 361a673.

⛔ Files ignored due to path filters (1)
  • qa/1089.out is excluded by !**/*.out
📒 Files selected for processing (6)
  • qa/1089
  • src/libpcp_import/src/import.c
  • src/pcp/atop/atop-daily.sh
  • src/pcp/atop/atop.c
  • src/pcp/atop/atop.h
  • src/pcp/atop/various.c

Comment thread src/pcp/atop/various.c
If a label name or value exceeds the local buffer size, pmsprintf
would truncate it — potentially stripping a closing quote from a
JSON string value and producing malformed JSON in the archive.
Skip such labels rather than writing corrupt data.

Addresses coderabbit finding on PR performancecopilot#2653.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@natoscott natoscott merged commit 8b7f54b into performancecopilot:main Jul 13, 2026
17 checks passed
@natoscott natoscott deleted the pcp-atop-labels branch July 13, 2026 02:59
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