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

Enable toggling request logging on/off for different query types #7562

Merged
merged 6 commits into from
Aug 6, 2019

Conversation

capistrant
Copy link
Contributor

Relates to #7115 and #5320

In reference to @gianm comment in #5320: I held off on making this a more involved enhancement that would allow ignoring only internal SegmentMetadata queries as opposed to all SegmentMetadata queries because I wasn't sure of the value add from doing that versus a blanket ignore of this type. I am certainly open to revisiting that and making this more than an on/off switch. (something like druid.request.logging.logSegmentMetadataQueries with the options all, none, internal_only, external_only that then leverages the identity in the query -- defaulting to logging all SegmentMetadata queries in clusters not using security and the config is not set to none)

@stale
Copy link

stale bot commented Jun 25, 2019

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the dev@druid.apache.org list. Thank you for your contributions.

@stale stale bot added the stale label Jun 25, 2019
@stale
Copy link

stale bot commented Jul 2, 2019

This pull request/issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@stale stale bot closed this Jul 2, 2019
@capistrant
Copy link
Contributor Author

@gianm @Caroline1000 Any interest in reviving this PR to address the related issue regarding the logging here?

@Caroline1000
Copy link
Contributor

+1 for reviving. Having the all, none, internal_only, external_only options might be useful but not sure it's necessary.

@gianm gianm reopened this Jul 10, 2019
@stale
Copy link

stale bot commented Jul 10, 2019

This pull request/issue is no longer marked as stale.

@stale stale bot removed the stale label Jul 10, 2019
@gianm
Copy link
Contributor

gianm commented Jul 10, 2019

Reopened!!

@@ -316,6 +316,7 @@ All processes that can serve queries can also log the query requests they see. B
|Property|Description|Default|
|--------|-----------|-------|
|`druid.request.logging.type`|Choices: noop, file, emitter, slf4j, filtered, composing, switching. How to log every query request.|[required to configure request logging]|
| `druid.request.logging.logSegmentMetadataQueries`| Boolean indicating if SegmentMetadata Queries should be logged by the Request Logger.| true|
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the way this property behaves is good, but it would be better inside FilteredRequestLogger. That way, it's composable, rather than needing to be implemented inside each and every RequestLogger.

Copy link
Member

@leventov leventov left a comment

Choose a reason for hiding this comment

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

I think the overall approach is still unnecessarily specific. It would be more generic if a config accepts a list of query types which shouldn't be logged.


public FilteredRequestLogger(RequestLogger logger, long queryTimeThresholdMs, long sqlQueryTimeThresholdMs)
public FilteredRequestLogger(RequestLogger logger, long queryTimeThresholdMs, long sqlQueryTimeThresholdMs,
Copy link
Member

Choose a reason for hiding this comment

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

According to Druid style, should chop down the list of params:

Suggested change
public FilteredRequestLogger(RequestLogger logger, long queryTimeThresholdMs, long sqlQueryTimeThresholdMs,
public FilteredRequestLogger(
RequestLogger logger,
long queryTimeThresholdMs,
long sqlQueryTimeThresholdMs,
boolean logSegmentMetadataQueries
)
{

Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to look into using spotless as a pre-push hook so that you don't have to catch styling issues in code review. It will automatically re-format the code according to a provided style guide
https://github.com/diffplug/spotless/tree/master/plugin-maven#applying-to-java-source

(long time lurker) Sorry if this is a redundant suggestion and you already have another tool that does similar stuff

@capistrant
Copy link
Contributor Author

@leventov That sounds like a good idea to me. How would you propose handling erroneous entries by users? Hard failure, Ignore with a warning log, other?

@leventov
Copy link
Member

@leventov
Copy link
Member

However, according to the policy proposed by @drcrallen here: #8083 (comment) (and which I think is reasonable), there should be only a warning, not a hard failure.

@drcrallen
Copy link
Contributor

In line with #8083 (comment) I agree it should be a warning. If my understanding is correct, miss-configuration in such a scenario would bring the behavior closer to the "default" behavior (i.e. worst case is it is reconciled to behave no different than if it weren't configured).

@capistrant
Copy link
Contributor Author

Thanks all for the tips and info! I'll be cleaning this up this week following all the feedback

@leventov leventov changed the title Enable ability to toggle SegmentMetadata request logging on/off Enable ability to toggle request logging on/off for different query types Aug 1, 2019
@leventov leventov changed the title Enable ability to toggle request logging on/off for different query types Enable toggling request logging on/off for different query types Aug 1, 2019
@@ -379,6 +379,7 @@ For native query, only request logs where query/time is above the threshold are
|--------|-----------|-------|
|`druid.request.logging.queryTimeThresholdMs`|Threshold value for query/time in milliseconds.|0 i.e no filtering|
|`druid.request.logging.sqlQueryTimeThresholdMs`|Threshold value for sqlQuery/time in milliseconds.|0 i.e no filtering|
|`druid.request.logging.queryTypeBlacklist` | List of Druid query types to exclude from request logs. Query types are defined as string objects in the Query interface found in Query.java. Mispelled query types will be ignored. Example to ignore scan and timeBoundary queries: ["scan", "timeBoundary"]| []|
Copy link
Member

Choose a reason for hiding this comment

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

queryTypeBlacklist sounds a little intimidating. I would say "mutedQueryTypes".

Copy link
Member

Choose a reason for hiding this comment

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

I suggest the description:

```suggestion
|`druid.request.logging.mutedQueryTypes` | Query requests of these types are not logged. Query types are defined as string objects corresponding to the "queryType" value for the specified query in the Druid's [native JSON query API](http://druid.apache.org/docs/latest/querying/querying.html). Misspelled query types will be ignored. Example to ignore scan and timeBoundary queries: ["scan", "timeBoundary"]| []|

@@ -58,7 +58,8 @@
@Override
public RequestLogger get()
{
FileRequestLogger logger = new FileRequestLogger(jsonMapper, factory.create(1, "RequestLogger-%s"), dir, filePattern);
FileRequestLogger logger = new FileRequestLogger(jsonMapper, factory.create(1, "RequestLogger-%s"), dir,
filePattern);
Copy link
Member

Choose a reason for hiding this comment

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

Please chop down all arguments (each on its own line) if they don't fit a line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it. I've got to stop forgetting about that one, thanks for the comment


public FilteredRequestLogger(RequestLogger logger, long queryTimeThresholdMs, long sqlQueryTimeThresholdMs)
public FilteredRequestLogger(RequestLogger logger,
Copy link
Member

Choose a reason for hiding this comment

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

Please chop down params: #7562 (comment)

@@ -106,6 +113,10 @@ public void testNotFilterAboveThreshold() throws IOException
EasyMock.expect(nativeRequestLogLine.getQueryStats())
.andReturn(new QueryStats(ImmutableMap.of("query/time", 1000)))
.once();
EasyMock.expect(nativeRequestLogLine.getQuery())
.andReturn(new SegmentMetadataQuery(new LegacyDataSource("foo"),
Copy link
Member

Choose a reason for hiding this comment

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

Please extract new SegmentMetadataQuery(...) as a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wasn't sure if I should do one final class variable or two local variables (one per method). Went with the former, but would be easy to change to something else if my choice happens to be considered a bad pattern in Java

@@ -114,6 +125,10 @@ public void testNotFilterAboveThreshold() throws IOException
EasyMock.expect(sqlRequestLogLine.getQueryStats())
.andReturn(new QueryStats(ImmutableMap.of("sqlQuery/time", 2000)))
.once();
EasyMock.expect(sqlRequestLogLine.getQuery())
.andReturn(new SegmentMetadataQuery(new LegacyDataSource("foo"),
Copy link
Member

Choose a reason for hiding this comment

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

Same

.andReturn(new QueryStats(ImmutableMap.of("query/time", 10000)))
.once();
EasyMock.expect(nativeRequestLogLine.getQuery())
.andReturn(new SegmentMetadataQuery(new LegacyDataSource("foo"),
Copy link
Member

Choose a reason for hiding this comment

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

Same

.andReturn(new QueryStats(ImmutableMap.of("sqlQuery/time", 10000)))
.once();
EasyMock.expect(sqlRequestLogLine.getQuery())
.andReturn(new SegmentMetadataQuery(new LegacyDataSource("foo"),
Copy link
Member

Choose a reason for hiding this comment

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

Same

@capistrant
Copy link
Contributor Author

I'm not sure how to interpret the TeamCity Failure. I'm looking in the errors in the report but don't see any of the files I changed in the files listed as error.

@gianm
Copy link
Contributor

gianm commented Aug 2, 2019

I'm not sure either. I triggered the job to run again, in case it was something weird with that run.

@gianm
Copy link
Contributor

gianm commented Aug 2, 2019

If you haven't merged master into your branch recently, sometimes that helps. You could try that if TC bombs out again.

@capistrant
Copy link
Contributor Author

Thanks @gianm, restarting it seemed to do the trick 👍

FileRequestLogger logger = new FileRequestLogger(jsonMapper, factory.create(1, "RequestLogger-%s"), dir,
filePattern);
FileRequestLogger logger = new FileRequestLogger(
jsonMapper,
Copy link
Member

Choose a reason for hiding this comment

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

In Druid, the wrapping indentation is 4, not 8 spaces. Please also fix other places in this PR.

@@ -106,6 +123,9 @@ public void testNotFilterAboveThreshold() throws IOException
EasyMock.expect(nativeRequestLogLine.getQueryStats())
.andReturn(new QueryStats(ImmutableMap.of("query/time", 1000)))
.once();
EasyMock.expect(nativeRequestLogLine.getQuery())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leventov Does that wrapping indentation of 4 standard include lines such as these 3? I see that the lines above and below are had been using 8.

Copy link
Member

Choose a reason for hiding this comment

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

No. Here, the alignment is on the dot. It's a coincidence that "EasyMock" is 8 characters long.

@leventov leventov added this to the 0.16.0 milestone Aug 6, 2019
@leventov
Copy link
Member

leventov commented Aug 6, 2019

@capistrant thanks for following through!

@capistrant
Copy link
Contributor Author

@leventov Thanks for the review and guidance for this PR! I'll work to get my editor better set up to comply with Druid style rules and have some automated checks client side so there is less back and forth regarding those tedious errors in the future 👍

@Caroline1000
Copy link
Contributor

thank you @capistrant ! 🎉

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.

6 participants