Skip to content

Commit 998ebff

Browse files
authored
Improve ComponentMetricsRequest documentation (#1092)
2 parents 9df4beb + 15e8d02 commit 998ebff

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

RELEASE_NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
* The `MovingWindow` now take all arguments as keyword-only to avoid mistakes.
1919
* The `frequenz-quantities` dependency was bumped to `1.0.0rc3`.
20+
* The `ComponentMetricsRequest` now produces a channel name without the `start_date` if the `start_date` is `None`. If you are somehow relying on the old behavior, please update your code.
2021

2122
## New Features
2223

src/frequenz/sdk/microgrid/_data_sourcing/_component_metric_request.py

+29-19
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,28 @@
1313

1414
@dataclass
1515
class ComponentMetricRequest:
16-
"""A request object to start streaming a metric for a component."""
16+
"""A request to start streaming a component's metric.
17+
18+
Requesters use this class to specify which component's metric they want to subscribe
19+
to, including the component ID, metric ID, and an optional start time. The
20+
`namespace` is defined by the requester and influences the construction of the
21+
channel name via the `get_channel_name()` method.
22+
23+
The `namespace` allows differentiation of data streams for the same component and
24+
metric. For example, requesters can use different `namespace` values to subscribe to
25+
raw or resampled data streams separately. This ensures that each requester receives
26+
the appropriate type of data without interference. Requests with the same
27+
`namespace`, `component_id`, and `metric_id` will use the same channel, preventing
28+
unnecessary duplication of data streams.
29+
30+
The requester and provider must use the same channel name so that they can
31+
independently retrieve the same channel from the `ChannelRegistry`. This is
32+
achieved by using the `get_channel_name` method to generate the name on both sides
33+
based on parameters set by the requesters.
34+
"""
1735

1836
namespace: str
19-
"""The namespace that this request belongs to.
20-
21-
Metric requests with a shared namespace enable the reuse of channels within
22-
that namespace.
23-
24-
If for example, an actor making a multiple requests, uses the name of the
25-
actor as the namespace, then requests from the actor will get reused when
26-
possible.
27-
"""
37+
"""A client-defined identifier influencing the channel name."""
2838

2939
component_id: int
3040
"""The ID of the requested component."""
@@ -35,21 +45,21 @@ class ComponentMetricRequest:
3545
start_time: datetime | None
3646
"""The start time from which data is required.
3747
38-
When None, we will stream only live data.
48+
If None, only live data is streamed.
3949
"""
4050

4151
def get_channel_name(self) -> str:
42-
"""Return a channel name constructed from Self.
43-
44-
This channel name can be used by the sending side and receiving sides to
45-
identify the right channel from the ChannelRegistry.
52+
"""Construct the channel name based on the request parameters.
4653
4754
Returns:
48-
A string denoting a channel name.
55+
A string representing the channel name.
4956
"""
57+
start = f",start={self.start_time}" if self.start_time else ""
5058
return (
51-
f"component_metric_request<namespace={self.namespace},"
59+
"component_metric_request<"
60+
f"namespace={self.namespace},"
5261
f"component_id={self.component_id},"
53-
f"metric_id={self.metric_id.name},"
54-
f"start={self.start_time}>"
62+
f"metric_id={self.metric_id.name}"
63+
f"{start}"
64+
">"
5565
)

0 commit comments

Comments
 (0)