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

ResponseException stores the JSON sent to Druid. #70

Merged
merged 1 commit into from
Oct 24, 2016

Conversation

archolewa
Copy link
Contributor

-- DruidAggregationQuery does not have toString defined.
Furthermore, it would be non-trivial to define a toString that
serializes the query into the actual query sent to Druid (we would need
to inject a ObjectMapper from the ObjectMapperSuite into the
aggregation query). Therefore, the ResponseException now takes an
ObjectWriter that can be used to serialize the druid query that is
logged.

Copy link
Collaborator

@cdeszaq cdeszaq left a comment

Choose a reason for hiding this comment

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

Doesn't look too bad, just 1 main concern really.

@@ -37,6 +45,29 @@ public ResponseException(Response.StatusType statusType, DruidAggregationQuery<?
}

/**
* Class constructor with throwable, other parameters and a mapper for serializing the druid query.
* @param statusType Status type of the response
Copy link
Collaborator

Choose a reason for hiding this comment

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

Space needed

@@ -64,7 +95,29 @@ public ResponseException(
DruidQuery<?> druidQuery,
Throwable cause
) {
super(buildMessage(reason, description, statusCode, druidQuery, cause));
this(statusCode, reason, description, druidQuery, cause, new ObjectMapper().writer());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should deprecate this constructor, since creating a new "naked" mapper w/o the extensions we have on the primary ones will result in a funky serialization.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And by that token, probably deprecate other constructors to this thing that don't take in the writer they'll need as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, and also not increase the number of deprecation warnings the compiler throws at us if we can 😉

Copy link
Collaborator

@cdeszaq cdeszaq left a comment

Choose a reason for hiding this comment

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

Looks good other than flipping those 2 lines. 👍

druidQueryString = objectWriter.writeValueAsString(druidQuery);
} catch (JsonProcessingException e) {
druidQueryString = druidQuery.toString();
LOG.warn(String.format("Failed to properly serialize druid query %s", druidQueryString), e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Flip these. Otherwise, if the toString() blows up, we never see the next log message

Copy link
Contributor Author

@archolewa archolewa Oct 21, 2016

Choose a reason for hiding this comment

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

If I do that, then the best we can say is "Failed to properly serialize a druid query." without any sort of string representation. Which admittedly isn't going to be that different from what will be displayed now, since we don't override toString.

Copy link
Collaborator

@cdeszaq cdeszaq Oct 24, 2016

Choose a reason for hiding this comment

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

Ah, makes sense. With that in mind, you can actually just in-line druidQuery in the LOG call, and let the logging framework call toString if it decides it needs to actually log it.

@archolewa archolewa force-pushed the actually-log-druid-query branch 2 times, most recently from 1bf0d94 to 95f4dea Compare October 24, 2016 18:15
Copy link
Collaborator

@cdeszaq cdeszaq left a comment

Choose a reason for hiding this comment

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

👍 Looks good. Just remember to squash before merge once this has it's 2 +1s

@DennisMcWherter
Copy link
Contributor

👍

-- `DruidAggregationQuery` does not have `toString` defined.
Furthermore, it would be non-trivial to define a `toString` that
serializes the query into the actual query sent to Druid (we would need
to inject a `ObjectMapper` from the `ObjectMapperSuite` into the
aggregation query). Therefore, the `ResponseException` now takes an
`ObjectWriter` that can be used to serialize the druid query that is
logged.
@archolewa archolewa force-pushed the actually-log-druid-query branch from 95f4dea to aac87bc Compare October 24, 2016 19:13
@archolewa archolewa merged commit 695a83f into master Oct 24, 2016
@archolewa archolewa deleted the actually-log-druid-query branch October 24, 2016 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants