Skip to content

Conversation

@jimczi
Copy link
Contributor

@jimczi jimczi commented Oct 15, 2018

This change adds a logger for the query and fetch phases that prints all requests
before their execution at the trace level. This will help debugging cases where an issue
occurs during the execution since only completed queries are logged by the slow logs.

This query adds a logger for the query and fetch phases that prints all requests before their execution at the trace level. This will help debugging cases where an issue occurs during the execution since only completed queries are logged by the slow logs.
@jimczi jimczi added >non-issue :Search/Search Search-related issues that do not fall into other categories labels Oct 15, 2018
@jimczi jimczi requested a review from romseygeek October 15, 2018 18:29
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

Copy link
Contributor

@romseygeek romseygeek left a comment

Choose a reason for hiding this comment

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

LGTM. It would be nice to be able to associate an ID with the query to match up query and fetch phases, but I guess that can be done as part of the query body itself?

@jimczi
Copy link
Contributor Author

jimczi commented Oct 15, 2018

It would be nice to be able to associate an ID with the query to match up query and fetch phases, but I guess that can be done as part of the query body itself?

Good idea, I added the X-Opaque-Id header if it is present

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! I left a few comments on how to avoid some overhead.

*/
void execute(SearchContext context);

class SearchContextRequestLog {
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be declared as static to avoid capturing the enclosing class' state? Further looking at the usage, I wonder whether this should actually be a static method to avoid creating garbage for every query?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This declaration is within an interface so the static modifier is redundant, this is a static nested class already.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, good point. I did not check that.

@Override
public void execute(SearchContext context) {

LOGGER.trace("{}", new SearchContextRequestLog(context));
Copy link
Member

Choose a reason for hiding this comment

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

It might make sense to guard this log statement? (i.e. if LOGGER.isTraceEnabled())?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++, this will avoid the creation of a new object on each query

return;
}

LOGGER.trace("{}", new SearchContextRequestLog(searchContext));
Copy link
Member

Choose a reason for hiding this comment

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

It might make sense to guard this log statement? (i.e. if LOGGER.isTraceEnabled())?)

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

@colings86 colings86 added v6.6.0 and removed v6.5.0 labels Oct 25, 2018
Copy link
Member

@danielmitterdorfer danielmitterdorfer left a comment

Choose a reason for hiding this comment

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

Thanks for iterating. LGTM!

@jimczi jimczi merged commit 7054e28 into elastic:master Nov 9, 2018
@jimczi jimczi deleted the query_log_trace branch November 9, 2018 08:41
jimczi added a commit that referenced this pull request Nov 9, 2018
This change adds a logger for the query and fetch phases that prints all requests before their execution at the trace level. This will help debugging cases where an issue occurs during the execution since only completed queries are logged by the slow logs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Search/Search Search-related issues that do not fall into other categories v6.6.0 v7.0.0-beta1

5 participants