Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

mgaido91
Copy link
Contributor

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:

  1. Unauthorized user
    screen shot 2018-06-26 at 3 53 33 pm

  2. Non-existing application
    screen shot 2018-06-26 at 3 25 19 pm

After the patch

  1. Unauthorized user
    screen shot 2018-06-26 at 3 41 29 pm

  2. Non-existing application
    screen shot 2018-06-26 at 3 40 37 pm

@mgaido91
Copy link
Contributor Author

cc @attilapiros @jerryshao @vanzin

@@ -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())
Copy link
Contributor

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 serverErrormethod just sets the status to Status.INTERNAL_SERVER_ERROR which overwritten by right away with Response.Status.SERVICE_UNAVAILABLE.

@SparkQA
Copy link

SparkQA commented Jun 26, 2018

Test build #92343 has finished for PR 21644 at commit 8b26a53.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@mgaido91
Copy link
Contributor Author

thanks for you comment @attilapiros. I followed it. Any more comments on this?

@SparkQA
Copy link

SparkQA commented Jun 27, 2018

Test build #92378 has finished for PR 21644 at commit 9934d47.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@jerryshao
Copy link
Contributor

@mgaido91 , would you please check all other response to see if it returns as expected, not only download link.

@SparkQA
Copy link

SparkQA commented Jun 27, 2018

Test build #92380 has finished for PR 21644 at commit 43efe0f.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@mgaido91
Copy link
Contributor Author

mgaido91 commented Jun 27, 2018

@jerryshao yes, I checked other too, here it is some examples:

screen shot 2018-06-27 at 5 20 35 pm
screen shot 2018-06-27 at 5 20 56 pm

screen shot 2018-06-27 at 5 22 35 pm
screen shot 2018-06-27 at 5 22 59 pm

Copy link
Contributor

@attilapiros attilapiros left a 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

@mgaido91
Copy link
Contributor Author

thanks @attilapiros for taking a look at this!

.entity(ErrorWrapper(msg))
.build()
)
new ServiceUnavailableException(msg),
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

@mgaido91 mgaido91 Jun 27, 2018

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.

Copy link
Contributor

@vanzin vanzin Jun 27, 2018

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.

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@vanzin vanzin left a 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,
Copy link
Contributor

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?

@SparkQA
Copy link

SparkQA commented Jun 27, 2018

Test build #92384 has finished for PR 21644 at commit 0be2525.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 27, 2018

Test build #92386 has finished for PR 21644 at commit a9baa7c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor

vanzin commented Jun 27, 2018

Merging to master.

@asfgit asfgit closed this in 776befb Jun 27, 2018
@SparkQA
Copy link

SparkQA commented Jun 27, 2018

Test build #92392 has finished for PR 21644 at commit 0c6bbbc.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

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.

5 participants