-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
receive_component_data_samples_stream
method
This method allows to stream data samples from a component. It uses a `GrpcStreamBroadcaster` to handle the streaming of the data samples, even when it doesn't make a lot of sense given how the API works now (it is much less likely that we will have the same request twice, justifiying the reuse of the broadcaster/data channel). To minimize changes, we go with this approach but it will probably be changed in the future. Signed-off-by: Leandro Lucarella <[email protected]>
- Loading branch information
Showing
7 changed files
with
636 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# License: MIT | ||
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH | ||
|
||
"""Definition of a component data aggregate.""" | ||
|
||
from dataclasses import dataclass | ||
|
||
from .._id import ComponentId | ||
from ..metrics._sample import MetricSample | ||
from ._state_sample import ComponentStateSample | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
class ComponentDataSamples: | ||
"""An aggregate of multiple metrics, states, and errors of a component.""" | ||
|
||
component_id: ComponentId | ||
"""The unique identifier of the component.""" | ||
|
||
metrics: list[MetricSample] | ||
"""The metrics sampled from the component.""" | ||
|
||
states: list[ComponentStateSample] | ||
"""The states sampled from the component.""" |
35 changes: 35 additions & 0 deletions
35
src/frequenz/client/microgrid/component/_data_samples_proto.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# License: MIT | ||
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH | ||
|
||
"""Loading of ComponentDataSamples objects from protobuf messages.""" | ||
|
||
|
||
from frequenz.api.common.v1.microgrid.components import components_pb2 | ||
|
||
from .._id import ComponentId | ||
from ..metrics._sample_proto import metric_sample_from_proto | ||
from ._data_samples import ComponentDataSamples | ||
from ._state_sample_proto import component_state_sample_from_proto | ||
|
||
|
||
def component_data_sample_from_proto( | ||
message: components_pb2.ComponentData, | ||
) -> ComponentDataSamples: | ||
"""Convert a protobuf component data message to a component data object. | ||
Args: | ||
message: The protobuf message to convert. | ||
Returns: | ||
The resulting `ComponentDataSamples` object. | ||
""" | ||
# At some point it might make sense to also log issues found in the samples, but | ||
# using a naive approach like in `component_from_proto` might spam the logs too | ||
# much, as we can receive several samples per second, and if a component is in | ||
# a unrecognized state for long, it will mean we will emit the same log message | ||
# again and again. | ||
return ComponentDataSamples( | ||
component_id=ComponentId(message.component_id), | ||
metrics=[metric_sample_from_proto(sample) for sample in message.metric_samples], | ||
states=[component_state_sample_from_proto(state) for state in message.states], | ||
) |
Oops, something went wrong.