-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Watcher: Only trigger a watch if new or schedule/changed #35908
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
Watcher: Only trigger a watch if new or schedule/changed #35908
Conversation
The trigger engine did always create a new schedule data structure, when the watcher indexing listener called an add. However the indexing listener also called add, when the watch status was updated. This means, that upon a watch status update the watch got retriggered, potentially waiting a defined interval from the watch status update onwards, instead of waiting from the last run. This commit only updates the schedule in the trigger engine, if it actually has changed, otherwise the existing schedule will not be touched. This has two results 1. If a watch is updated by an execution, the existing interval will not be touched (meaning the scheduled time will not move forward). 2. If a watch is updated by a user, but the schedule is not changed, it will not be reset from the update (for example starting to count from 5 minutes again, if the interval was set to 5 minutes). Furthermore some minor cleanups were applied, making variables final in the ctor, preventing double creation of variables.
|
Pinging @elastic/es-core-features |
jakelandis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple minor/questions but LGTM as-is too.
| // resulting in later executions, as the time would only count after a watch has been stored, as this code is triggered by the | ||
| // watcher indexing listener | ||
| // this also means that updating an existing watch would not retrigger the schedule time, if it remains the same schedule | ||
| if (currentSchedule == null || currentSchedule.schedule.equals(trigger.getSchedule()) == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: should we add a comment to the Schedule interface that implementations must implement .equals ? (else this check may silently fail)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. the only way to really fix that would be to implement sth like Comparable, but that is not really needed from a functional perspective. I have added a comment for now.
| new DateTime(triggeredTime, UTC), new DateTime(scheduledTime, UTC)); | ||
| events.add(new ScheduleTriggerEvent(schedule.name, new DateTime(triggeredTime, UTC), | ||
| new DateTime(scheduledTime, UTC))); | ||
| DateTime triggeredDateTime = new DateTime(triggeredTime, UTC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: curious why not Java time here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the datetime is used two lines below in the CTOR. We will work on switching fully to java time in the future.
| public void accept(Iterable<TriggerEvent> events) { | ||
| events.forEach(triggerEvents::add); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: Is the register and triggerEvents needed here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. removed.
The trigger engine did always create a new schedule data structure, when the watcher indexing listener called an add. However the indexing listener also called add, when the watch status was updated. This means, that upon a watch status update the watch got retriggered, potentially waiting a defined interval from the watch status update onwards, instead of waiting from the last run. This commit only updates the schedule in the trigger engine, if it actually has changed, otherwise the existing schedule will not be touched. This has two results 1. If a watch is updated by an execution, the existing interval will not be touched (meaning the scheduled time will not move forward). 2. If a watch is updated by a user, but the schedule is not changed, it will not be reset from the update (for example starting to count from 5 minutes again, if the interval was set to 5 minutes). Furthermore some minor cleanups were applied, making variables final in the ctor, preventing double creation of variables.
The trigger engine did always create a new schedule data structure, when the watcher indexing listener called an add. However the indexing listener also called add, when the watch status was updated. This means, that upon a watch status update the watch got retriggered, potentially waiting a defined interval from the watch status update onwards, instead of waiting from the last run. This commit only updates the schedule in the trigger engine, if it actually has changed, otherwise the existing schedule will not be touched. This has two results 1. If a watch is updated by an execution, the existing interval will not be touched (meaning the scheduled time will not move forward). 2. If a watch is updated by a user, but the schedule is not changed, it will not be reset from the update (for example starting to count from 5 minutes again, if the interval was set to 5 minutes). Furthermore some minor cleanups were applied, making variables final in the ctor, preventing double creation of variables.
The trigger engine did always create a new schedule data structure, when
the watcher indexing listener called an add. However the indexing
listener also called add, when the watch status was updated. This means,
that upon a watch status update the watch got retriggered, potentially
waiting a defined interval from the watch status update onwards, instead
of waiting from the last run.
This commit only updates the schedule in the trigger engine, if it
actually has changed, otherwise the existing schedule will not be
touched. This has two results
be touched (meaning the scheduled time will not move forward).
will not be reset from the update (for example starting to count from 5
minutes again, if the interval was set to 5 minutes).
Furthermore some minor cleanups were applied, making variables final in
the ctor, preventing double creation of variables, preventing shadow naming.