Skip to content

pmdapmimport, pcp-summary: add pmimport.* metrics for import tools#2632

Open
natoscott wants to merge 1 commit into
performancecopilot:mainfrom
natoscott:pcp-summary-pmimport
Open

pmdapmimport, pcp-summary: add pmimport.* metrics for import tools#2632
natoscott wants to merge 1 commit into
performancecopilot:mainfrom
natoscott:pcp-summary-pmimport

Conversation

@natoscott

@natoscott natoscott commented Jun 23, 2026

Copy link
Copy Markdown
Member

Introduce a generic pmimport.{archive,version,args} metric set with an instance domain with each instance an active import tool identified by name.

pmdapmimport scans PCP_IMPORT_DIR on each fetch; each file is a status file written by an import tool containing key=value lines:
pid= process ID (long-running daemons only, via PMI_PROCESS flag)
version= tool version string
args= tool-specific arguments
archive= current archive base path

Mapping to:
pmimport.archive current archive base path
pmimport.version tool version string
pmimport.args tool-specific argument string

Add PMI_PROCESS flag (0x4) to pmiStart(): long-running import daemons pass this flag to write their pid= to the status file and have it removed on clean exit via pmiEnd(). One-shot tools (e.g. sadc invoked by sa1) omit the flag so the status file persists between invocations.

pmdapmimport reads pid= and uses __pmProcessExists() to skip stale status files left by daemons that exited uncleanly.

pmi_context gains a flags:16 bitfield (alongside the existing state:16) to carry PMI_PROCESS across the lifetime of a context.

pcp-summary(1) displays sysstat/sadc with custom formatting; any other active import tool is shown generically with aligned tool/modules/archive lines, so new importers appear automatically without script changes.

The PMDA is included in local.conf so it is available in both live pmcd mode and local context mode (pminfo -L), enabling pcp-summary and other tools to report import tool status without requiring pmcd.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces the pmimport PMDA (domain 43) that scans PCP_IMPORT_DIR for active PCP import tool status files and exposes instanced archive, version, and args metrics plus singleton hostname, timezone, and zoneinfo metrics. Adds PMI_PROCESS flag to libpcp_import to control sidecar-file lifecycle. Integrates pmimport metrics into pcp-summary.sh and adds QA coverage.

Changes

pmimport PMDA: domain registration, implementation, and integration

Layer / File(s) Summary
Domain registration and PMI_PROCESS contract
src/pmns/stdpmid.pcp, src/include/pcp/import.h, src/libpcp_import/src/private.h
Domain 43 assigned to PMIMPORT; PMI_PROCESS flag macro (0x4) added to public import API; pmi_context.state split into two packed 16-bit bitfields (state:16, flags:16) and sidecar path comment updated.
libpcp_import PMI_PROCESS flag behavior
src/libpcp_import/src/import.c, src/libpcp_import/src/archive.c
pmiStart() stores PMI_PROCESS bit into current->flags; pmiSetImportProgram() conditionally writes pid= to the sidecar file; _pmi_end() restricts sidecar deletion to long-running (PMI_PROCESS) importers only.
pmimport PMDA: build system, PMNS, and help text
src/pmdas/GNUmakefile, src/pmdas/pmimport/GNUmakefile, src/pmdas/pmimport/root_pmimport, src/pmdas/pmimport/help, src/pmdas/pmimport/.gitignore
pmimport added to CPMDAS; full GNUmakefile with domain, library targets, help/version-script generation, and install rules; root_pmimport PMNS defines all six metrics under domain 43; help text documents each metric; .gitignore excludes build artifacts.
pmimport PMDA: DSO implementation and cache management
src/pmdas/pmimport/pmda_pmimport.c, src/pmdas/pmcd/src/pmcd.c
refresh_pmimport() scans PCP_IMPORT_DIR, tracks mtime changes, parses pid/version/args/archive, and validates PID liveness; pmimport_fetchcb() serves both instanced string metrics and singleton hostname/timezone/zoneinfo; pmimport_init() wires DSO interface version 7 with persisted instance-domain state.
pcp-summary: pmimport metrics query and reporting
src/pcp/summary/pcp-summary.sh
pmimport.archive/version/args added to pminfo query; AWK routing extended for pmimport values; pmcd/pmda output gated on version availability; fallback from pmimport singletons for timezone/pcp_host/zoneinfo; pminfo -Lf retry for live-mode failures; new tail section reports sysstat/sadc and other pmimport tools.
QA test and filter updates
qa/2005, qa/common.filter, qa/1881, qa/507
qa/2005 stubs a sadc status file in a temp PCP_IMPORT_DIR and verifies pmimport.* values and descriptors via pminfo -L; common.filter excludes pmdapmimport and the pmimport PMNS entry; qa/1881 and qa/507 strip trailing parenthesized timezone values from filter output.

Sequence Diagram(s)

sequenceDiagram
  rect rgba(70, 130, 180, 0.5)
    Note over pcp-summary.sh,pmimport PMDA: Metric collection
    pcp-summary.sh->>pminfo: query pmcd.* + pmimport.archive/version/args
    pminfo->>pmimport PMDA: fetch instanced + singleton metrics
    pmimport PMDA->>PCP_IMPORT_DIR: scan status files (opendir/readdir)
    PCP_IMPORT_DIR-->>pmimport PMDA: pid/version/args/archive entries
    pmimport PMDA->>pmimport PMDA: mtime_changed? + kill(pid,0) liveness
    pmimport PMDA-->>pminfo: string values per instance
    pminfo-->>pcp-summary.sh: AWK-parsed pmimport_* variables
  end
  rect rgba(60, 179, 113, 0.5)
    Note over pcp-summary.sh,tmp/pmimport_*: Reporting
    pcp-summary.sh->>pcp-summary.sh: fallback timezone/zoneinfo from pmimport if pmcd absent
    pcp-summary.sh->>_pmimport_tool: read tmp/pmimport_* cache files
    _pmimport_tool-->>pcp-summary.sh: formatted sysstat/sadc + other tools report
  end
Loading

Possibly related PRs

  • performancecopilot/pcp#2611: Directly extends the same pmiStart(..., flags) infrastructure and modifies libpcp_import flag/context handling in the same files (src/include/pcp/import.h, src/libpcp_import/src/import.c) as this PR.

Suggested reviewers

  • tallpsmith

🐇 A hop through the import dir, sniffing each file,
Domain forty-three claimed — now pmimport's real!
PMI_PROCESS waves its pid flag up high,
While pcp-summary reports every tool on the fly.
The sidecar lives on for one-shots, then fades —
A rabbit's tidy cleanup through metric arcades! 🌿

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: introducing pmimport.* metrics for tracking import tools via a new pmdapmimport PMDA.
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.
Description check ✅ Passed The pull request description directly addresses the changeset, explaining the new pmimport PMDA, PMI_PROCESS flag, status file handling, and integration with pcp-summary.

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


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: 3

🧹 Nitpick comments (1)
qa/2005 (1)

31-36: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add one fixture where args contains spaces to harden parser coverage.

The current fixture (args=CPU,DISK) won’t catch whitespace-tokenization regressions in pmimport.args reporting. Adding one tool with spaced args would lock this behavior down.

🤖 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 `@qa/2005` around lines 31 - 36, Add a second stub sidecar fixture after the
existing one (after the EOF on line 36) that creates another sadc file with the
same structure but includes spaces within the args field value, such as
args=CPU, DISK or similar. This will ensure the pmimport.args parser is tested
against whitespace-tokenization scenarios and prevent regressions in how spaces
are handled during argument parsing.
🤖 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/summary/pcp-summary.sh`:
- Line 448: The test expression on line 448 uses the -a operator inside the
square brackets for combining conditions, which is not POSIX compliant. Replace
this by splitting the test into separate test commands connected with the &&
operator instead. Specifically, replace the single test bracket containing [ -n
"$version" -a -n "$agents" ] with two separate test commands chained with &&
(such that each variable is tested individually). This maintains the same
logical behavior while ensuring POSIX shell portability.
- Around line 480-481: The current AWK command extracts only field 3 ($3) which
gets truncated at the first space when values contain whitespace. To preserve
the full pmimport_args value including spaces, modify the AWK print statement to
extract the complete content from field 3 to the end of the line instead of just
printing $3. This can be done by using substring operations on the input record
to get everything after the second field, or by reconstructing fields from
position 3 onwards to capture the entire value with spaces intact.

In `@src/pmdas/pmimport/pmda_pmimport.c`:
- Around line 130-134: The issue is that pmdaCacheStore reactivates an instance
at line 130, but when the mtime check at line 133 determines the file is
unchanged, the code skips the remaining logic with continue, which bypasses the
pid-based stale detection check that occurs later. To fix this, restructure the
control flow so that the pid liveness validation (currently at lines 147-151) is
performed regardless of whether the mtime has changed. Either move the stale
detection logic before the mtime unchanged check, or refactor the conditional to
only skip the file re-reading but still execute the pid validation. This ensures
that stale daemon instances are properly invalidated on subsequent fetches even
when the file modification time hasn't changed.

---

Nitpick comments:
In `@qa/2005`:
- Around line 31-36: Add a second stub sidecar fixture after the existing one
(after the EOF on line 36) that creates another sadc file with the same
structure but includes spaces within the args field value, such as args=CPU,
DISK or similar. This will ensure the pmimport.args parser is tested against
whitespace-tokenization scenarios and prevent regressions in how spaces are
handled during argument parsing.
🪄 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 UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: b9e3cc66-7913-4ebd-afac-f6654791c79e

📥 Commits

Reviewing files that changed from the base of the PR and between 1c256b8 and c49890f.

⛔ Files ignored due to path filters (1)
  • qa/2005.out is excluded by !**/*.out
📒 Files selected for processing (16)
  • qa/2005
  • qa/common.filter
  • src/include/pcp/import.h
  • src/libpcp_import/src/archive.c
  • src/libpcp_import/src/import.c
  • src/libpcp_import/src/private.h
  • src/pcp/summary/pcp-summary.sh
  • src/pmdas/GNUmakefile
  • src/pmdas/pmcd/src/pmcd.c
  • src/pmdas/pmimport/.gitignore
  • src/pmdas/pmimport/GNUmakefile
  • src/pmdas/pmimport/help
  • src/pmdas/pmimport/pmda_pmimport.c
  • src/pmdas/pmimport/root_pmimport
  • src/pmlogconf/tools/pcp-summary
  • src/pmns/stdpmid.pcp

Comment thread src/pcp/summary/pcp-summary.sh
Comment thread src/pcp/summary/pcp-summary.sh Outdated
Comment thread src/pmdas/pmimport/pmda_pmimport.c Outdated
Comment thread src/pmdas/pmimport/pmda_pmimport.c Fixed
@natoscott natoscott force-pushed the pcp-summary-pmimport branch from c49890f to 8addeb0 Compare June 23, 2026 11:15

@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

🤖 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/summary/pcp-summary.sh`:
- Around line 167-177: The local-context retry path that executes `eval pminfo
-Lf $metrics` lacks error checking for actual pminfo command failures. After the
retry command on line 176, add a check similar to the one performed on the
initial pminfo command to detect `pminfo:` errors in the error output. If such
errors are found in the retry, the script should surface a clear error message
and exit instead of silently proceeding with potentially empty or partial metric
data.
🪄 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: e6fe87e0-e5ee-4f43-b705-675b7bd19001

📥 Commits

Reviewing files that changed from the base of the PR and between c49890f and 8addeb0.

⛔ Files ignored due to path filters (1)
  • qa/2005.out is excluded by !**/*.out
📒 Files selected for processing (16)
  • qa/2005
  • qa/common.filter
  • src/include/pcp/import.h
  • src/libpcp_import/src/archive.c
  • src/libpcp_import/src/import.c
  • src/libpcp_import/src/private.h
  • src/pcp/summary/pcp-summary.sh
  • src/pmdas/GNUmakefile
  • src/pmdas/pmcd/src/pmcd.c
  • src/pmdas/pmimport/.gitignore
  • src/pmdas/pmimport/GNUmakefile
  • src/pmdas/pmimport/help
  • src/pmdas/pmimport/pmda_pmimport.c
  • src/pmdas/pmimport/root_pmimport
  • src/pmlogconf/tools/pcp-summary
  • src/pmns/stdpmid.pcp
✅ Files skipped from review due to trivial changes (5)
  • src/pmdas/pmimport/root_pmimport
  • src/include/pcp/import.h
  • src/pmlogconf/tools/pcp-summary
  • src/pmdas/pmcd/src/pmcd.c
  • src/pmdas/pmimport/.gitignore
🚧 Files skipped from review as they are similar to previous changes (10)
  • src/libpcp_import/src/archive.c
  • src/pmdas/pmimport/help
  • src/pmns/stdpmid.pcp
  • qa/common.filter
  • src/pmdas/GNUmakefile
  • src/libpcp_import/src/private.h
  • qa/2005
  • src/libpcp_import/src/import.c
  • src/pmdas/pmimport/GNUmakefile
  • src/pmdas/pmimport/pmda_pmimport.c

Comment thread src/pcp/summary/pcp-summary.sh
Introduce a generic pmimport.{archive,version,args} metric set with an
instance domain with each instance an active import tool identified by
name.

pmdapmimport scans PCP_IMPORT_DIR on each fetch; each file is a status
file written by an import tool containing key=value lines:
  pid=      process ID (long-running daemons only, via PMI_PROCESS flag)
  version=  tool version string
  args=     tool-specific arguments
  archive=  current archive base path

Mapping to:
  pmimport.archive  current archive base path
  pmimport.version  tool version string
  pmimport.args     tool-specific argument string

Add PMI_PROCESS flag (0x4) to pmiStart(): long-running import daemons
pass this flag to write their pid= to the status file and have it
removed on clean exit via pmiEnd().  One-shot tools (e.g. sadc invoked
by sa1) omit the flag so the status file persists between invocations.

pmdapmimport reads pid= and uses __pmProcessExists() to skip stale
status files left by daemons that exited uncleanly.

pmi_context gains a flags:16 bitfield (alongside the existing state:16)
to carry PMI_PROCESS across the lifetime of a context.

pcp-summary(1) displays sysstat/sadc with custom formatting; any other
active import tool is shown generically with aligned tool/modules/archive
lines, so new importers appear automatically without script changes.

The PMDA is included in local.conf so it is available in both live pmcd
mode and local context mode (pminfo -L), enabling pcp-summary and other
tools to report import tool status without requiring pmcd.

Signed-off-by: Nathan Scott <nathans@redhat.com>
@natoscott natoscott force-pushed the pcp-summary-pmimport branch from 8addeb0 to 3b895c1 Compare June 24, 2026 04:03
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.

2 participants