Skip to content

Return typed errors from realtime updates, prepare for realtime statistics - #4424

Merged
leonardehrenfried merged 25 commits into
opentripplanner:dev-2.xfrom
leonardehrenfried:typed-realtime-errors
Sep 8, 2022
Merged

Return typed errors from realtime updates, prepare for realtime statistics#4424
leonardehrenfried merged 25 commits into
opentripplanner:dev-2.xfrom
leonardehrenfried:typed-realtime-errors

Conversation

@leonardehrenfried

@leonardehrenfried leonardehrenfried commented Aug 30, 2022

Copy link
Copy Markdown
Member

Summary

Right now the realtime updates return either a false or null to indicate an error. Instead of proper statistics OTP instead logs lots of errors which are hard to analyse.

In this PR I return proper error types:

  • Optional<UpdateError>
  • Result<TripTimesPatch, UpdateError>

Result is a newly introduced type that contains two result states of a computation: a success or a failure. This is very similar to an Either in functional languages.

Future

This PR enables future development where you can aggregate metrics and return them in Prometheus or an HTTP endpoint.

Basically what is described in #4206.

Log improvements

Before

Lots and lots of these:

09:36:59.761 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 491676271] No pattern found for tripId. Skipping cancellation.
09:36:59.761 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 491676271] Failed to apply TripUpdate.
09:36:59.761 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 491676301] No pattern found for tripId. Skipping cancellation.
09:36:59.761 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 491676301] Failed to apply TripUpdate.
09:36:59.761 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 491676331] No pattern found for tripId. Skipping cancellation.
09:36:59.761 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 491676331] Failed to apply TripUpdate.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992051] No pattern found for tripId. Skipping cancellation.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992051] Failed to apply TripUpdate.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992061] No pattern found for tripId. Skipping cancellation.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992061] Failed to apply TripUpdate.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992071] No pattern found for tripId. Skipping cancellation.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992071] Failed to apply TripUpdate.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992081] No pattern found for tripId. Skipping cancellation.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992081] Failed to apply TripUpdate.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992091] No pattern found for tripId. Skipping cancellation.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992091] Failed to apply TripUpdate.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992101] No pattern found for tripId. Skipping cancellation.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992101] Failed to apply TripUpdate.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992111] No pattern found for tripId. Skipping cancellation.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992111] Failed to apply TripUpdate.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992121] No pattern found for tripId. Skipping cancellation.
09:36:59.767 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992121] Failed to apply TripUpdate.
09:36:59.768 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992131] No pattern found for tripId. Skipping cancellation.
09:36:59.768 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992131] Failed to apply TripUpdate.
09:36:59.768 WARN (TimetableSnapshotSource.java:1044) [feedId: 1, tripId: 472992141] No pattern found for tripId. Skipping cancellation.

After

09:38:55.167 INFO (TimetableSnapshotSource.java:322) [feedId: 1] 245 of 323 update messages were applied successfully
09:38:55.172 ERROR (TimetableSnapshotSource.java:336) [feedId: 1] 7 failures of type UNKNOWN: [1:548853331, 1:562522371, 1:537942001, 1:559810471, 1:537942011, 1:548854041, 1:571903591]
09:38:55.173 ERROR (TimetableSnapshotSource.java:336) [feedId: 1] 71 failures of type TRIP_ID_NOT_FOUND: [1:518239181, 1:491667061, 1:472992111, 1:472994451, 1:472994571, 1:472995141, 1:472994371, 1:472995261, 1:472995061, 1:472992071, 1:491676081, 1:518238971, 1:491653421, 1:491676001, 1:491675871, 1:491676201, 1:472994811, 1:518239261, 1:491667071, 1:518239141, 1:472994731, 1:472994741, 1:491652801, 1:472992121, 1:472994461, 1:472994581, 1:472994381, 1:472995271, 1:472995151, 1:472995071, 1:472992081, 1:491676051, 1:491653251, 1:491653691, 1:491676131, 1:491676331, 1:491653451, 1:518238881, 1:491675841, 1:472994821, 1:472994941, 1:472994631, 1:491667041, 1:472992131, 1:491675811, 1:472994871, 1:472995201, 1:472992051, 1:472992091, 1:491676181, 1:518238911, 1:491676021, 1:518239001, 1:491676221, 1:491676301, 1:491652751, 1:472994511, 1:472994521, 1:472994641, 1:472995211, 1:472994881, 1:472992101, 1:472992061, 1:472992141, 1:491653391, 1:491676191, 1:491676271, 1:518238941, 1:518239231, 1:491676111, 1:491652781]
09:38:55.173 INFO (TimetableSnapshotSource.java:346) [feedId: 1] Failures by scheduleRelationship {CANCELED=71, SCHEDULED=7}

Unit tests

Added.

Documentation

n/a

@leonardehrenfried
leonardehrenfried requested a review from a team as a code owner August 30, 2022 10:34
@codecov-commenter

codecov-commenter commented Aug 30, 2022

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 38.42105% with 117 lines in your changes missing coverage. Please review.

Project coverage is 58.23%. Comparing base (00e710e) to head (ad76407).
Report is 8935 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...nner/updater/stoptime/TimetableSnapshotSource.java 14.92% 55 Missing and 2 partials ⚠️
...pplanner/ext/siri/SiriTimetableSnapshotSource.java 0.00% 36 Missing ⚠️
.../org/opentripplanner/ext/siri/TimetableHelper.java 0.00% 11 Missing ⚠️
...main/java/org/opentripplanner/model/Timetable.java 55.00% 9 Missing ⚠️
.../java/org/opentripplanner/common/model/Result.java 93.54% 2 Missing ⚠️
...in/java/org/opentripplanner/model/UpdateError.java 91.66% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             dev-2.x    #4424    +/-   ##
===========================================
  Coverage      58.22%   58.23%            
- Complexity     11204    11215    +11     
===========================================
  Files           1480     1482     +2     
  Lines          59131    59249   +118     
  Branches        6783     6784     +1     
===========================================
+ Hits           34431    34502    +71     
- Misses         22644    22686    +42     
- Partials        2056     2061     +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leonardehrenfried leonardehrenfried added the +Real-Time The issue/PR is related to RealTime updates label Aug 30, 2022
Comment thread src/main/java/org/opentripplanner/common/model/Result.java Outdated
@leonardehrenfried leonardehrenfried changed the title Return typed error from realtime updates, prepare for realtime statistics Return typed errors from realtime updates, prepare for realtime statistics Aug 30, 2022
@hannesj
hannesj requested a review from optionsome September 1, 2022 13:36

@optionsome optionsome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I misunderstood you in the developer meeting. I thought you meant you had changed the default log level of these classes from the logback config but instead you have changed the log level of some calls. I think this is ok. Only minor problem is that there is quite a lot of spam on the debug log level (at least when using an MQTT updater). Should we have these realtime classes grouped in the logback.xml file so that the log level could be easily changed by a developer?

Comment thread src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java Outdated
Comment thread src/main/java/org/opentripplanner/model/Timetable.java
Comment thread src/main/java/org/opentripplanner/updater/stoptime/TimetableSnapshotSource.java Outdated
Comment thread src/main/java/org/opentripplanner/updater/stoptime/TimetableSnapshotSource.java Outdated
warn(tripId, "TripUpdate contains no updates, skipping.");
return false;
debug(tripId, "TripUpdate contains no updates, skipping.");
UpdateError.of(tripId, NO_UPDATES);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this check is duplicate of the check from createUpdatedTripTimes which returned the TOO_FEW_STOPS error. Should we remove one of these checks?

Comment thread src/main/java/org/opentripplanner/updater/stoptime/TimetableSnapshotSource.java Outdated
Comment thread src/main/java/org/opentripplanner/updater/stoptime/TimetableSnapshotSource.java Outdated
Comment thread src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java Outdated
Comment thread src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java Outdated
Comment thread src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java Outdated
Comment thread src/ext/java/org/opentripplanner/ext/siri/TimetableHelper.java Outdated
Comment thread src/main/java/org/opentripplanner/model/Timetable.java Outdated
Comment thread src/main/java/org/opentripplanner/model/Timetable.java Outdated
Comment thread src/main/java/org/opentripplanner/model/Timetable.java Outdated
Comment thread src/main/java/org/opentripplanner/model/Timetable.java Outdated
} else {
// Updated trip
if (handleModifiedTrip(transitModel, fuzzyTripMatcher, feedId, journey)) {
if (handleModifiedTrip(transitModel, fuzzyTripMatcher, feedId, journey).isEmpty()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This still has this check

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This method returns a List<UpdateError>. Would you prefer it to return a Result<Void, List<UpdateError>>?

After having thought about it for a bit I think that using a Result is correct, even though it's a slightly overcomplicated type. WDYT?

Comment on lines +70 to +72
<logger name="org.opentripplanner.model.Timetable" level="warn" />
<logger name="org.opentripplanner.ext.siri.SiriTimetableSnapshotSource" level="warn" />
<logger name="org.opentripplanner.ext.siri.TimetableHelper" level="warn" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it intentional that these have warn as default? I don't know if it's better for these classes than info but just wanted to ask if you had left them like that by accident.


// Add new trip times to the buffer and return success
final boolean updated = buffer.update(pattern, updatedTripTimes, serviceDate);
var maybeError = buffer.update(pattern, updatedTripTimes, serviceDate);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we convert this into a Result?

@leonardehrenfried
leonardehrenfried merged commit a46bf1d into opentripplanner:dev-2.x Sep 8, 2022
@leonardehrenfried
leonardehrenfried deleted the typed-realtime-errors branch September 8, 2022 14:13
t2gran pushed a commit that referenced this pull request Sep 8, 2022
@t2gran t2gran added this to the 2.2 milestone Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

+Real-Time The issue/PR is related to RealTime updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants