Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@

<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->

- Receivers created with `GrpcStreamBroadcaster.new_receiver(include_events=True)` are no longer a `frequenz.channels.Merger`. If you call `stop()` on them, call `close()` instead.
- For these receivers, overflow is no longer logged as one warning per dropped message by the `frequenz.channels._broadcast` logger. The `frequenz.client.base.streaming` logger now logs one warning when a buffer starts dropping messages and one info message afterwards. Update log filters and alerts that match the old message.

## New Features

<!-- Here goes the main new features and examples or instructions on how to use them -->

- `GrpcStreamBroadcaster.new_receiver()` has a new `overflow_recovery_period` argument, 5 minutes by default. With `include_events=True` and `warn_on_overflow=True`, the info message is logged the next time a message of the same kind is queued after that long without drops. It is also logged when the stream ends or the receiver is closed, but not when the receiver is garbage-collected.

## Bug Fixes

<!-- Here goes notable bug fixes that are worth a special mention or explanation -->

- `ExponentialBackoff` raises `ValueError` at construction if an interval, the multiplier, or jitter is negative or outside the finite floating-point range.
- `ExponentialBackoff` raises `ValueError` at construction if `initial_interval`, `multiplier` or `jitter` is negative, infinite or NaN, or if `max_interval` is negative or NaN. `max_interval=math.inf` means no maximum.
- `LinearBackoff` raises `ValueError` at construction if `interval` or `jitter` is negative, infinite or NaN.
- `ExponentialBackoff` keeps retrying when the multiplier's power would overflow.
- Receivers created with `include_events=True` now yield data and events in the order they were sent.
- A receiver created with `include_events=True` after the stream ended now stops at once. It waited forever if it was the first such receiver.
- Closing a receiver created with `include_events=True` while a task waits in `receive()` now raises `ReceiverStoppedError` in that task, not `CancelledError`.
- If the retry strategy returns an interval that can't be converted to a `timedelta`, such as infinity or NaN, the stream now ends as if the retry limit was reached: the error is logged, receivers created with `include_events=True` get `StreamFatalError`, and all receivers stop. Before, the broadcaster could fail without closing its receivers, which then waited forever.
- `GrpcStreamBroadcaster.new_receiver()` raises `ValueError` if `maxsize` is less than 1. Before, `maxsize=0` stopped the stream for every receiver on the first message.
32 changes: 25 additions & 7 deletions src/frequenz/client/base/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"""Default retry jitter, in seconds."""


def _is_finite_nonnegative(value: float) -> bool:
"""Return whether `value` is a finite, nonnegative float."""
return 0.0 <= value <= float_info.max


class Strategy(ABC):
"""Interface for implementing retry strategies."""

Expand Down Expand Up @@ -92,10 +97,20 @@ def __init__(

Args:
interval: time to wait for before the next retry, in seconds.
Must be finite and nonnegative.
jitter: a jitter to add to the retry interval.
Must be finite and nonnegative.
limit: max number of retries before giving up. `None` means no
limit, and `0` means no retry.

Raises:
ValueError: If `interval` or `jitter` is invalid.
"""
for name, value in (("interval", interval), ("jitter", jitter)):
if not _is_finite_nonnegative(value):
raise ValueError(
f"{name} must be finite and nonnegative, got {value!r}"
)
self._interval = interval
self._jitter = jitter
self._limit = limit
Expand Down Expand Up @@ -143,13 +158,13 @@ def __init__( # pylint: disable=too-many-arguments

Args:
initial_interval: Base wait before the first retry, in seconds.
Must be nonnegative and fit in a finite float.
Must be finite and nonnegative.
max_interval: Maximum wait, including jitter, in seconds.
Must be nonnegative and fit in a finite float.
Must be nonnegative. [`math.inf`][] means no maximum.
multiplier: Factor applied for each retry after the first.
Must be nonnegative and fit in a finite float.
Must be finite and nonnegative.
jitter: Maximum jitter to add to the base interval, in seconds.
Must be nonnegative and fit in a finite float.
Must be finite and nonnegative.
limit: Maximum number of retries as an integer, or `None` for
unlimited retries. A value of `0` or less disables retries.

Expand All @@ -158,12 +173,15 @@ def __init__( # pylint: disable=too-many-arguments
"""
for name, value in (
("initial_interval", initial_interval),
("max_interval", max_interval),
("multiplier", multiplier),
("jitter", jitter),
):
if not 0.0 <= value <= float_info.max:
raise ValueError(f"{name} must be finite and nonnegative")
if not _is_finite_nonnegative(value):
raise ValueError(
f"{name} must be finite and nonnegative, got {value!r}"
)
if not (_is_finite_nonnegative(max_interval) or max_interval == math.inf):
raise ValueError(f"max_interval must be nonnegative, got {max_interval!r}")

self._initial = float(initial_interval)
self._max = float(max_interval)
Expand Down
Loading