Skip to content

Commit

Permalink
chore: generate warnings for events that will be removed in Juju 4.0 (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
tonyandrewmeyer authored Sep 18, 2024
1 parent 84ad4b0 commit 94bf413
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ops/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import enum
import logging
import pathlib
import warnings
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
):
Expand Down

0 comments on commit 94bf413

Please sign in to comment.