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

Include the exception message in error response #14395

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

shounakmk219
Copy link
Collaborator

Add the exception message to the rest endpoint error messages wherever missing so that user knows the reason of request failure without checking the logs

@@ -430,8 +430,8 @@ private SuccessResponse addSchema(Schema schema, boolean override, boolean force
throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.BAD_REQUEST, e);
} catch (Exception e) {
_controllerMetrics.addMeteredGlobalValue(ControllerMeter.CONTROLLER_SCHEMA_UPLOAD_ERROR, 1L);
throw new ControllerApplicationException(LOGGER, String.format("Failed to add new schema %s.", schemaName),
Response.Status.INTERNAL_SERVER_ERROR, e);
throw new ControllerApplicationException(LOGGER, String.format("Failed to add new schema %s. Reason: %s",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a format that we followed for such error logs?
I like this format as it will make easier to search/ grep.

Copy link
Contributor

Choose a reason for hiding this comment

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

I vote against this messages created with String.format. They are difficult to read and may affect performance (in a negative way). In this case the performance is not problematic, but it is just a bad idea to try to do that everywhere

Copy link
Collaborator

Choose a reason for hiding this comment

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

As a developer who learnt the trade on C using printf and snprintf, this is the most natural templatization method for me :)

It is unfortunate that the Java implementation is terrible. A benchmark that shows the terrible performance of String.format. Source: https://stackoverflow.com/a/1281651

StringBuilder or + are possible candidates. I find StringBuilder more natural because + to me are for numbers and it confuses my brain for a new nanoseconds.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there a format that we followed for such error logs?

I see this format being followed at other places where a custom message is followed by Reason: <exception message> hence extending the same here.

I vote against this messages created with String.format

Agree, in this PR I am not touching the existing formatted messages, just adding the reason part where its missing. Cleaning up all the String.format can be a separate PR altogether.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

opened an issue to discuss and finalize which option to use #14404

@gortiz
Copy link
Contributor

gortiz commented Nov 6, 2024

This may be a good temporal solution, but in general printing messages as they are is a bad practice. It can leak tons of information that shouldn't be leaked.

The ideal solution would be to have our own exception (like PinotException) with a getUserMessage() method that can be trusted. Given we are very far away from that, the solution proposed in this PR seems good enough.

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 5.55556% with 17 lines in your changes missing coverage. Please review.

Project coverage is 63.77%. Comparing base (59551e4) to head (2c5462c).
Report is 1300 commits behind head on master.

Files with missing lines Patch % Lines
...ller/api/resources/PinotSchemaRestletResource.java 0.00% 5 Missing ⚠️
...ller/api/resources/PinotTenantRestletResource.java 0.00% 4 Missing ⚠️
...ler/api/resources/TableConfigsRestletResource.java 20.00% 4 Missing ⚠️
...roller/api/resources/PinotTaskRestletResource.java 0.00% 2 Missing ⚠️
...oller/api/resources/PinotTableRestletResource.java 0.00% 1 Missing ⚠️
...ller/api/resources/PinotUpsertRestletResource.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #14395      +/-   ##
============================================
+ Coverage     61.75%   63.77%   +2.02%     
- Complexity      207     1555    +1348     
============================================
  Files          2436     2660     +224     
  Lines        133233   145982   +12749     
  Branches      20636    22356    +1720     
============================================
+ Hits          82274    93106   +10832     
- Misses        44911    45994    +1083     
- Partials       6048     6882     +834     
Flag Coverage Δ
custom-integration1 100.00% <ø> (+99.99%) ⬆️
integration 100.00% <ø> (+99.99%) ⬆️
integration1 100.00% <ø> (+99.99%) ⬆️
integration2 0.00% <ø> (ø)
java-11 63.72% <5.55%> (+2.01%) ⬆️
java-21 63.67% <5.55%> (+2.04%) ⬆️
skip-bytebuffers-false 63.77% <5.55%> (+2.02%) ⬆️
skip-bytebuffers-true 63.62% <5.55%> (+35.89%) ⬆️
temurin 63.77% <5.55%> (+2.02%) ⬆️
unittests 63.77% <5.55%> (+2.02%) ⬆️
unittests1 55.49% <ø> (+8.60%) ⬆️
unittests2 34.14% <5.55%> (+6.41%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@@ -369,8 +369,8 @@ private void persistInstancePartitionsHelper(InstancePartitions instancePartitio
InstancePartitionsUtils.persistInstancePartitions(_pinotHelixResourceManager.getPropertyStore(),
instancePartitions);
} catch (Exception e) {
throw new ControllerApplicationException(LOGGER, "Caught Exception while persisting the instance partitions",
Response.Status.INTERNAL_SERVER_ERROR, e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Why Message here vs Reason ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah good catch, will fix it!

@@ -430,8 +430,8 @@ private SuccessResponse addSchema(Schema schema, boolean override, boolean force
throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.BAD_REQUEST, e);
} catch (Exception e) {
_controllerMetrics.addMeteredGlobalValue(ControllerMeter.CONTROLLER_SCHEMA_UPLOAD_ERROR, 1L);
throw new ControllerApplicationException(LOGGER, String.format("Failed to add new schema %s.", schemaName),
Response.Status.INTERNAL_SERVER_ERROR, e);
throw new ControllerApplicationException(LOGGER, String.format("Failed to add new schema %s. Reason: %s",
Copy link
Collaborator

Choose a reason for hiding this comment

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

As a developer who learnt the trade on C using printf and snprintf, this is the most natural templatization method for me :)

It is unfortunate that the Java implementation is terrible. A benchmark that shows the terrible performance of String.format. Source: https://stackoverflow.com/a/1281651

StringBuilder or + are possible candidates. I find StringBuilder more natural because + to me are for numbers and it confuses my brain for a new nanoseconds.

@gortiz gortiz merged commit e35f43c into apache:master Nov 7, 2024
21 checks passed
davecromberge pushed a commit to davecromberge/pinot that referenced this pull request Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants