Skip to content

osd/PeeringState: add perf counters for PG rebuild times - #69578

Merged
sseshasa merged 1 commit into
ceph:mainfrom
sseshasa:wip-osd-perf-counter-pg-rebuild-stats
Jul 6, 2026
Merged

sseshasa merged 1 commit into
ceph:mainfrom
sseshasa:wip-osd-perf-counter-pg-rebuild-stats

Conversation

@sseshasa

@sseshasa sseshasa commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Track per-OSD PG rebuild duration in prepare_stats_for_publish() (primary OSD only). Three new counters are added to the recoverystate_perf collection:

  • pg_rebuild_duration: LONGRUNAVG time counter (sum+count pair); This counter internally maintains 'avgcount' that tracks the cumulative number of rebuild events.
  • pg_rebuild_max_secs: maximum rebuild duration observed in seconds
  • pg_rebuild_min_secs: minimum rebuild duration observed in seconds

The logic uses a per-PG in-memory latch (rebuild_start_time) to capture the redundancy failure entry point. When a PG is first observed to be in a vulnerable state (PG_STATE_DEGRADED,
PG_STATE_UNDERSIZED, or num_objects_misplaced/degraded > 0), it latches info.stats.last_change as the start time, provided last_change > last_clean, which ensures only genuine new failures after the prior clean interval are tracked.

On recovery, the rebuild duration is computed as (now - rebuild_start_time) and is only recorded if delta num_objects_recovered > 0 or the PG had confirmed redundancy loss at latch time, filtering out spurious state transitions. The latch is cleared after each recorded event.

The latch is also cleared in clear_primary_state() so that an interval change or role transition (primary -> replica) does not carry a stale start time or baseline recovered count into a future interval.

The new last_degraded is intentionally not used here to retain compatibility with older Ceph branches where the field doesn't exist and requires encoding changes. A future simplification can replace the latch with a direct (last_clean - last_degraded) calculation once last_degraded is consistently available.

This interim solution is a close approximation of the PG rebuild time.

These counters are scraped per-OSD by ceph-exporter and exposed to Prometheus, enabling durability score calculations over user-defined time windows.

Other Changes:

  1. Add unit tests to TestPeeringState.cc that exercise the latch logic.
  2. Add a standalone integration test to verify that the rebuild perf counters are incremented on the primary OSD after a recovery event.

Fixes: https://tracker.ceph.com/issues/77493
Signed-off-by: Sridhar Seshasayee [email protected]

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@sseshasa
sseshasa requested a review from a team as a code owner June 18, 2026 13:12
@sseshasa
sseshasa requested a review from rzarzynski June 18, 2026 13:12
@sseshasa
sseshasa force-pushed the wip-osd-perf-counter-pg-rebuild-stats branch from 4ef6a07 to c13a774 Compare June 18, 2026 13:19
@sseshasa
sseshasa requested a review from anmolbabu June 18, 2026 13:23
@sseshasa

sseshasa commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Here's an example of how the stats look like:

"recoverystate_perf": {
        ...
        "process_log_stats_invalidated": 0,
        "pg_split_parent_stats_invalidated": 0,
        "pg_split_child_stats_invalidated": 0,
        "update_stats_invalidated": 0,
        "append_log_stats_invalidated": 0,
        "merge_log_stats_invalidated": 0,
        "pg_rebuild_duration": {
            "avgcount": 1,
            "sum": 0.341132220,
            "avgtime": 0.341132220
        },
        "pg_rebuild_max_secs": 0,
        "pg_rebuild_min_secs": 0
    },

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

LGTM with two comments.

Comment thread src/osd/osd_perf_counters.h Resolved
Comment thread src/osd/PeeringState.h Resolved
@sseshasa
sseshasa force-pushed the wip-osd-perf-counter-pg-rebuild-stats branch 3 times, most recently from 3b86d5c to e9c9477 Compare June 22, 2026 12:38
Track per-OSD PG rebuild duration in prepare_stats_for_publish()
(primary OSD only). Three new counters are added to the
recoverystate_perf collection:

 - pg_rebuild_duration: LONGRUNAVG time counter (sum+count pair);
   This counter internally maintains 'avgcount' that tracks the
   cumulative number of rebuild events.
 - pg_rebuild_max_secs: maximum rebuild duration observed in seconds
 - pg_rebuild_min_secs: minimum rebuild duration observed in seconds

The logic uses a per-PG in-memory latch (rebuild_start_time) to
capture the redundancy failure entry point. When a PG is first observed
to be in a vulnerable state (PG_STATE_DEGRADED,
PG_STATE_UNDERSIZED, or num_objects_misplaced/degraded > 0), it
latches info.stats.last_change as the start time, provided
last_change > last_clean, which ensures only genuine new failures
after the prior clean interval are tracked.

On recovery, the rebuild duration is computed as (now - rebuild_start_time)
and is only recorded if delta num_objects_recovered > 0 or the PG had
confirmed redundancy loss at latch time, filtering out spurious state
transitions. The latch is cleared after each recorded event.

The latch is also cleared in clear_primary_state() so that an interval
change or role transition (primary -> replica) does not carry a stale
start time or baseline recovered count into a future interval.

The new last_degraded is intentionally not used here to retain compatibility
with older Ceph branches where the field doesn't exist and requires encoding
changes. A future simplification can replace the latch with a direct
(last_clean - last_degraded) calculation once last_degraded is consistently
available.

This interim solution is a close approximation of the PG rebuild time.

These counters are scraped per-OSD by ceph-exporter and exposed to
Prometheus, enabling durability score calculations over user-defined
time windows.

Other Changes:
1. Add unit tests to TestPeeringState.cc that exercise the latch logic.
2. Add a standalone integration test to verify that the rebuild perf counters
   are incremented on the primary OSD after a recovery event.

Fixes: https://tracker.ceph.com/issues/77493
Signed-off-by: Sridhar Seshasayee <[email protected]>
@sseshasa
sseshasa force-pushed the wip-osd-perf-counter-pg-rebuild-stats branch from e9c9477 to 4d29f4e Compare June 22, 2026 13:49
@ronen-fr

Copy link
Copy Markdown
Contributor

jenkins test api

@sseshasa

Copy link
Copy Markdown
Contributor Author

jenkins test make check

1 similar comment
@sseshasa

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@ljflores

Copy link
Copy Markdown
Member

@sseshasa

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@MattyWilliams22

Copy link
Copy Markdown
Contributor

jenkins test api

@NitzanMordhai

Copy link
Copy Markdown
Contributor

@sseshasa
sseshasa merged commit 5937363 into ceph:main Jul 6, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants