-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add SQL id, request logs, and metrics #6302
Conversation
@gaodayue Is this still WIP? I see "TODO" in the description |
@gaodayue Sure, I can review, though I probably won't have time until next week |
Hi @gaodayue, in the meantime could you please check the tests and inspections? In the tests, it looks like lots of CalciteQueryTests are failing due to the new |
Thanks @gianm . I will fix all failed test cases ASAP.
That method is for custom QueryMetrics impls to add "sqlQueryId" dimension to the metrics. I add @SuppressWarnings("unused") to the signature, hope the inspection tool can understand it. |
docs/content/configuration/index.md
Outdated
@@ -347,6 +347,37 @@ Composite Request Logger emits request logs to multiple request loggers. | |||
|--------|-----------|-------| | |||
|`druid.request.logging.loggerProviders`|List of request loggers for emitting request logs.|none| | |||
|
|||
### SQL Request Logging | |||
|
|||
Brokers can be configured to log the sql request (both from HTTP and JDBC) they see. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's capitalize "sql" everywhere in the non-property parts of the docs
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
public abstract class AbstractFileRequestLogger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's necessary to split the RequestLogger implementations into native/SQL versions, it's enough that there's a new SqlRequestLogLine implementation.
If you want to have two different request loggers for SQL and native queries, I think would be better to bind the SQL provider to a different configuration parameter and inject the desired provider using annotations (maybe like how you can get a @Coordinator
DruidLeaderClient and a separate @IndexingService
instance)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gianm Do you have a strong preference on single request logger vs. separate loggers for SQL and native queries? I saw there was some discussion around that in the proposal, I'm personally fine with either approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, after thinking about it more, I think it's better to have everything go through one RequestLogger interface. Will write up the reasons why in a separate comment.
Seems like the inspection tool still complains about the unused method, could you give me some suggestions on how to handle it? |
@gaodayue maybe you can merge the master branch, it works for me. |
@gaodayue @jon-wei re: #6302 (comment), I am thinking it will be best to have a single RequestLogger interface with methods like
|
What do you think? |
Thanks @gianm. I think your arguments about single RequestLogger interface are reasonable, and I would like to give that approach a try. Sorry for the late reply. I'm currently on a vacation, so I'm not sure when can I finish refactoring this, but I'll do my best. |
Combined RequestLogger and SqlRequestLogger into one interface according to Gian's advice, the code looks a lot concise now. @gianm could your review again? |
Sync with master again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaodayue, sorry for the delay on reviewing. But thank you very much for the contribution. I left some comments just now, a couple of which are substantive (to do with the request log format and the X-Druid-Native-Query-Ids
header). Let us know what you think.
And /cc @jon-wei, could you please take a look at the security checks in SqlLifecycle?
@@ -58,10 +78,12 @@ public String getLine(ObjectMapper objectMapper) throws JsonProcessingException | |||
); | |||
} | |||
|
|||
@JsonProperty("timestamp") | |||
public DateTime getTimestamp() | |||
public String getSqlQueryLine(ObjectMapper objectMapper) throws JsonProcessingException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This format should be documented, but also, IMO, adjusted. Firstly, it should be on one line (this makes it easier to parse); secondly, it should be the same rough format as getNativeQueryLine (so the same parser can handle both). That means a TSV. How about doing:
return JOINER.join(
Arrays.asList(
timestamp,
remoteAddr,
objectMapper.writeValueAsString(ImmutableMap.of("queryType", "sql", "sql", sql)),
objectMapper.writeValueAsString(queryStats)
)
);
It's sort of using a fake queryType of 'sql', which is a little weird, but makes parsing pretty easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, this:
return JOINER.join(
Arrays.asList(
timestamp,
remoteAddr,
"",
objectMapper.writeValueAsString(queryStats),
objectMapper.writeValueAsString(ImmutableMap.of("sql", sql))
)
);
It leaves the native-query field blank, and adds a new field on the end of the TSV for sql query. It uses a JSON object rather than emitting the SQL as-is for two reasons: (1) we can extend with more info later if we want; (2) the SQL query might have newlines and such in it, and the objectMapper.writeValueAsString
will get rid of those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the format should be documented and easy to parse. Considering the two approaches, I'm in favor of the latter one because it makes it clear that SQL query is different from native query (e.g., it doesn't have queryType
). But I also want to tweak it into
return JOINER.join(
Arrays.asList(
timestamp,
remoteAddr,
"",
objectMapper.writeValueAsString(queryStats),
objectMapper.writeValueAsString(ImmutableMap.of("query", sql, "context", sqlQueryContext))
)
);
It uses the field naming of SqlQuery but only includes query
and context
fields which apply to both http and jdbc scenario. Please let me know your opinions :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that format you suggested, +1 from me.
sql/src/main/java/org/apache/druid/sql/calcite/view/DruidViewMacro.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed the auth-related changes, those lgtm, had a couple of other small comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please merge from master and then this LGTM.
Merged with master. The reported inspection errors don't look like a problem to me. |
@gaodayue thanks for merging with master. We'll need to fix the inspection report since otherwise it will start failing for master as well. Could you look into it? There are three I see:
It's an extension point, not meant to be used by Druid production code. Annotating it with
I think doing (1) should fix this too.
This looks like a bug in the inspection. It looks like RequestLogLineConsumer declares |
Hmm, the first thing is fixed, but TC is still complaining about the redundant "throws" that is not actually redundant. I'm not sure how to fix this. I tried downloading the latest IntelliJ (2018.3.2) and my IDE does not flag this line as a redundant throw. In fact, it flags the @gaodayue, sorry, but can you try one more thing: change If making that change does not silence the inspection, my suggestion would be to remove the RedundantThrows check from /cc @leventov, any other ideas what might be going on? |
…mposingRequestLoggerProvider
That seemed to work! |
@jon-wei any further comments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@gianm please raise an issue in IntelliJ's YouTrack. Ideally a link to the issue should be in a comment next to suppression, so that people could know when the suppression could be removed. See |
I've raised this issue: https://youtrack.jetbrains.com/issue/IDEA-205535 |
Fixed #6301
This PR adds a new
sqlQueryId
method to theQueryMetrics
interface, which should be noted in the release notes.