Skip to content

OTP-1807 Move Trivial MonitoredTrip PreChecks#343

Open
JymDyerIBI wants to merge 15 commits intodevfrom
OTP-1807-move-trivial-prechecks
Open

OTP-1807 Move Trivial MonitoredTrip PreChecks#343
JymDyerIBI wants to merge 15 commits intodevfrom
OTP-1807-move-trivial-prechecks

Conversation

@JymDyerIBI
Copy link
Contributor

@JymDyerIBI JymDyerIBI commented Aug 28, 2025

Checklist

  • Appropriate branch selected (all PRs must first be merged to dev before they can be merged to master)
  • Any modified or new methods or classes have helpful JavaDoc and code is thoroughly commented
  • The description lists all applicable issues this PR seeks to resolve
  • The description lists any configuration setting(s) that differ from the default settings (N/A)
  • All tests and CI builds passing

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, TripAnalyzer will obtain a monitored trip from MongoDB, then instantiate a CheckMonitoredTrip class and execute its run() method. We can call this new method before even instantiating CheckMonitoredTrip and avoid all that overhead.

…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.
…PreCheck() method to get the trivial checks out of the way before instantiating and running CheckMonitoredTrip instance.
@JymDyerIBI JymDyerIBI self-assigned this Aug 28, 2025
Copy link
Contributor

@br648 br648 left a comment

Choose a reason for hiding this comment

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

Checking if a snooze check can be added to the pre-check scope or not?

*/
protected static boolean shouldSkipMonitoredTripPreCheck(MonitoredTrip trip) {
// before anything else, return true if the trip is inactive
if (!trip.isActive) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@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);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix indent for if block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indent fixed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix indent for the closing bracket.

Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

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

Could we move stuff from shouldSkipMonitoredTripCheck(trip) to the Mongo filter in makeTripFilter?

Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

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

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).

Copy link
Collaborator

Choose a reason for hiding this comment

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

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);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@JymDyerIBI (not blocking) Any thoughts on my comment above?

Comment on lines +75 to +81
// 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;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

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).

JymDyerIBI and others added 6 commits November 14, 2025 09:40
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants