OTP-1807 Move Trivial MonitoredTrip PreChecks#343
Conversation
…yzer can determine whether to even bother locking the monitored trip and all the setup for instantiating this class and running run(). - Convenience method for unit test to call static method.
…h preCheck = true for unit test.
…h preCheck = true for unit test.
…PreCheck() method to get the trivial checks out of the way before instantiating and running CheckMonitoredTrip instance.
br648
left a comment
There was a problem hiding this comment.
Checking if a snooze check can be added to the pre-check scope or not?
src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTrip.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTrip.java
Show resolved
Hide resolved
| */ | ||
| protected static boolean shouldSkipMonitoredTripPreCheck(MonitoredTrip trip) { | ||
| // before anything else, return true if the trip is inactive | ||
| if (!trip.isActive) { |
There was a problem hiding this comment.
Because no action is performed on trips that match at least the criteria in these methods, I think the criteria should be added to the Mongo filter in MonitorAllTripsJob.makeTripFilter (where some checks here are redundant with those filters). What do you think?
There was a problem hiding this comment.
@JymDyerIBI (not blocking) Any thoughts on my comment above?
| assertEquals(expectedStatus, modifiedTrip.journeyState.tripStatus, message); | ||
| MonitoredTrip modifiedTrip = Persistence.monitoredTrips.getById(monitoredTrip.id); | ||
| assertEquals(expectedStatus, modifiedTrip.journeyState.tripStatus, message); | ||
| } |
There was a problem hiding this comment.
Fix indent for if block.
There was a problem hiding this comment.
Fix indent for the closing bracket.
binh-dam-ibigroup
left a comment
There was a problem hiding this comment.
Could we move stuff from shouldSkipMonitoredTripCheck(trip) to the Mongo filter in makeTripFilter?
binh-dam-ibigroup
left a comment
There was a problem hiding this comment.
Hi @JymDyerIBI, with the latest changes, it is no longer possible to snooze/unsnooze a trip or to modify a snoozed trip (getting request time outs in the UI).
There was a problem hiding this comment.
Some code broke in CI with the error "CheckMonitoredTripTest.java:[1164,43] method shouldUnsnoozeTrip in class org.opentripplanner.middleware.tripmonitor.jobs.CheckMonitoredTrip cannot be applied to given types".
| assertEquals(expectedStatus, modifiedTrip.journeyState.tripStatus, message); | ||
| MonitoredTrip modifiedTrip = Persistence.monitoredTrips.getById(monitoredTrip.id); | ||
| assertEquals(expectedStatus, modifiedTrip.journeyState.tripStatus, message); | ||
| } |
There was a problem hiding this comment.
Fix indent for the closing bracket.
|
|
||
| // After trip has completed, check that trip status has been updated. | ||
| CheckMonitoredTrip check = new CheckMonitoredTrip(monitoredTrip, this::mockOtpPlanResponse); | ||
| if (!CheckMonitoredTrip.shouldSkipMonitoredTripPreCheck(monitoredTrip)) { |
There was a problem hiding this comment.
Would it make sense to replace this if block with an assertion on the expected value for shouldSkipMonitoredTripCheck?
| */ | ||
| protected static boolean shouldSkipMonitoredTripPreCheck(MonitoredTrip trip) { | ||
| // before anything else, return true if the trip is inactive | ||
| if (!trip.isActive) { |
There was a problem hiding this comment.
@JymDyerIBI (not blocking) Any thoughts on my comment above?
src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTrip.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTrip.java
Outdated
Show resolved
Hide resolved
| // Do a few trivial prechecks to see whether to even bother locking the trip | ||
| // and instantiating a CheckMonitoredTrip run. | ||
| if (CheckMonitoredTrip.shouldSkipMonitoredTripPreCheck(trip)) { | ||
| analyzerIsIdle.set(true); | ||
| continue; | ||
| } | ||
|
|
There was a problem hiding this comment.
Delete this block and move the call to shouldSkipMonitoredTripPreCheck, either back inside shouldSkipMonitoredTripCheck, or in doRun right before the call to shouldSkipMonitoredTripCheck.
This change as written causes an error when updating a trip from the UI, for instance to pause notifications or modify a paused trip. When a trip is updated (PUT request), new CheckMonitoredTrip(trip).run() gets run. Because the skipping logic is no longer run, it will try to compute the next active date of an inactive trip (and will never find one).
…CheckMonitoredTrip.java Wording. Co-authored-by: Binh Dam <56846598+binh-dam-ibigroup@users.noreply.github.com>
…CheckMonitoredTrip.java Wording. Co-authored-by: Binh Dam <56846598+binh-dam-ibigroup@users.noreply.github.com>
Checklist
devbefore they can be merged tomaster)Description
CheckMonitoredTrip.shouldSkipMonitoredTripCheck()is a "big brain method" with many checks going on. There are simple checks that can be done as soon as a monitored trip is obtained, so move them into a new method.In production,
TripAnalyzerwill obtain a monitored trip from MongoDB, then instantiate aCheckMonitoredTripclass and execute itsrun()method. We can call this new method before even instantiatingCheckMonitoredTripand avoid all that overhead.