Skip to content

pcp2openmetrics: add live timestamp mode#2637

Open
lmchilton wants to merge 1 commit into
performancecopilot:mainfrom
lmchilton:pcp2openmetrics-timestamps
Open

pcp2openmetrics: add live timestamp mode#2637
lmchilton wants to merge 1 commit into
performancecopilot:mainfrom
lmchilton:pcp2openmetrics-timestamps

Conversation

@lmchilton

Copy link
Copy Markdown
Contributor

update pcp2openmetrics tool to allow for live timestamp mode option. This update follows openmetric / prometheus exposing timestamp guidelines. Updated man page & QA #1131

Resolves issue #2538

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: ee50aa9b-1073-4c27-890f-e7ab743d38fd

📥 Commits

Reviewing files that changed from the base of the PR and between 8803d71 and 2b4bd59.

⛔ Files ignored due to path filters (1)
  • qa/1131.out is excluded by !**/*.out
📒 Files selected for processing (3)
  • qa/1131
  • src/pcp2openmetrics/pcp2openmetrics.1
  • src/pcp2openmetrics/pcp2openmetrics.py
✅ Files skipped from review due to trivial changes (1)
  • src/pcp2openmetrics/pcp2openmetrics.1
🚧 Files skipped from review as they are similar to previous changes (2)
  • qa/1131
  • src/pcp2openmetrics/pcp2openmetrics.py

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added live timestamp mode for pcp2openmetrics (-l / --times); when enabled, emitted OpenMetrics samples include explicit sample timestamps (and timestamps are always included when running in archive mode).
  • Bug Fixes
    • Improved OpenMetrics output normalization by refining placeholder token handling in the filtering pipeline.
  • Documentation
    • Updated the pcp2openmetrics manpage to document the --times / -l option (“Live timestamp mode”).
  • Tests
    • Extended QA with an additional pcp2openmetrics -s2 --times … run to validate timestamp output and normalization.

Walkthrough

pcp2openmetrics now supports -l/--times for timestamped samples. The manpage documents the option, output formatting now respects the flag, and QA normalization plus a new invocation cover the changed output.

Changes

Live timestamp mode

Layer / File(s) Summary
CLI option and docs
src/pcp2openmetrics/pcp2openmetrics.py, src/pcp2openmetrics/pcp2openmetrics.1
Recognizes times, adds -l/--times, and documents live timestamp mode in the manpage.
Live timestamp output
src/pcp2openmetrics/pcp2openmetrics.py
Forces timestamps in archive mode and emits sample timestamps only when self.times is enabled.
QA normalization and test
qa/1131
Updates the OpenMetrics filter placeholders and adds a pcp2openmetrics -s2 --times hinv.ncpu test run.

Poem

I hopped through counters, brisk and keen,
and found a -l in the machine.
Now live outputs softly gleam,
with timestamp sparkles in the stream.
🐇

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding live timestamp mode to pcp2openmetrics.
Description check ✅ Passed The description is directly related to the changes and mentions the new timestamp mode, docs, and QA updates.
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: 3

🤖 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/pcp2openmetrics/pcp2openmetrics.1`:
- Around line 421-425: The SYNOPSIS short-option cluster is missing the newly
documented lowercase l option, so update the synopsis in pcp2openmetrics.1 to
match the documented command-line options. Keep the short-option list consistent
with the `-l, --time-stamp` entry by adding `l` in the compact options section
so users can discover it from the top-level usage summary.

In `@src/pcp2openmetrics/pcp2openmetrics.py`:
- Around line 142-146: The counter timestamp cache in pcp2openmetrics.py can
grow without bound because counter_timestamps only ever adds new (metric_name,
instance_id) keys. Update the live-mode counter handling paths around the
related metric processing code (including the sections near the referenced
counter-timestamp logic) to evict stale entries when instances disappear or are
no longer observed. Use the existing counter_timestamps structure as the cleanup
point so long-running exporter stability is preserved.
- Around line 58-59: The self.keys list in pcp2openmetrics.py has a missing
separator between the time_stamp and count_scale entries, causing those config
directives to merge into one invalid key. Update the list in the initialization
block where self.keys is defined so time_stamp and count_scale are separate
elements, preserving recognition of both directives.
🪄 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: c37c1883-be10-4564-8af4-8c0dd5fd28c9

📥 Commits

Reviewing files that changed from the base of the PR and between 3d1a65d and 371f9c2.

⛔ Files ignored due to path filters (1)
  • qa/1131.out is excluded by !**/*.out
📒 Files selected for processing (3)
  • qa/1131
  • src/pcp2openmetrics/pcp2openmetrics.1
  • src/pcp2openmetrics/pcp2openmetrics.py

Comment thread src/pcp2openmetrics/pcp2openmetrics.1 Outdated
Comment thread src/pcp2openmetrics/pcp2openmetrics.py Outdated
Comment thread src/pcp2openmetrics/pcp2openmetrics.py Outdated
Comment on lines +142 to +146
# Counter metric timestamp tracking
# key - (metric_name, instance_id)
# value - timestamp when first seen
self.counter_timestamps = {}

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.

🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift

Prevent unbounded growth of counter_timestamps in long-running live mode.

self.counter_timestamps only adds keys and never removes stale (metric, inst) entries. With high instance churn, this can grow indefinitely and degrade long-lived exporter stability.

Also applies to: 509-513, 520-523

🤖 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/pcp2openmetrics/pcp2openmetrics.py` around lines 142 - 146, The counter
timestamp cache in pcp2openmetrics.py can grow without bound because
counter_timestamps only ever adds new (metric_name, instance_id) keys. Update
the live-mode counter handling paths around the related metric processing code
(including the sections near the referenced counter-timestamp logic) to evict
stale entries when instances disappear or are no longer observed. Use the
existing counter_timestamps structure as the cleanup point so long-running
exporter stability is preserved.

@lmchilton lmchilton force-pushed the pcp2openmetrics-timestamps branch from 371f9c2 to bcc4cc6 Compare June 25, 2026 17:32
Comment thread src/pcp2openmetrics/pcp2openmetrics.py Outdated
if self.time_stamp and openmetrics_type(desc) == "counter":
counter_key = (metric, inst)
creation_ts = self.counter_timestamps.get(counter_key, ts)
body += '%s%s %s\n' % (openmetrics_name_ts, openmetrics_labels(inst, name, desc, labels), creation_ts)

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.

I think its incorrect to expose timestamps for counter metrics only here - we should treat live mode the same as archive (a few lines above) in this regard, and export the timestamp for the sample (as per the v1 OM spec, and as we always have).

The "_created" lines are indeed intended for counters only, re-reading the spec(s). They could be applicable to both archive and live PCP values, however, looking at our code - and in particular the fetchgroup code behind the python API - these are not going to be handled correctly (there is no knowledge of "mark" records in src/libpcp/src/fetchgroup.c which is the code being used by pmconfig.py and in turn by pcp2openmetrics.py). We should ignore the _created timestamp, its not ever going to be correctly handled here.

Finally, the PMWEBAPI(3) uses the parameter name "times" to enable these timestamps - could we mirror that here? i.e. instead of --time_stamp lets use --times? (and this should remain the default in archive mode).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@natoscott thank you for the clarification! I updated everything

@lmchilton lmchilton force-pushed the pcp2openmetrics-timestamps branch from bcc4cc6 to 3e0d882 Compare June 30, 2026 15:42

@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

🤖 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 `@qa/1131`:
- Around line 107-108: The new QA case uses pcp2openmetrics with only -s2, which
still falls back to the tool’s default 10-second interval and slows the test.
Update the command in this test case to pass an explicit short time interval
with pcp2openmetrics so the assertion remains fast while preserving coverage;
locate the change in the qa/1131 test around the pcp2openmetrics invocation.

In `@src/pcp2openmetrics/pcp2openmetrics.py`:
- Line 204: The `--times` option help text in `pmSetLongOption` is misleading
because the implementation in `pcp2openmetrics.py` only appends a sample
timestamp to emitted series rather than adding a new metric. Update the
`--times` description to reflect the actual behavior, and keep the wording
aligned with the logic used later when timestamps are emitted so users
understand what the flag does.
- Line 58: The config option handling in the pcp2openmetrics parser is wired to
the wrong runtime field, so `times=yes` never affects output. Update the option
mapping in the config parsing logic around the `times` entry so it sets
`self.time_stamp` (or rename the runtime flag consistently), and verify the
output gating that reads `self.time_stamp` now reflects the
`pcp2openmetrics.conf` setting.
🪄 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: b8a86648-056d-4fd0-9d75-45cbdadeebdb

📥 Commits

Reviewing files that changed from the base of the PR and between bcc4cc6 and 3e0d882.

⛔ Files ignored due to path filters (1)
  • qa/1131.out is excluded by !**/*.out
📒 Files selected for processing (3)
  • qa/1131
  • src/pcp2openmetrics/pcp2openmetrics.1
  • src/pcp2openmetrics/pcp2openmetrics.py

Comment thread qa/1131
Comment thread src/pcp2openmetrics/pcp2openmetrics.py
Comment thread src/pcp2openmetrics/pcp2openmetrics.py Outdated
Comment thread src/pcp2openmetrics/pcp2openmetrics.1 Outdated
option may be used.
.TP
\fB\-l\fR, \fB\-\-times\fR
Live timestamp mode. When configured counters are accompanied by their respective timestamp

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.

counters -> metric values

Comment thread src/pcp2openmetrics/pcp2openmetrics.py Outdated
Comment thread src/pcp2openmetrics/pcp2openmetrics.py Outdated
@lmchilton lmchilton force-pushed the pcp2openmetrics-timestamps branch from 3e0d882 to 8803d71 Compare July 7, 2026 17:40

@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.

🧹 Nitpick comments (1)
src/pcp2openmetrics/pcp2openmetrics.py (1)

507-510: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor duplication in timestamp-conditional formatting.

The two branches only differ by the trailing %s for ts; could be simplified to avoid repeating the format/label call.

-                if self.times:
-                    body += '%s%s %s %s\n' % (openmetrics_name_end, openmetrics_labels(inst, name, desc, labels), value, ts)
-                else:
-                    body += '%s%s %s\n' % (openmetrics_name_end, openmetrics_labels(inst, name, desc, labels), value)
+                line = '%s%s %s' % (openmetrics_name_end, openmetrics_labels(inst, name, desc, labels), value)
+                if self.times:
+                    line += ' %s' % ts
+                body += line + '\n'
🤖 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/pcp2openmetrics/pcp2openmetrics.py` around lines 507 - 510, The
timestamp-conditional formatting in the OpenMetrics output duplicates the same
name/label/value formatting in both branches. Refactor the logic in the block
around openmetrics_name_end and openmetrics_labels so the common prefix is built
once, then append ts only when self.times is set. Keep the behavior identical
while removing the repeated formatting call.
🤖 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.

Nitpick comments:
In `@src/pcp2openmetrics/pcp2openmetrics.py`:
- Around line 507-510: The timestamp-conditional formatting in the OpenMetrics
output duplicates the same name/label/value formatting in both branches.
Refactor the logic in the block around openmetrics_name_end and
openmetrics_labels so the common prefix is built once, then append ts only when
self.times is set. Keep the behavior identical while removing the repeated
formatting call.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro Plus

Run ID: 06360553-c000-4346-bdbb-cafe08f84372

📥 Commits

Reviewing files that changed from the base of the PR and between 3e0d882 and 8803d71.

⛔ Files ignored due to path filters (1)
  • qa/1131.out is excluded by !**/*.out
📒 Files selected for processing (3)
  • qa/1131
  • src/pcp2openmetrics/pcp2openmetrics.1
  • src/pcp2openmetrics/pcp2openmetrics.py
✅ Files skipped from review due to trivial changes (1)
  • src/pcp2openmetrics/pcp2openmetrics.1
🚧 Files skipped from review as they are similar to previous changes (1)
  • qa/1131

update pcp2openmetrics tool to allow for live timestamp
mode option. This update follows openmetric / prometheus
exposing timestamp guidelines. Updated man page & QA performancecopilot#1131

Resolves upstream RFE issue [performancecopilot#2538]
@lmchilton lmchilton force-pushed the pcp2openmetrics-timestamps branch from 8803d71 to 2b4bd59 Compare July 7, 2026 18:35
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