Skip to content

mgr/ActivePyModules: use RAII for perf schema section management - #69181

Merged
SrinivasaBharath merged 1 commit into
ceph:mainfrom
stzuraski898:wip-sz-74693-perf_schema_no_counters
Jul 23, 2026
Merged

SrinivasaBharath merged 1 commit into
ceph:mainfrom
stzuraski898:wip-sz-74693-perf_schema_no_counters

Conversation

@stzuraski898

@stzuraski898 stzuraski898 commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Refactor get_perf_schema_python() and get_unlabeled_perf_schema_python() to use Formatter::ObjectSection and Formatter::ArraySection RAII helpers instead of manual close_section() calls. Manual closes have have led to crashes when close_section() calls were left unguarded, for example when an OSD with no perf counters had it's perf counters queried.

Following up on comments within the original PR here: #67156

Modified both labeled and unlabeled paths to use RAII to have code consistency.

An additional related PR, made in response to findings from Unit Tests, can be found here #68213.

PR 68213 also resolves the segfault caused by an OSD having no counters hitting an unguarded close_section, but the RAII approach is ideal, and worthy of another PR.

Fixes: https://tracker.ceph.com/issues/74693

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.

Comment thread src/mgr/ActivePyModules.cc Resolved
Comment thread src/mgr/ActivePyModules.cc Resolved
Comment thread src/mgr/ActivePyModules.cc Resolved
Comment thread src/mgr/ActivePyModules.cc Resolved
Comment thread src/mgr/ActivePyModules.cc Resolved
Comment thread src/mgr/ActivePyModules.cc Resolved
Comment thread src/mgr/ActivePyModules.cc Resolved
Comment thread src/mgr/ActivePyModules.cc Resolved

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

the commit message reads:

This fixes a crash ..
...
Fixes: https://tracker.ceph.com/issues/74693

but it does not -- it's a refactoring instead of a fix. probably we should drop these statement and tag.

@stzuraski898
stzuraski898 force-pushed the wip-sz-74693-perf_schema_no_counters branch from 37ca0a4 to b316c96 Compare June 1, 2026 21:11
@stzuraski898

Copy link
Copy Markdown
Contributor Author

but it does not -- it's a refactoring instead of a fix. probably we should drop these statement and tag.

Agreed, these were fixed already by adding a guard around the final close_sections in #68213. For clarity, I've amended my commit message to reflect that this is a refactor for RAII. I've pushed the new commit, implementing the changes requested from your review.

I ran clang-format on only the perf schema functions for this commit, let me know if you think it'd be a good idea to do so for the entire ActivePyModules file.

Thanks for the review!

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

the change still has lots of formatting-only changes. please ping me once you addressed all comments.

@stzuraski898
stzuraski898 force-pushed the wip-sz-74693-perf_schema_no_counters branch 4 times, most recently from afae75d to abe794b Compare June 3, 2026 20:46
@stzuraski898

Copy link
Copy Markdown
Contributor Author

@tchaikov I believe I've gotten to everything, and have pushed a new commit

Comment thread src/mgr/ActivePyModules.cc Resolved
Comment thread src/mgr/ActivePyModules.cc Resolved
@stzuraski898
stzuraski898 force-pushed the wip-sz-74693-perf_schema_no_counters branch 6 times, most recently from bf230a1 to 1eb0f78 Compare June 8, 2026 21:22
@stzuraski898

Copy link
Copy Markdown
Contributor Author

Hey @tchaikov I believe my newest commit has covered your review if you wanted to take another look. Thanks for reviewing!

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@tchaikov

Copy link
Copy Markdown
Contributor

Hey @tchaikov I believe my newest commit has covered your review if you wanted to take another look. Thanks for reviewing!

please resolve the conflicts and ping me again.

Refactor get_perf_schema_python() and get_unlabeled_perf_schema_python() to use Formatter::ObjectSection and Formatter::ArraySection RAII helpers instead of manual close_section() calls. Manual closes have have led to crashes when close_section() calls were left unguarded, for example when an OSD with no perf counters had it's perf counters queried.

Fixes: https://tracker.ceph.com/issues/74693
Signed-off-by: stzuraski898 <[email protected]>
@stzuraski898
stzuraski898 force-pushed the wip-sz-74693-perf_schema_no_counters branch from 1eb0f78 to 078b140 Compare June 15, 2026 21:26
@stzuraski898

Copy link
Copy Markdown
Contributor Author

@tchaikov I've resolved the conflict, thanks!

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

@shraddhaag

Copy link
Copy Markdown
Contributor

@SrinivasaBharath
SrinivasaBharath merged commit 635a928 into ceph:main Jul 23, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown

This is an automated message by src/script/redmine-upkeep.py.

I found one or more Fixes: tags in the commit messages in

git log 635a92806d102a6b0a8349c9699b0515871604ef^..635a92806d102a6b0a8349c9699b0515871604ef

The referenced tickets are:

Those tickets do not reference this merged Pull Request. If this Pull Request merge resolves any of those tickets, please update the "Pull Request ID" field on each ticket. A future run of this script will appropriately update them.

Update Log: https://github.com/ceph/ceph/actions/runs/30023709008

stzuraski898 added a commit to stzuraski898/ceph that referenced this pull request Aug 19, 2026
…_schema

PR ceph#69181 (tracker ceph#74693) refactored get_unlabeled_perf_schema_python()
and get_perf_schema_python() in ActivePyModules.cc to replace manual
open_object_section()/close_section() pairs with RAII
Formatter::ObjectSection guards and std::optional lifetime management.

The existing QA coverage had four gaps:
- get_perf_schema_python() was never called by any test
- get_unlabeled_perf_schema() was called but its return value was discarded
- The wildcard (svc_type="") and by-service (svc_id="") daemon-selection
  branches were never exercised
- The label-transition branch (same counter group, different label set)
  inside get_perf_schema_python() was never triggered

Changes:

src/pybind/mgr/selftest/module.py:
- Add _collect_perf_schema() which runs all schema queries, asserts
  structural and value correctness (field presence, type bitmask range
  1..31, priority range 0..10, units in {0,1}), and returns the raw
  data as a dict for external inspection.
- Add 'mgr self-test perf-schema-test' CLI command that calls
  _collect_perf_schema() and returns the result as JSON on stdout,
  allowing the teuthology test to assert on real values rather than
  relying on assertions hidden inside the mgr process.
- Fold _self_test_perf_counters() into a one-line call to
  _collect_perf_schema() so selftest run coverage is preserved.

qa/tasks/mgr/test_module_selftest.py:
- Add test_selftest_perf_schema() which calls 'ceph mgr self-test
  perf-schema-test', parses the JSON, and asserts all top-level keys
  and empty-state sentinels are present and correct.

qa/tasks/mgr/test_perf_schema.py (new):
- TestPerfSchema MgrTestCase with eight focused test methods that call
  'ceph mgr self-test perf-schema-test', parse the JSON, and assert
  using self.assert*. Covers: exact-lookup, wildcard (get_all),
  by-service (get_by_service), empty daemon state, and labeled schema
  structure for both get_unlabeled_perf_schema and get_perf_schema.

qa/suites/rados/mgr/tasks/4-units/perf_schema.yaml (new):
- Drops into the existing pick-one 4-units/ slot. No other YAML changes
  required; cephfs_test_runner picks up the new test class automatically.

Fixes: https://tracker.ceph.com/issues/74693
Signed-off-by: Steven Zuraski <[email protected]>
Assisted by: IBM Bob
stzuraski898 added a commit to stzuraski898/ceph that referenced this pull request Aug 20, 2026
…_schema

PR ceph#69181 (tracker ceph#74693) refactored get_unlabeled_perf_schema_python()
and get_perf_schema_python() in ActivePyModules.cc to replace manual
open_object_section()/close_section() pairs with RAII
Formatter::ObjectSection guards and std::optional lifetime management.

The existing QA coverage had three gaps:
- get_perf_schema_python() was never called by any test
- get_unlabeled_perf_schema() was called but its return value was discarded
- The wildcard (svc_type="") and by-service (svc_id="") daemon-selection
  branches were never exercised

Changes:

src/pybind/mgr/selftest/module.py:
- Add _collect_perf_schema() which runs all schema queries, asserts
  structural and value correctness (field presence, type bitmask range
  1..31, priority range 0..10, units in {0,1}) using self.PERFCOUNTER_*
  constants from MgrModule, and returns the raw data as a dict for
  external inspection.
- Add 'mgr self-test perf-schema-test' CLI command that calls
  _collect_perf_schema() and returns the result as JSON on stdout,
  allowing the teuthology test to assert on real values rather than
  relying on assertions hidden inside the mgr process.
- Fold _self_test_perf_counters() into a one-line call to
  _collect_perf_schema() so selftest run coverage is preserved.

qa/tasks/mgr/test_perf_schema.py (new):
- TestPerfSchema MgrTestCase with six focused test methods that call
  'ceph mgr self-test perf-schema-test', parse the JSON, and assert
  structural correctness using self.assert*. Covers: exact-lookup,
  wildcard (get_all), by-service (get_by_service), empty daemon state,
  and labeled schema structure for both get_unlabeled_perf_schema and
  get_perf_schema. Value-range validation is intentionally left to the
  mgr-side assertions in _collect_perf_schema() to avoid duplication.

qa/suites/rados/mgr/tasks/4-units/perf_schema.yaml (new):
- Drops into the existing pick-one 4-units/ slot. No other YAML changes
  required; cephfs_test_runner picks up the new test class automatically.

Fixes: https://tracker.ceph.com/issues/74693
Signed-off-by: stzuraski898 <[email protected]>
Assisted by: IBM Bob
stzuraski898 added a commit to stzuraski898/ceph that referenced this pull request Aug 20, 2026
…_schema

PR ceph#69181 (tracker ceph#74693) refactored get_unlabeled_perf_schema_python()
and get_perf_schema_python() in ActivePyModules.cc to use RAII
Formatter::ObjectSection guards. The existing QA coverage had three gaps:
get_perf_schema_python() was never called, get_unlabeled_perf_schema()
return value was discarded, and the wildcard/by-service daemon-selection
branches were never exercised.

Add _collect_perf_schema() to selftest/module.py which exercises all six
query variants (exact, wildcard, by-service for both labeled and unlabeled)
and asserts structural correctness inline. Expose it via three new CLI
commands — 'mgr self-test perf-schema-test' (returns full JSON),
'mgr self-test dump-unlabeled-perf-schema', and
'mgr self-test dump-perf-schema' — so teuthology tests can inspect real
values rather than relying on assertions hidden inside the mgr process.
Update _self_test_perf_counters() to call get_perf_schema() rather than
get_unlabeled_perf_schema() to preserve existing selftest run coverage.

Add qa/tasks/mgr/test_perf_schema.py with seven test methods covering
exact-lookup, wildcard, by-service, empty daemon state, and labeled schema
structure for both APIs. Add qa/suites/rados/mgr/tasks/4-units/perf_schema.yaml
to drop into the existing pick-one slot.

Fixes: https://tracker.ceph.com/issues/74693
Signed-off-by: stzuraski898 <[email protected]>
Assisted by: IBM Bob
stzuraski898 added a commit to stzuraski898/ceph that referenced this pull request Aug 25, 2026
…_schema

PR ceph#69181 (tracker ceph#74693) refactored get_unlabeled_perf_schema_python()
and get_perf_schema_python() in ActivePyModules.cc to use RAII
Formatter::ObjectSection guards, but left test coverage gaps.

Add _collect_perf_schema() to selftest/module.py as a pure collector
that calls all six query variants (exact, wildcard, by-service for both
labeled and unlabeled APIs) and returns the raw results. Expose it via
three CLI commands:

  ceph mgr self-test perf-schema-test
  ceph mgr self-test dump-unlabeled-perf-schema <svc_type> <svc_id>
  ceph mgr self-test dump-perf-schema <svc_type> <svc_id>

Add qa/tasks/mgr/test_perf_schema.py with seven test methods that assert
the structural shape of each query variant: exact lookup keyed by
'osd.0', wildcard covering all daemons, by-service filtering, labeled
schema list-of-entries structure (labels + counters dicts), and
empty-result behaviour for a non-existent service type.

Add qa/suites/rados/mgr/tasks/4-units/perf_schema.yaml to slot the new
test into the existing pick-one teuthology task suite.

Also call both get_unlabeled_perf_schema() and get_perf_schema() in
_self_test_perf_counters() so that 'mgr self-test run' smoke-tests
both APIs.

Fixes: https://tracker.ceph.com/issues/79553
Signed-off-by: stzuraski898 <[email protected]>
Assisted by: IBM Bob
stzuraski898 added a commit to stzuraski898/ceph that referenced this pull request Aug 25, 2026
…_schema

PR ceph#69181 (tracker ceph#74693) refactored get_unlabeled_perf_schema_python()
and get_perf_schema_python() in ActivePyModules.cc to use RAII
Formatter::ObjectSection guards, but left test coverage gaps.

Add _collect_perf_schema() to selftest/module.py as a pure collector
that calls all six query variants (exact, wildcard, by-service for both
labeled and unlabeled APIs) and returns the raw results. Expose it via
three CLI commands:

  ceph mgr self-test perf-schema-test
  ceph mgr self-test dump-unlabeled-perf-schema <svc_type> <svc_id>
  ceph mgr self-test dump-perf-schema <svc_type> <svc_id>

Add qa/tasks/mgr/test_perf_schema.py with seven test methods that assert
the structural shape of each query variant: exact lookup keyed by
'osd.0', wildcard covering all daemons, by-service filtering, labeled
schema list-of-entries structure (labels + counters dicts), and
empty-result behaviour for a non-existent service type.

Add qa/suites/rados/mgr/tasks/4-units/perf_schema.yaml to slot the new
test into the existing pick-one teuthology task suite.

Also call both get_unlabeled_perf_schema() and get_perf_schema() in
_self_test_perf_counters() so that 'mgr self-test run' smoke-tests
both APIs.

Fixes: https://tracker.ceph.com/issues/79553
Signed-off-by: stzuraski898 <[email protected]>
Assisted by: IBM Bob
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.

4 participants