Skip to content

mgr/prometheus: Fix healthcheck history column alignment and sort order - #71147

Open
Prachi-Lasurkar wants to merge 1 commit into
ceph:mainfrom
Prachi-Lasurkar:wip-79527-fix-healthcheck-history-output
Open

Prachi-Lasurkar wants to merge 1 commit into
ceph:mainfrom
Prachi-Lasurkar:wip-79527-fix-healthcheck-history-output

Conversation

@Prachi-Lasurkar

@Prachi-Lasurkar Prachi-Lasurkar commented Aug 19, 2026 •

Copy link
Copy Markdown

Dynamically calculate the healthcheck name column width to prevent
misalignment and sort entries by Last Seen in descending order,
showing the most recently active checks first.

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

Before Changes:

[root@ceph12 ~]# ceph healthcheck history ls
Healthcheck Name          First Seen (UTC)      Last seen (UTC)       Count  Active
BLUESTORE_SLOW_OP_ALERT   2025/11/07 16:01:59   2026/08/12 17:30:18      63    No  
CEPHADM_APPLY_SPEC_FAIL   2024/11/04 19:29:16   2024/11/04 19:54:46      28    No  
CEPHADM_DAEMON_PLACE_FAIL  2024/11/12 22:44:19   2025/11/08 10:08:03      15    No  
CEPHADM_FAILED_DAEMON     2024/10/04 00:53:37   2026/07/29 14:12:55      97    No  
CEPHADM_HOST_CHECK_FAILED  2024/10/03 15:15:51   2026/08/10 19:53:21     233    No  
CEPHADM_REFRESH_FAILED    2024/10/02 23:18:35   2026/08/10 19:44:51     111    No  
CEPHADM_STRAY_DAEMON      2024/11/13 16:51:36   2024/11/19 13:52:02       3    No  
DAEMON_OLD_VERSION        2024/11/29 04:38:11   2025/04/04 16:41:32       2    No  
DB_DEVICE_STALLED_READ_ALERT  2025/12/30 13:25:44   2026/07/27 23:39:46      27    No  
FS_DEGRADED               2024/10/23 13:36:06   2026/02/21 18:05:25      26    No  
FS_WITH_FAILED_MDS        2024/10/23 13:36:06   2026/02/07 12:14:20       7    No 

After Changes:

[ceph: root@test-prachicode-0 /]# ceph healthcheck history ls
Healthcheck Name                         First Seen (UTC)      Last seen (UTC)       Count  Active
RECENT_MGR_MODULE_CRASH                  2026/08/18 11:04:44   2026/08/18 12:05:44       1   Yes  
OSD_NO_DOWN_OUT_INTERVAL                 2026/08/18 12:02:44   2026/08/18 12:05:44       1   Yes  
AUTH_INSECURE_GLOBAL_ID_RECLAIM_ALLOWED  2026/08/18 11:55:14   2026/08/18 11:55:44       1    No  
PG_DEGRADED                              2026/08/18 11:04:14   2026/08/18 11:13:29       2    No  
OSD_HOST_DOWN                            2026/08/18 11:03:59   2026/08/18 11:13:14       1    No  
OSD_DOWN                                 2026/08/18 11:03:59   2026/08/18 11:13:14       1    No  
PG_AVAILABILITY                          2026/08/18 11:04:59   2026/08/18 11:12:29       1    No  
TOO_FEW_OSDS                             2026/08/18 10:51:14   2026/08/18 10:56:29       1    No  
8 health check(s) listed

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.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR ci-approved to allow Jenkins CI jobs to run.

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

@Prachi-Lasurkar, please see my comment

max(len(k) for k in self.healthcheck.keys()))
fmt = (f"{{healthcheck_name:<{col_width}}} {{first_seen:<20}} "
f"{{last_seen:<20}} {{count:>5}} {{active:^6}}")
out.append(fmt.format(

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.

col_width is computed from one self.healthcheck.keys() snapshot, but the header/rows below are built from a second, independent .keys() call plus per-key self.healthcheck[k] lookups. ThreadSafeLRUCacheDict only locks each individual call, not a read spanning several of them, and str never takes self.lock (the RLock check() holds while mutating).
So MetricCollectionThread can run check() between these snapshots:

  • A new/longer healthcheck name added after col_width is computed won't fit -> reintroduces the misalignment bug this PR fixes.
  • An entry evicted (LRU) between the .keys() snapshot and the later self.healthcheck[k] lookup -> KeyError.

Simplest fix: take one atomic snapshot via .items() (already lock-protected as a single call) and build everything off it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for the review, @NitzanMordhai!
You are right, the multiple independent .keys() and [k] calls were not atomic, leaving a window for MetricCollectionThread to mutate the dict between them.
Fixed by taking a single atomic snapshot at the start of str via self.healthcheck.items(), which locks once, copies the entire dict into a plain Python list, and releases. All subsequent operations - empty check, col_width, sort, rows, and footer count now work exclusively from this frozen snapshot with no further live dict access.
Please let me know if you have further feedback.

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.

@Prachi-Lasurkar thanks, please fix the following ci test errors:
338/352 Test #4: run-tox-mgr ...............................***Failed 457.99 sec 20:51:53 Requirement already satisfied: tox in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (4.63.0) 20:51:53 Requirement already satisfied: cachetools>=7.0.3 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (7.2.0) 20:51:53 Requirement already satisfied: colorama>=0.4.6 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (0.4.6) 20:51:53 Requirement already satisfied: filelock>=3.25 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (3.32.7) 20:51:53 Requirement already satisfied: packaging>=26 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (26.3) 20:51:53 Requirement already satisfied: platformdirs>=4.9.4 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (4.11.11) 20:51:53 Requirement already satisfied: pluggy>=1.6 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (1.6.0) 20:51:53 Requirement already satisfied: pyproject-api>=1.10 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (1.11.2) 20:51:53 Requirement already satisfied: python-discovery>=1.4.4 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (1.6.1) 20:51:53 Requirement already satisfied: tomli-w>=1.2 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (1.2.0) 20:51:53 Requirement already satisfied: tomli>=2.4 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (2.4.1) 20:51:53 Requirement already satisfied: typing-extensions>=4.15 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (4.16.0) 20:51:53 Requirement already satisfied: virtualenv>=21.1 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from tox) (21.9.0) 20:51:53 Requirement already satisfied: distlib<1,>=0.3.7 in /ceph/build/mgr-virtualenv/lib/python3.10/site-packages (from virtualenv>=21.1->tox) (0.4.3) 20:51:53 flake8: install_deps /ceph/src/pybind/mgr> python -I -m pip install flake8 20:51:53 flake8: commands[0] /ceph/src/pybind/mgr> flake8 --config=tox.ini alerts balancer cephadm ceph_secrets ceph_secrets_client.py ceph_secrets_types.py cli_api crash devicehealth diskprediction_local hello nvmeof iostat localpool mgr_module.py mgr_util.py cherrypy_mgr.py nfs object_format.py orchestrator prometheus rbd_support rgw selftest smb 20:51:53 prometheus/module.py:357:29: E128 continuation line under-indented for visual indent 20:51:53 prometheus/module.py:358:29: E128 continuation line under-indented for visual indent 20:51:53 2 E128 continuation line under-indented for visual indent 20:51:53 flake8: exit 1 (2.70 seconds) /ceph/src/pybind/mgr> flake8 --config=tox.ini alerts balancer cephadm ceph_secrets ceph_secrets_client.py ceph_secrets_types.py cli_api crash devicehealth diskprediction_local hello nvmeof iostat localpool mgr_module.py mgr_util.py cherrypy_mgr.py nfs object_format.py orchestrator prometheus rbd_support rgw selftest smb pid=159967 20:51:53 flake8: FAIL ✖ in 5.87 seconds

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@NitzanMordhai, I’ve made the code changes accordingly. Please review them.

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.

@Prachi-Lasurkar yep, LGTM!

@timqn22

timqn22 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

ok to test

@Prachi-Lasurkar
Prachi-Lasurkar force-pushed the wip-79527-fix-healthcheck-history-output branch from c076fd3 to 75abae5 Compare September 21, 2026 16:45
 Dynamically calculate the healthcheck name column width to prevent
 misalignment and sort entries by Last Seen in descending order,
 showing the most recently active checks first.

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

Signed-off-by: Prachi Lasurkar <[email protected]>

@NitzanMordhai NitzanMordhai 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!

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath9-testing-20261027.065249-main.

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.

5 participants