opentripplanner / OpenTripPlanner

An open source multi-modal trip planner
http://www.opentripplanner.org
Other
2.12k stars 1.01k forks source link

Improve cancellation of large response in TransModel API #5908

Closed vpaturet closed 2 weeks ago

vpaturet commented 3 weeks ago

Summary

5883 implemented support for cancelling queries that produce too large responses.

However GraphQL resolvers were not properly canceled, as in the case of an API timeout exception. This PR applies the same logic for large response and API timeout. Both error cases are mapped to the same HTTP error code (422 - Unprocessable Content) since the root cause is identical: a syntactically correct request that uses too much resources.

Note: multilingual error messages should be updated.

Response sent to the API client:


{
  "errors": [
    {
      "message": "The number of fields in the GraphQL result exceeds the maximum allowed: 1000000",
      "locations": [],
      "extensions": {
        "classification": "ResponseTooLarge"
      }
    }
  ]
}

Issue

No

Unit tests

Added unit tests

Documentation

No

codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 35.00000% with 13 lines in your changes missing coverage. Please review.

Project coverage is 69.45%. Comparing base (b9e54d2) to head (9be3805). Report is 20 commits behind head on dev-2.x.

Files Patch % Lines
.../AbortOnUnprocessableRequestExecutionStrategy.java 0.00% 5 Missing :warning:
...entripplanner/apis/transmodel/TransmodelGraph.java 0.00% 3 Missing :warning:
...planner/ext/restapi/resources/PlannerResource.java 0.00% 2 Missing :warning:
...ner/apis/transmodel/ResponseTooLargeException.java 0.00% 2 Missing :warning:
...s/transmodel/MaxFieldsInResultInstrumentation.java 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev-2.x #5908 +/- ## ============================================= - Coverage 69.45% 69.45% -0.01% - Complexity 17064 17069 +5 ============================================= Files 1927 1929 +2 Lines 73578 73584 +6 Branches 7549 7550 +1 ============================================= + Hits 51106 51107 +1 - Misses 19847 19852 +5 Partials 2625 2625 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.