[persistence] improve time mock for quartz scheduler#1787
Merged
cyrilou242 merged 2 commits intomasterfrom Feb 7, 2025
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes the behavior of the QuartzScheduler simpler to understand when the time is mocked in e2e tests.
Problem
When the time is mocked, time can jump and the quartz scheduler can miss cron triggers.
See
org.quartz.simpl.RamJobStore,org.quartz.core.QuartzSchedulerThreadandorg.quartz.impl.triggers.CronTriggerImplPreviously the logic applied for the cron trigger schedules created here:
was
MISFIRE_INSTRUCTION_SMART_POLICY, which resulted inMISFIRE_INSTRUCTION_FIRE_ONCE_NOWinCronTriggerImpl.updateAfterMisfireThis means jobs were created with a scheduled fire time equal to the mocked time, which would not necessarily correspond to a correct cron trigger time.
This caused issue in the simulation because when a task is created, the endTime is obtained from the scheduled fire time and it is assumed this time is a valid cron time.
See
thirdeye/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/job/DetectionPipelineJob.java
Line 74 in 0756d06
Change
The behavior of the function above
updateAfterMisfireis overridden with aspectJ to behave like MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY.The other implementation option was to introduce a configuration knob in the server and add
.withMisfireHandlingInstructionIgnoreMisfires()to the code herethirdeye/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/TaskCronSchedulerRunnable.java
Line 270 in 713d3b4
but introducing some hard to understand logic in the public config API did not seem like a good idea.
This may be changed in the future if need be, changing from one solution to the other is simple.
The behavior of the QuartzScheduler is now simpler to understand when time is mocked:
thirdeye/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/job/NotificationPipelineJob.java
Line 65 in 0756d06
Because the triggers will run at roughly the same time, this is very likely to happen, so if the output of tasks or the number of tasks is important, best is to increase time 1 cron trigger at a time.
The AnomalyResolutionTest are fixed: they were incorrect, flaky and exploiting the issue described above.
Time mock changes:
other changes are test fixes and improvements