From 94bf413d3593badfb3f9aa29cb2fdbbfff418d0f Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Wed, 18 Sep 2024 19:50:34 +1200 Subject: [PATCH] chore: generate warnings for events that will be removed in Juju 4.0 (#1374) A `DeprecationWarning` is emitted whenever an instance of `CollectMetricsEvent`, `PreSeriesUpgradeEvent`, or `PostSeriesUpgradeEvent` is created (which should only be whenever there is an observed event of that type). Documentation warnings were already added in an earlier PR. Fixes #1280 --- ops/charm.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ops/charm.py b/ops/charm.py index c626d11da..edef8db32 100644 --- a/ops/charm.py +++ b/ops/charm.py @@ -18,6 +18,7 @@ import enum import logging import pathlib +import warnings from typing import ( TYPE_CHECKING, Any, @@ -359,6 +360,14 @@ class PreSeriesUpgradeEvent(HookEvent): .. jujuremoved:: 4.0 """ + def __init__(self, handle: 'Handle'): + warnings.warn( + 'pre-series-upgrade events will not be emitted from Juju 4.0 onwards', + DeprecationWarning, + stacklevel=3, + ) + super().__init__(handle) + class PostSeriesUpgradeEvent(HookEvent): """Event triggered after a series upgrade. @@ -375,6 +384,14 @@ class PostSeriesUpgradeEvent(HookEvent): .. jujuremoved:: 4.0 """ + def __init__(self, handle: 'Handle'): + warnings.warn( + 'post-series-upgrade events will not be emitted from Juju 4.0 onwards', + DeprecationWarning, + stacklevel=3, + ) + super().__init__(handle) + class LeaderElectedEvent(HookEvent): """Event triggered when a new leader has been elected. @@ -412,6 +429,15 @@ class CollectMetricsEvent(HookEvent): .. jujuremoved:: 4.0 """ + def __init__(self, handle: 'Handle'): + warnings.warn( + 'collect-metrics events will not be emitted from Juju 4.0 onwards - ' + 'consider using the Canonical Observability Stack', + DeprecationWarning, + stacklevel=3, + ) + super().__init__(handle) + def add_metrics( self, metrics: Mapping[str, Union[int, float]], labels: Optional[Mapping[str, str]] = None ):