Repository navigation
squid: mgr: fix PyObject* refcounting in TTLCache and cleanup logic - #66483
Conversation
rzarzynski
left a comment
There was a problem hiding this comment.
LGTM with a nit: the differences from cherry-picking need to be explicitly mentioned the commit description (Conflicts).
| import re | ||
| import threading | ||
| import time | ||
| import enum | ||
| from collections import namedtuple | ||
| from collections import OrderedDict | ||
| from tempfile import NamedTemporaryFile |
There was a problem hiding this comment.
I think it's a difference from main which was including tempfile already.
64ef34f to
defd6ac
Compare
| import re | ||
| import threading | ||
| import time | ||
| import enum | ||
| from collections import namedtuple | ||
| from collections import OrderedDict |
There was a problem hiding this comment.
Oh, so the discrepancy between main and the backport has been tackled not by adding the Conflict section but rather by squeezing the diff. Fine!
defd6ac to
c094b0c
Compare
|
don't merge until #66571 merged |
|
Converting to draft based on #66483 (comment) |
c094b0c to
0cea9aa
Compare
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
@NitzanMordhai is this blocked on something? |
|
jenkins test make check |
|
jenkins test api |
|
jenkins test dashboard |
@dvanders No, now we can continue with it |
This patch introduces several improvements to the Prometheus module:
- Introduces `HealthHistory._prune()` to drop stale and inactive health checks.
Limits the in-memory healthcheck dict to a configurable max_entries (default 1000).
TTL for stale entries is configurable via `healthcheck_history_stale_ttl` (default 3600s).
- Refactors HealthHistory.check() to use a unified iteration over known and current checks,
improving concurrency and minimizing redundant updates.
- Use cherrypy.tools.gzip instead of manual gzip.compress() for cleaner
HTTP compression with proper header handling and client negotiation.
- Introduces new module options:
- `healthcheck_history_max_entries`
- Add proper error handling for CherryPy engine startup failures
- Remove os._exit monkey patch in favor of proper exception handling
- Remove manual Content-Type header setting (CherryPy handles automatically)
Fixes: https://tracker.ceph.com/issues/68989
Signed-off-by: Nitzan Mordechai <[email protected]>
(cherry picked from commit be28901)
Fix incorrect reference counting and memory retention behavior in TTLCache when storing PyObject* values. Previously, TTLCache::insert did not increment the reference count, and `erase` / `clear` did not correctly decref the values, leading to use-after-free or leaks depending on usage. Changes: - Move Py_INCREF from cacheable_get_python() to TTLCache::insert() - Add `TTLCache::clear()` method for proper memory cleanup - Ensure TTLCache::get() returns a new reference - Fix misuse of std::move on c_str() in PyJSONFormatter These changes prevent both memory leaks and use-after-free errors when mgr modules use cached Python objects logic. Fixes: https://tracker.ceph.com/issues/68989 Signed-off-by: Nitzan Mordechai <[email protected]> (cherry picked from commit 7fadf6a)
The HealthHistory.check() method acquires the lock and then calls HealthHistory.save(), which also tries to acquire the same lock. With a regular Lock(), the same thread blocks trying to re-acquire it (deadlock). Switch to RLock to allow nested acquisition by the same thread. PR ceph#65245 added the locks. Fixes: https://tracker.ceph.com/issues/74148 Signed-off-by: Nitzan Mordechai <[email protected]> (cherry picked from commit 26394ca)
PR ceph#65245 drop the header set for standby module, we should still have it. Fixes: https://tracker.ceph.com/issues/74149 Signed-off-by: Nitzan Mordechai <[email protected]> (cherry picked from commit 2ef12b2)
Fixes: https://tracker.ceph.com/issues/74149 Signed-off-by: Nitzan Mordechai <[email protected]> (cherry picked from commit e3de8c9)
2d050a7 to
5bdeb77
Compare
|
jenkins test docs |
There was a problem hiding this comment.
Ceph Release Engineering Audit Report
Commit Parity Visualizer
| BACKPORT PR #66483 | SOURCE PR |
SOURCE STATUS |
|---|---|---|
| 848874c mgr/prometheus: prune stale health checks, compress output | PR #65245 | be28901 mgr/prometheus: prune stale health checks, compress output |
| deb702e mgr/TTLCache: fix PyObject* lifetime management and cleanup logic | 7fadf6a mgr/TTLCache: fix PyObject* lifetime management and cleanup logic | |
| 10ef056 mgr/prometheus: Use RLock to fix deadlock in HealthHistory | PR #66571 | 26394ca mgr/prometheus: Use RLock to fix deadlock in HealthHistory |
| 8b01148 mgr/prometheus: metrics header for standby module | 2ef12b2 mgr/prometheus: metrics header for standby module | |
| 5bdeb77 mgr/prometheus/test_module: Adding unit-test for new classes | e3de8c9 mgr/prometheus/test_module: Adding unit-test for new classes |
Automated Backport Parity Review - Cherry-Pick Conflicts / Deviations
A conflict or deviation was detected during the simulation of this backport. The code in this PR does not match a clean cherry-pick of the upstream commits.
This does not necessarily indicate an issue but a maintainer should review.
**Click to expand conflict summaries.**
Deviation in Backport 848874c (cherry-pick of be28901)
Affected File(s)
src/pybind/mgr/prometheus/module.py
Range Diff
Click to expand
--- Original (be28901f)
+++ Backport (848874c8)
@@ -21,3 +21,4 @@
Fixes: https://tracker.ceph.com/issues/68989
Signed-off-by: Nitzan Mordechai <[email protected]>
+(cherry picked from commit be28901f361cadcf6bf993276d71f3a79beaae4f)
================================================================================
RANGE DIFF
================================================================================
1: be28901f361 ! 1: 848874c8e86 mgr/prometheus: prune stale health checks, compress output
@@ Commit message
Fixes: https://tracker.ceph.com/issues/68989
Signed-off-by: Nitzan Mordechai <[email protected]>
+ (cherry picked from commit be28901f361cadcf6bf993276d71f3a79beaae4f)
## doc/mgr/prometheus.rst ##
@@ doc/mgr/prometheus.rst: Configuration
@@ src/pybind/mgr/prometheus/module.py: import yaml
import enum
from collections import namedtuple
+from collections import OrderedDict
- from tempfile import NamedTemporaryFile
from mgr_module import CLIReadCommand, MgrModule, MgrStandbyModule, PG_STATES, Option, ServiceInfoT, HandleCommandResult, CLIWriteCommand
-@@ src/pybind/mgr/prometheus/module.py: from mgr_util import get_default_addr, profile_method, build_url
+ from mgr_util import get_default_addr, profile_method, build_url
from orchestrator import OrchestratorClientMixin, raise_if_exception, OrchestratorError
from rbd import RBD
--from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, IO
-+from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, IO, TypeVar, Generic
+-from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable
++from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, TypeVar, Generic
+
LabelValues = Tuple[str, ...]
Number = Union[int, float]
- MetricValue = Dict[LabelValues, Number]
@@ src/pybind/mgr/prometheus/module.py: MetricValue = Dict[LabelValues, Number]
DEFAULT_PORT = 9283Deviation in Backport 10ef056 (cherry-pick of 26394ca)
Affected File(s)
src/pybind/mgr/prometheus/module.py
Range Diff
Click to expand
--- Original (26394ca0)
+++ Backport (10ef0564)
@@ -8,3 +8,4 @@
Fixes: https://tracker.ceph.com/issues/74148
Signed-off-by: Nitzan Mordechai <[email protected]>
+(cherry picked from commit 26394ca06981e87ec7aee75b8467817afa330ba6)
================================================================================
RANGE DIFF
================================================================================
1: 26394ca0698 ! 1: 10ef0564977 mgr/prometheus: Use RLock to fix deadlock in HealthHistory
@@ Commit message
Fixes: https://tracker.ceph.com/issues/74148
Signed-off-by: Nitzan Mordechai <[email protected]>
+ (cherry picked from commit 26394ca06981e87ec7aee75b8467817afa330ba6)
## src/pybind/mgr/prometheus/module.py ##
-@@ src/pybind/mgr/prometheus/module.py: from mgr_util import get_default_addr, profile_method, build_url, test_port_allo
+@@ src/pybind/mgr/prometheus/module.py: from mgr_util import get_default_addr, profile_method, build_url
from orchestrator import OrchestratorClientMixin, raise_if_exception, OrchestratorError
from rbd import RBD
--from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, IO, TypeVar, Generic
-+from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, IO, TypeVar, Iterator
+-from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, TypeVar, Generic
+-
++from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, TypeVar, Iterator
LabelValues = Tuple[str, ...]
Number = Union[int, float]
MetricValue = Dict[LabelValues, Number]
@@ src/pybind/mgr/prometheus/module.py: class HealthHistory:
def __init__(self, mgr: MgrModule):
self.mgr = mgr
- self.lock = threading.Lock()
-+ self.lock = threading.RLock()
- self.max_entries = cast(int, self.mgr.get_localized_module_option('healthcheck_history_max_entries', 1000))
+- self.max_entries = cast(int, self.mgr.get_localized_module_option('healthcheck_history_max_entries', 1000))
- self.healthcheck: LRUCacheDict[str, HealthCheckEvent] = LRUCacheDict(maxsize=self.max_entries)
-+ self.healthcheck: ThreadSafeLRUCacheDict[str, HealthCheckEvent] = ThreadSafeLRUCacheDict(maxsize=self.max_entries)
++ self.lock = threading.RLock()
++ self.max_entries = cast(int, self.mgr.get_localized_module_option(
++ 'healthcheck_history_max_entries', 1000))
++ self.healthcheck: ThreadSafeLRUCacheDict[str, HealthCheckEvent] = ThreadSafeLRUCacheDict(
++ maxsize=self.max_entries)
self._load()
def _load(self) -> None:
@@ src/pybind/mgr/prometheus/module.py: class Module(MgrModule, OrchestratorClientM
for name, info in self.health_history.healthcheck.items():
v = 1 if info.active else 0
self.metrics['health_detail'].set(
+@@ src/pybind/mgr/prometheus/module.py: class Module(MgrModule, OrchestratorClientMixin):
+ host = cast(str, server.get('hostname', ''))
+ for service in cast(List[ServiceInfoT], server.get('services', [])):
+ ret.update({(service['id'], service['type']): (host,
+- service.get('ceph_version', 'unknown'),
++ service.get(
++ 'ceph_version', 'unknown'),
+ service.get('name', ''))})
+ return ret
+ How to proceed:
- Authors (Genuine Conflicts): If this is a genuine conflict requiring manual resolution, ensure your resolution is correct. You must explain the conflict resolution in the commit message (e.g., leave the standard Git
Conflicts:block intact) and include an explanation for changes. - Authors (Need Help?): Reach out to the Component Lead for technical guidance on complex code conflicts.
- Component Leads (Review): Please review the Range Diff(s) above to verify the author's manual conflict resolution is correct for this release branch. If the deviation is intentional, documented, and approved then the component lead or @ceph/ceph-release-manager can bypass this check by commenting
/audit override.
Be familiar with the rules and guidelines for writing backports.
🛟 Need Help?
If you need technical help resolving these issues, please consult with the Component Lead. If you need administrative overrides, please see the #ceph-upstream-releases channel on Slack and request a review from the @ceph/ceph-release-manager.
📋 Component Lead / Release Manager
To override the audit failure, apply releng-audit-override label or comment /audit override.
When you are ready for a new audit, please remove the releng-audit-fail label or comment /audit retest.
|
✅ Audit Override Applied by @batrick. |
backport tracker: https://tracker.ceph.com/issues/74057
backport of #65245
parent tracker: https://tracker.ceph.com/issues/68989
this backport was staged using ceph-backport.sh version 16.0.0.6848
find the latest version at https://github.com/ceph/ceph/blob/main/src/script/ceph-backport.sh