Fix up error handling in unusedSegments API.#16206
Conversation
- Throwing DruidException directly without wrapping it up in a proper Response object causes the server to treat them as 500 with a huge junk stacktrace. This PR fixes that by handling DruidException and any other exception in this API. - Also, clean up and break up the unit tests such that each test case is on its own. Validate the status codes in addition to the exception messages.
| return Response.status(Response.Status.OK).entity(retVal).build(); | ||
| } | ||
| catch (DruidException e) { | ||
| return Response |
There was a problem hiding this comment.
It will be nice if we can hook this into the web-server somehow so all APIs benefits. I haven't looked into how to do it, though.
There was a problem hiding this comment.
You would need to write a ResourceFilter and tag all relevant API endpoint methods with @ResourceFilter(DruidExceptionMappingFilter.class).
There was a problem hiding this comment.
Thanks 👍 Can look into wiring that up for all the endpoints in a follow up.
| return Response.status(Response.Status.OK).entity(retVal).build(); | ||
| } | ||
| catch (DruidException e) { | ||
| return Response |
There was a problem hiding this comment.
You would need to write a ResourceFilter and tag all relevant API endpoint methods with @ResourceFilter(DruidExceptionMappingFilter.class).
server/src/main/java/org/apache/druid/server/http/MetadataResource.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/apache/druid/server/http/MetadataResourceTest.java
Show resolved
Hide resolved
server/src/test/java/org/apache/druid/server/http/MetadataResourceTest.java
Outdated
Show resolved
Hide resolved
processing/src/main/java/org/apache/druid/java/util/common/Intervals.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Kashif Faraz <kashif.faraz@gmail.com>
| authorizedSegments.iterator().forEachRemaining(retVal::add); | ||
| return Response.status(Response.Status.OK).entity(retVal).build(); | ||
| } | ||
| catch (DruidException e) { |
There was a problem hiding this comment.
Could we not instead map InvalidInput exception to the appropriate response in some higher layer exception mapper so that all apis benefit, instead of doing this try catch here?
There was a problem hiding this comment.
Yes, I agree and had similar thoughts in this comment: #16206 (comment)
4333e3c to
a0f8b49
Compare
| ) + 1 | ||
| ).getPath(); | ||
| final List<PathSegment> pathSegments = request.getPathSegments(); | ||
| final String dataSourceName = pathSegments.get( |
There was a problem hiding this comment.
Thanks for simplifying this!
Problem:
Before this patch, the
/datasources/{dataSourceName}/unusedSegmentsAPI throws a 500 with a huge stack trace for any invalid parameters specified in the request. This is becauseDruidExceptions are thrown without mapping them to a HTTP response.Click here to see the stacktrace with a 500 error code
Changes:
Responseobject with the appropriate error code.AuthorizationUtils.filterAuthorizedResources()withDatasourceResourceFilter. The endpoint is annotated consistent with other usages.DatasourceResourceFilterto remove the lambda and update javadocs. The usages information is self-evident with an IDE.testGetUnusedSegmentsInDataSource()into smaller unit tests for each test case. Also, validate the error codes.With the fix in this patch, a 400 error code is returned without the stacktrace:
This PR has: