Skip to content

Conversation

@Marenz
Copy link
Contributor

@Marenz Marenz commented Jan 7, 2025

  • Add unify merge filter for dispatches
  • Ensure that start events are executed before stop events
  • Update release notes

Signed-off-by: Mathias L. Baumann <[email protected]>
@Marenz Marenz requested a review from a team as a code owner January 7, 2025 18:23
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:dispatcher Affects the high-level dispatcher interface labels Jan 7, 2025
@Marenz Marenz requested review from llucax and removed request for stefan-brus-frequenz January 7, 2025 18:23
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.

Interesting, I always thought merging multiple dispatches in one big period was the default behavior.

LGTM for now, but in the future I think we should really go for extensible merge strategies / policies, so we can implement merging by target too for example.

I guess to implement this externally as merge strategy/policy objects we would need to expose more of the internal state of the dispatcher and pass the dispatcher to the strategy object, or maybe just passing the list of dispatches would be enough too.

"""A queue item for the scheduled events."""

time: datetime
stop_event: bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
stop_event: bool
is_stop_event: bool

Otherwise it sounds like an action? Or even maybe an event enum with START/STOP as it would be more extensible for other potential events? But probably that's overkill at this stage.

BTW, I still don't understand what this is for, it even seems to be unused!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given two events at the same time:

  • Dispatch 12 - STOP
  • Dispatch 13 - START

As the list of events is ordered based on (event time, id),
we would in this case first run dispatch 12 as the time matches and the id smaller.

What we want, however is to run always the START event if the time is equal. Because then the filters looking at the events had a chance to observe START before STOP and thus can filter out the STOP when desired.

it even seems to be unused!

We don't need to directly reference it, the ordering is done by the dataclass

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, this is really sneaky! So you are relying on the order between True and False? You naughty naughty boy...

Then I would definitely clarify this in a comment and probably even make it a priority: int (or a IntEnum) to make it even more clear that this is in the item only to affect the order in the queue.

Copy link
Contributor Author

@Marenz Marenz Jan 13, 2025

Choose a reason for hiding this comment

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

Sneaky? I call that elegant.

@Marenz Marenz force-pushed the mergy branch 2 times, most recently from efb289c to 6a3d2db Compare January 13, 2025 10:20
llucax
llucax previously approved these changes Jan 14, 2025
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.

Just 2 optional comments, so approving. Feel free to force-merge after changes if you decide to address them.

RELEASE_NOTES.md Outdated
* `Dispatcher.running_status_change` has been replaced by the method `Dispatcher.new_running_state_event_receiver(self, type: str)`.
* `Dispatcher.lifecycle_events` has been replaced by the method `Dispatcher.new_lifecycle_events_receiver(self, dispatch_type: str)`.
* `Dispatcher.running_status_change` has been replaced by the method `Dispatcher.new_running_state_event_receiver(self, dispatch_type: str, unify_running_intervals: bool)`.
* A new feature "unify running intervals" has been added to the `Dispatcher.new_running_state_event_receiver` method. Using it, you can automatically merge & unify consecutive and overlapping dispatch start/stop events of the same type. E.g. dispatch `A` starting at 10:10 and ending at 10:30 and dispatch `B` starts at 10:30 until 11:00, with the feature enabled this would in total trigger one start event, one reconfigure event at 10:30 and one stop event at 11:00.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this in Upgrading and now New Features?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it is kind of both?

Copy link
Contributor

Choose a reason for hiding this comment

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

The new option is, optional, so it is backwards compatible, that's what I meant and what I see you put in the release notes 👍

async def new_running_state_event_receiver(self, type: str) -> Receiver[Dispatch]:
"""Create a new receiver for running state events.
async def new_running_state_event_receiver(
self, type: str, unify_running_intervals: bool = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self, type: str, unify_running_intervals: bool = True
self, type: str, *, unify_running_intervals: bool = True

This allows us to filter the `stop` events when we desire to
merge consecutive events.

Signed-off-by: Mathias L. Baumann <[email protected]>
Signed-off-by: Mathias L. Baumann <[email protected]>
@Marenz Marenz merged commit e7fd295 into frequenz-floss:v0.x.x Jan 14, 2025
14 checks passed
@Marenz Marenz deleted the mergy branch January 14, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:dispatcher Affects the high-level dispatcher interface part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants