Skip to content

Interface fixes & enhancements - #33

Closed
Marenz wants to merge 7 commits into
frequenz-floss:v0.x.xfrom
Marenz:moar
Closed

Marenz wants to merge 7 commits into
frequenz-floss:v0.x.xfrom
Marenz:moar

Conversation

@Marenz

@Marenz Marenz commented Apr 16, 2024

Copy link
Copy Markdown
Contributor
  • Fix start_time conversion imprecision bug
  • Rename client-side create request fields is_{active,dry_run}
  • Make .create() return the new created dispatch

@Marenz
Marenz requested a review from a team as a code owner April 16, 2024 13:50
@Marenz
Marenz requested a review from ktickner April 16, 2024 13:50
@github-actions github-actions Bot added the part:tests Affects the unit, integration and performance (benchmarks) tests label Apr 16, 2024
@github-actions github-actions Bot added the part:docs Affects the documentation label Apr 16, 2024
@Marenz
Marenz requested review from llucax and removed request for ktickner April 16, 2024 13:53
@Marenz
Marenz force-pushed the moar branch 3 times, most recently from 9f3141d to b607783 Compare April 16, 2024 14:14

@llucax llucax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It might be useful to comment in more detail why there was any imprecision in "Fix start_time conversion imprecision bug" and how it is fixed by the common functions, at least for me it is not clear so I might make the same mistake in other API clients.

Comment thread RELEASE_NOTES.md Resolved
Comment thread src/frequenz/client/dispatch/_client.py Resolved
Comment thread src/frequenz/client/dispatch/_client.py Resolved
@Marenz
Marenz force-pushed the moar branch 2 times, most recently from 2a5cb78 to 3a12a94 Compare April 16, 2024 16:33
@Marenz

Marenz commented Apr 16, 2024

Copy link
Copy Markdown
Contributor Author

Updated:

  • always return Dispatch in create now (no parameter
  • use dict of CreateRequest for attribute comparison
  • Added explanation for time bug

@Marenz
Marenz force-pushed the moar branch 2 times, most recently from 96ff3ea to 36a64cd Compare April 17, 2024 17:00
@Marenz Marenz changed the title Small interface fixes & enhancements Interface fixes & enhancements Apr 17, 2024
@leandro-lucarella-frequenz

This comment was marked as outdated.

@llucax

llucax commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

I suggest opening a new PR with the new commits, as they are not really necessary to be in this PR and we were close to finish the review. I have a few comments for the new commits and that will make merging this PR more time consuming.

@llucax

llucax commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

Added explanation for time bug

Awesome, thanks! Now I remember.

@llucax llucax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With this small change, this should be ready to merge up to the commit changing the Client.create() method.

"""
async for dispatch in self.list(microgrid_id=request.microgrid_id):
found = True
for key, value in request.__dict__.items():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you sure this works as expected? When I look at __dict__ in a message it also have __slots__ and other stuff, maybe it would be better to use the google.protobuf.json_format.MessageToDict function?

You'll need to set at lest including_default_value_fields=True and I guess it would be better to set use_integers_for_enums=True and maybe something like float_precision=8.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It at least seems to be what I expected it to be..
These are the fields and their values I get in my loop

request.microgrid_id = 1
request.type = ECHO_FREQUENCY
request.start_time = 2024-04-18 18:44:42.901963+00:00
request.duration = 0:05:00
request.selector = ComponentCategory.INVERTER
request.active = True
request.dry_run = False
request.payload = {'font': 'Times New Roman'}
request.recurrence = RecurrenceRule(frequency=<Frequency.UNSPECIFIED: 0>, interval=0, end_criteria=None, byminutes=[], byhours=[], byweekdays=[], bymonthdays=[], bymonths=[])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, besides, this isn't a Protobuf object, this is our abstraction. We only convert to protobuf right before sending the request.

@Marenz

Marenz commented Apr 18, 2024

Copy link
Copy Markdown
Contributor Author

Responded to comment and removed the unrelated commits

@github-actions github-actions Bot added the part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) label Apr 22, 2024
Marenz and others added 5 commits April 23, 2024 17:19
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Use client-common v0.1.0 and api-dispatch v0.13.0
To properly convert from protobuf to datetime, one has to explicitly
handle the nanoseconds like so:

```python
    # Add microseconds and add nanoseconds converted to microseconds
    microseconds = int(ts.nanos / 1000)
    return datetime.fromtimestamp(ts.seconds + microseconds * 1e-6,
tz=tz)
```

We implemented a convert function that does exactly this, but we have
not been using it consistently yet. This commit replaces the last
occurances.

With that in mind, this commit changes:
* Consistently use the conversion function from the common repository
Fix start_time conversion imprecision bug
* Use shorter notations to set timezones
* Raise on invalid timezone in create()

Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Makes it easier to handle & compare the request object with
a dispatch object, also adds more consistency overall.

Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Some tests require extra checks to not rely on the order.

Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Marenz added 2 commits April 23, 2024 18:33
Round start_time seconds to have the same behavior as the gRPC server
frequenz-io/frequenz-service-dispatch#77

Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
There is hardly any use-case for wanting to use `create()` and not have the
new dispatch available.

This is also in anticipation of the upcoming server-side feature that will
return the newly created dispatch.

Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>

@shsms shsms left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a couple of comments - no immediate action needed for one of them I think.

Comment on lines +129 to +130
Will try to return the created dispatch, identifying it by
the same fields as the request.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe present tense is nicer, but you could also elaborate a bit on what "try" means:

Suggested change
Will try to return the created dispatch, identifying it by
the same fields as the request.
Returns the created dispatch, if it can be identified using
the same fields as the request. If not, raises an exception.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a fair suggestion, though given that we'll update this part soon, I think we can leave it for now.

if key == "start_time":
value = rounded_start_time(value)

if not (found := getattr(dispatch, key) == value):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since python 3.11 getattr can be much slower because they get in the way of the adaptive interpreter and other optimizations. It is too bad api.CreateDispatch doesn't return a dispatch ID, or the entire dispatch.

Won't be a bad idea to implement this in the api level, I think, so that you can avoid additional calls to list and then filter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Won't be a bad idea to implement this in the api level, I think, so that you can avoid additional calls to list and then filter.

That's all in the works, this is just to provide the feature before the API is ready. That way we can later add it and clients don't need to change.

@Marenz
Marenz enabled auto-merge April 24, 2024 10:00
ktickner
ktickner previously approved these changes Apr 24, 2024
@Marenz
Marenz dismissed ktickner’s stale review April 24, 2024 10:02

The merge-base changed after approval.

@shsms

shsms commented Apr 24, 2024

Copy link
Copy Markdown
Contributor

Ok, LGTM then.

ktickner
ktickner previously approved these changes Apr 24, 2024
@Marenz
Marenz disabled auto-merge April 24, 2024 10:05
@Marenz
Marenz dismissed ktickner’s stale review April 24, 2024 10:08

The merge-base changed after approval.

ktickner
ktickner previously approved these changes Apr 24, 2024
@Marenz
Marenz dismissed ktickner’s stale review April 24, 2024 10:15

The merge-base changed after approval.

@Marenz

Marenz commented Apr 24, 2024

Copy link
Copy Markdown
Contributor Author

Re-opeening as github seems very bugged now.

@Marenz Marenz closed this Apr 24, 2024
@Marenz
Marenz deleted the moar branch April 24, 2024 10:26
@shsms

shsms commented Apr 24, 2024

Copy link
Copy Markdown
Contributor

Probably needs a rebase?

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:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants