-
Notifications
You must be signed in to change notification settings - Fork 28.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-24660][SHS] Show correct error pages when downloading logs #21644
Conversation
@@ -148,38 +148,36 @@ private[v1] trait BaseAppResource extends ApiRequestContext { | |||
} | |||
|
|||
private[v1] class ForbiddenException(msg: String) extends WebApplicationException( | |||
Response.status(Response.Status.FORBIDDEN).entity(msg).build()) | |||
Response.status(Response.Status.FORBIDDEN).entity(msg).`type`(MediaType.TEXT_PLAIN).build()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can extract a new helper function to build the response object from a Response.Status
and a message. I think UIUtils is good place for such a function then you can use it at OneApplicationResource.scala
too as the serverError
method just sets the status to Status.INTERNAL_SERVER_ERROR
which overwritten by right away with Response.Status.SERVICE_UNAVAILABLE
.
Test build #92343 has finished for PR 21644 at commit
|
thanks for you comment @attilapiros. I followed it. Any more comments on this? |
Test build #92378 has finished for PR 21644 at commit
|
@mgaido91 , would you please check all other response to see if it returns as expected, not only download link. |
Test build #92380 has finished for PR 21644 at commit
|
@jerryshao yes, I checked other too, here it is some examples: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No other issue I can see.
LGTM
thanks @attilapiros for taking a look at this! |
.entity(ErrorWrapper(msg)) | ||
.build() | ||
) | ||
new ServiceUnavailableException(msg), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... none of this is your fault, but it seems these exceptions are not needed anymore. jax-rs 2.1 has exceptions for all these and they could just replace these wrappers.
e.g. if you just throw ServiceUnavailableException
directly instead of this wrapper, the result would be the same.
You can find all exceptions at:
https://jax-rs.github.io/apidocs/2.1/javax/ws/rs/package-summary.html
I think it's better to clean this up instead of adding another helper API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your review. Sure I can do the refactor, but the helper method would be needed anyway. Indeed, the problem which was present before the PR is that we are not specifying the type of the response, so it takes the type which is produced. And in the default exceptions you mentioned the Response
is built without setting the type, so we still need to pass them the Response
we build in the helper method.
I will follow your suggestion (so I'll clean up our exceptions using the jax ones), but keeping the helper method for this reason. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, if that's the case then probably the wrappers can save some code (since they abstract the building of the response)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, indeed they do. Not too much code but
throw new ForbiddenException(raw"""user "$user" is not authorized""")
would become
throw new ForbiddenException(UIUtils.buildErrorResponse(
Response.Status.FORBIDDEN, raw"""user "$user" is not authorized"""))
what do you think? Shall we do the refactor?
PS in any case, I'd save the BadParameterException
as it does save a lot of duplicated code with the constructor defined there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok to leave (almost) as is. It avoids duplicating the status code in every call, which would be annoying.
But we can remove the "cause" exceptions from all these wrappers since they're redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I updated with your suggestion, thanks
.status(Response.Status.SERVICE_UNAVAILABLE) | ||
.build() | ||
case NonFatal(_) => | ||
UIUtils.buildErrorResponse(Response.Status.SERVICE_UNAVAILABLE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If doing the cleanup, it's probably ok to just throw the exception here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just throw ServiceUnavailable
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, we need to set the type, otherwise it returns the response as octet-stream which is causing the issue..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But isn't the type being set in the exception now? Seems like the same thing that happens in other cases, where the response is set to json but the exception overrides it when thrown.
But if it doesn't really work, then ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, now I see what you mean, sorry, I didn't get it. I am doing that, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending tests.
.status(Response.Status.SERVICE_UNAVAILABLE) | ||
.build() | ||
case NonFatal(_) => | ||
UIUtils.buildErrorResponse(Response.Status.SERVICE_UNAVAILABLE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just throw ServiceUnavailable
, no?
Test build #92384 has finished for PR 21644 at commit
|
Test build #92386 has finished for PR 21644 at commit
|
Merging to master. |
Test build #92392 has finished for PR 21644 at commit
|
What changes were proposed in this pull request?
SHS is showing bad errors when trying to download logs is not successful. This may happen because the requested application doesn't exist or the user doesn't have permissions for it, for instance.
The PR fixes the response when errors occur, so that they are displayed properly.
How was this patch tested?
manual tests
Before the patch:
Unauthorized user
Non-existing application
After the patch
Unauthorized user
Non-existing application