Skip to content

Remove channel registry#1371

Open
simonvoelcker wants to merge 5 commits intofrequenz-floss:v1.x.xfrom
simonvoelcker:remove-channel-registry
Open

Remove channel registry#1371
simonvoelcker wants to merge 5 commits intofrequenz-floss:v1.x.xfrom
simonvoelcker:remove-channel-registry

Conversation

@simonvoelcker
Copy link
Contributor

@simonvoelcker simonvoelcker commented Mar 5, 2026

This removes the ChannelRegistry class.

Background

This is part of an initiative to close unused channels to save resources. The ChannelRegistry was a de-facto singleton class for storing channels by name. Request objects such as ComponentMetricRequest or ReportRequest have a get_channel_name() method, and the returned channel name acted as a contract between sender and receiver - With the name, they could obtain the same channel from the ChannelRegistry. By getting rid of the registry, we are moving towards a target state where only references to senders and receivers, but no channels are being held.

Implementation

ComponentMetricRequest

ComponentMetricRequest objects represent a request to receive metrics from a component - Sometimes also referred to as telemetry stream. To serve such a request without relying on the ChannelRegistry, the request got a new attribute: telem_stream_sender: Sender[Receiver[Sample[Quantity]]]. This is the sender of a one-shot channel that is used to send the receiver of the telemetry stream back to the original requester - Similar to a callback function. The receiver of a component metric request should therefore create (and own) the channel that sends the metric data, and use the one-shot channel to send a receiver of that channel "back".

In a few places, component metric requests were created and sent from synchronous functions which returned the receiver. To make this work with the round-trip outlined above, an additional channel was added that merely forwards the metric data via a Pipe. This allows us to immediately return a sender while the channel that serves the metric data is being constructed asynchronously.

These changes can be found in the first commit.

ReportRequest

ReportRequest objects are a different kind of request that was handled similarly.

These changes can be found in the second commit.

Channel ownership

The receivers of request objects create the channels and own them. For instance, in case of ComponentMetricRequests, MicrogridApiSource now maintains a dictionary (channel_lookup: dict[str, Broadcast]) as a replacement for the channel registry. It is necessary to have this lookup dictionary to avoid creating duplicate channels for similar metric requests. In this case, a new receiver is created from an existing channel found in the lookup dictionary.

Forwarding channels are owned by their creator (e.g. GridFrequency). These (and the Pipes that connect them to the other channels) are currently never closed. Closing these when all receivers or senders are closed is a TODO for a later iteration.

@github-actions github-actions bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) part:data-pipeline Affects the data pipeline part:core Affects the SDK core components (data structures, etc.) part:microgrid Affects the interactions with the microgrid labels Mar 5, 2026
@simonvoelcker simonvoelcker force-pushed the remove-channel-registry branch 2 times, most recently from f4e6125 to 9186ad8 Compare March 5, 2026 19:16
@github-actions github-actions bot added the part:docs Affects the documentation label Mar 5, 2026
@simonvoelcker simonvoelcker force-pushed the remove-channel-registry branch 3 times, most recently from 360ca1a to a878b7a Compare March 6, 2026 14:04
…ChannelRegistry

Signed-off-by: Simon Völcker <simon.voelcker@frequenz.com>
Signed-off-by: Simon Völcker <simon.voelcker@frequenz.com>
Signed-off-by: Simon Völcker <simon.voelcker@frequenz.com>
Signed-off-by: Simon Völcker <simon.voelcker@frequenz.com>
Signed-off-by: Simon Völcker <simon.voelcker@frequenz.com>
@simonvoelcker simonvoelcker force-pushed the remove-channel-registry branch from a878b7a to 22cd7c5 Compare March 6, 2026 14:42
"frequenz-microgrid-component-graph >= 0.3.4, < 0.4",
"frequenz-client-common >= 0.3.6, < 0.4.0",
"frequenz-channels >= 1.6.1, < 2.0.0",
"frequenz-channels @ git+https://github.com/shsms/frequenz-channels-python.git@oneshot",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't merge before this is merged 👀

@simonvoelcker simonvoelcker marked this pull request as ready for review March 6, 2026 15:17
@simonvoelcker simonvoelcker requested a review from a team as a code owner March 6, 2026 15:17
@simonvoelcker simonvoelcker requested review from florian-wagner-frequenz and removed request for a team March 6, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:core Affects the SDK core components (data structures, etc.) part:data-pipeline Affects the data pipeline part:docs Affects the documentation part:microgrid Affects the interactions with the microgrid part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

1 participant