Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch and expose microgrid ID and location #708

Conversation

daniel-zullo-frequenz
Copy link
Contributor

Fixes #265

@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:microgrid Affects the interactions with the microgrid labels Oct 6, 2023
@daniel-zullo-frequenz daniel-zullo-frequenz changed the title Fetch and expose microgrid metadata Fetch and expose microgrid ID and location Oct 6, 2023
@github-actions github-actions bot added the part:docs Affects the documentation label Oct 6, 2023
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

This way you only need to update the medatada(self) method to remove the if not microgrid_metadata: return Metadata(...) and raise a custom error (or let the AioRpcError bubble up) when the microgrid service catches up.

src/frequenz/sdk/microgrid/client/_client.py Outdated Show resolved Hide resolved
src/frequenz/sdk/microgrid/client/_client.py Outdated Show resolved Hide resolved
src/frequenz/sdk/microgrid/client/_client.py Outdated Show resolved Hide resolved
src/frequenz/sdk/microgrid/connection_manager.py Outdated Show resolved Hide resolved
src/frequenz/sdk/microgrid/connection_manager.py Outdated Show resolved Hide resolved
@llucax
Copy link
Contributor

llucax commented Oct 10, 2023

BTW @tiyash-basu-frequenz when the microgrid service implements this, not getting a metadata object (with the location and microgrid ID) should be an unrecoverable error, right?

@tiyash-basu-frequenz
Copy link
Contributor

BTW @tiyash-basu-frequenz when the microgrid service implements this, not getting a metadata object (with the location and microgrid ID) should be an unrecoverable error, right?

The API will return an error if none of the metadata items is available. We can discuss the behaviour for partially available metadata (e.g., there is a microgrid ID, but no location info).

I was thinking about returning an error if the microgrid ID is missing. But if just location is missing, then we should return the metadata object with location set to None.

@llucax llucax changed the base branch from v0.x.x to v1.x.x October 11, 2023 07:20
@daniel-zullo-frequenz daniel-zullo-frequenz force-pushed the feature/microgrid-metadata branch 2 times, most recently from 94e5326 to 0f03d5a Compare October 12, 2023 14:30
@daniel-zullo-frequenz
Copy link
Contributor Author

Updated based on comments from Tiyash and Luca

@llucax
Copy link
Contributor

llucax commented Oct 13, 2023

@tiyash-basu-frequenz we were thinking that for working with the microgrid API itself, the micrigrid_id is completely irrelevant, so we shouldn't stop the SDK from working if for some reason we can't get any metadata at all. The location might be useful, but I guess different users can decide if not having a location is a show stopper or if they can do without it (I guess many uses cases will work without a location too).

So SDK-wise, I think we'll allow all metadata to be missing regardless of what the microgrid API does.

@llucax
Copy link
Contributor

llucax commented Oct 13, 2023

we were thinking that for working with the microgrid API itself, the micrigrid_id is completely irrelevant, so we shouldn't stop the SDK from working if for some reason we can't get any metadata at all. The location might be useful, but I guess different users can decide if not having a location is a show stopper or if they can do without it (I guess many uses cases will work without a location too).

So SDK-wise, I think we'll allow all metadata to be missing regardless of what the microgrid API does.

Before @daniel-zullo-frequenz reverts the latest changes, @frequenz-floss/python-sdk-team do we agree on this path? ☝️

So basically microgrid_id: int | None and location: Location | None (and I think even possibly latitude and longitude could be None too, for example for some Sun position calculations only latitude is relevant, so if for some reason a longitude is missing we should still provide the latitude.

@tiyash-basu-frequenz
Copy link
Contributor

for some Sun position calculations only latitude is relevant, so if for some reason a longitude is missing we should still provide the latitude.

... and vice-versa. IMO the SDK should be use-case agnostic here, and the client-app should decide whether the missing information is an error condition or not.
It also applies to country_code (in the upcoming Microgrid API release).

@daniel-zullo-frequenz daniel-zullo-frequenz force-pushed the feature/microgrid-metadata branch 4 times, most recently from 2cfdebb to 3976ccd Compare October 24, 2023 15:29
@llucax llucax self-requested a review October 31, 2023 13:06
@daniel-zullo-frequenz daniel-zullo-frequenz marked this pull request as ready for review November 3, 2023 21:49
@daniel-zullo-frequenz daniel-zullo-frequenz requested a review from a team as a code owner November 3, 2023 21:49
Copy link
Contributor

@Marenz Marenz left a comment

Choose a reason for hiding this comment

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

LGTM, just one comment

src/frequenz/sdk/microgrid/metadata.py Outdated Show resolved Hide resolved
src/frequenz/sdk/microgrid/metadata.py Outdated Show resolved Hide resolved
src/frequenz/sdk/microgrid/metadata.py Outdated Show resolved Hide resolved
tests/microgrid/test_microgrid_api.py Show resolved Hide resolved
The microgrid metadata is needed to retrieve
the ID and location of the microgrid.

Signed-off-by: Daniel Zullo <[email protected]>
So far the microgrid metadata is needed to get the ID and
the location of the microgrid. The metadata is retrieved
from the microgrid API through the gRPC call GetMicrogridMetadata.

Signed-off-by: Daniel Zullo <[email protected]>
The ConnectionManager retrieves the metadata at
initialization when connecting to the microgrid.

Signed-off-by: Daniel Zullo <[email protected]>
Signed-off-by: Daniel Zullo <[email protected]>
@@ -15,6 +15,7 @@
from frequenz.api.microgrid import microgrid_pb2 as microgrid_pb
from frequenz.api.microgrid.microgrid_pb2_grpc import MicrogridStub
from frequenz.channels import Broadcast, Receiver, Sender
from google.protobuf.empty_pb2 import Empty # pylint: disable=no-name-in-module
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is being used all over the place in the SDK, but if we use this instead, then we don't need the # pylint disable=...:

Suggested change
from google.protobuf.empty_pb2 import Empty # pylint: disable=no-name-in-module
from google.protobuf import .empty_pb2

Maybe we can create an issue to change it in a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created #774

Copy link
Contributor

Choose a reason for hiding this comment

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

not there, but we will need it later, where we say empty_pb2.Empty, I think it just moves the hint to a different place.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I think some symbols are dynamically generated and pylint falis to see them at the import level, but once it is imported it works fine.

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've checked it and Sahas is right, this just moves the pylint error to the place empty_pb2.Empty is used, so from no-name-in-module to no-member

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I also saw that, I closed #774 as invalid, and it seems pylnt 3 should fix the issue, but a preliminary test didn't work. We'll see.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the follow up!

@daniel-zullo-frequenz daniel-zullo-frequenz added this pull request to the merge queue Nov 7, 2023
Merged via the queue into frequenz-floss:v1.x.x with commit 39854a8 Nov 7, 2023
14 checks passed
@daniel-zullo-frequenz daniel-zullo-frequenz deleted the feature/microgrid-metadata branch November 7, 2023 11:21
@llucax llucax added this to the v1.0.0-rc3 milestone Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
Development

Successfully merging this pull request may close these issues.

Retrieve and expose microgrid metadata
5 participants