Skip to content

Commit 13512cc

Browse files
committed
mgr/cephadm: update timestamp on repeat daemon/service events
If you have a daemon/service event and then an identical event happens later (e.g. the same daemon is redeployed multiple times) the events are not updated on the repeat instances. In cases like this I think it makes more sense to update the timestamp so users can see the most recent time the event happened. Fixes: https://tracker.ceph.com/issues/63238 Signed-off-by: Adam King <[email protected]>
1 parent 0787262 commit 13512cc

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/pybind/mgr/cephadm/inventory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,8 @@ def add(self, event: OrchestratorEvent) -> None:
15071507

15081508
for e in self.events[event.kind_subject()]:
15091509
if e.message == event.message:
1510+
# if subject and message match, just update the timestamp
1511+
e.created = event.created
15101512
return
15111513

15121514
self.events[event.kind_subject()].append(event)

src/pybind/mgr/cephadm/tests/test_cephadm.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,42 @@ def test_daemon_action_fail(self, cephadm_module: CephadmOrchestrator):
400400

401401
assert 'myerror' in ''.join(evs)
402402

403+
@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
404+
def test_daemon_action_event_timestamp_update(self, cephadm_module: CephadmOrchestrator):
405+
# Test to make sure if a new daemon event is created with the same subject
406+
# and message that the timestamp of the event is updated to let users know
407+
# when it most recently occurred.
408+
cephadm_module.service_cache_timeout = 10
409+
with with_host(cephadm_module, 'test'):
410+
with with_service(cephadm_module, RGWSpec(service_id='myrgw.foobar', unmanaged=True)) as _, \
411+
with_daemon(cephadm_module, RGWSpec(service_id='myrgw.foobar'), 'test') as daemon_id:
412+
413+
d_name = 'rgw.' + daemon_id
414+
415+
now = str_to_datetime('2023-10-18T22:45:29.119250Z')
416+
with mock.patch("cephadm.inventory.datetime_now", lambda: now):
417+
c = cephadm_module.daemon_action('redeploy', d_name)
418+
assert wait(cephadm_module,
419+
c) == f"Scheduled to redeploy rgw.{daemon_id} on host 'test'"
420+
421+
CephadmServe(cephadm_module)._check_daemons()
422+
423+
d_events = cephadm_module.events.get_for_daemon(d_name)
424+
assert len(d_events) == 1
425+
assert d_events[0].created == now
426+
427+
later = str_to_datetime('2023-10-18T23:46:37.119250Z')
428+
with mock.patch("cephadm.inventory.datetime_now", lambda: later):
429+
c = cephadm_module.daemon_action('redeploy', d_name)
430+
assert wait(cephadm_module,
431+
c) == f"Scheduled to redeploy rgw.{daemon_id} on host 'test'"
432+
433+
CephadmServe(cephadm_module)._check_daemons()
434+
435+
d_events = cephadm_module.events.get_for_daemon(d_name)
436+
assert len(d_events) == 1
437+
assert d_events[0].created == later
438+
403439
@pytest.mark.parametrize(
404440
"action",
405441
[

0 commit comments

Comments
 (0)