-
Notifications
You must be signed in to change notification settings - Fork 2k
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 query logging #19516
add query logging #19516
Conversation
Thank you for your contribution Blackbaud-MikeLueders! We will review the pull request and get back to you soon. |
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.
Thank you @Blackbaud-EricSlater for your contribution.
@kushagraThapar FYI
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/SqlQuerySpecLogger.java
Outdated
Show resolved
Hide resolved
@@ -737,6 +738,8 @@ private String parentResourceLinkToQueryLink(String parentResourceLink, Resource | |||
IDocumentQueryClient queryClient, | |||
UUID activityId) { | |||
|
|||
SqlQuerySpecLogger.getInstance().logQuery(sqlQuery); |
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.
@mbhaskar is this the right place?
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.
queryDocuments
would be a better place IMHO if all we want is to log the document/item queries.
Line 2204 in e01f66b
public Flux<FeedResponse<Document>> queryDocuments(String collectionLink, SqlQuerySpec querySpec, |
Placing logging in createQueryInternal
would log various other queries including databases/collections etc, which may not be the intention here.
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.
makes sense, moved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/SqlQuerySpecLogger.java
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/SqlQuerySpecLogger.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.
Thanks for your contribution @Blackbaud-MikeLueders .
So far the reason we have not implemented query logging is because of privacy concerns for customer data.
We have heard from some customers, that their logs can be accessed by anyone (someone with not a lot of permissions), so we are reluctant to put these queries in logs.
But if the SDK team agrees to have logging for queries, we can proceed with this change. @moderakh @FabianMeiswinkel @mbhaskar @simplynaveen20 @kirankumarkolli
Also, please add a couple of test cases for this, so as to know what to expect in the logs.
And the public class surface change that I mentioned in the code review comment.
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/SqlQuerySpecLogger.java
Outdated
Show resolved
Hide resolved
This pull request is protected by Check Enforcer. What is Check Enforcer?Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass. Why am I getting this message?You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged. What should I do now?If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows: What if I am onboarding a new service?Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment: |
@kushagraThapar I don't understand the privacy concern issue. The query will only be logged if the And if they did, they would already be logging the query. If
So any motivated person can already see the complete query, including the parameters (at INFO, which is higher than DEBUG/TRACE). But TBH, this wouldn't even be my main concern if I thought organizations were enabling
|
@Blackbaud-MikeLueders - Its not about enabling logging at |
I should clarify, I don't think it's wrong to have those logs in the first place (although they do seem to be at the wrong level, I would suggest |
e73829b
to
8dc29ea
Compare
@kushagraThapar rebased and pushed, thanks for getting this in! |
Seems like some of the unit tests you have added are failing, can you please fix those. |
@kushagraThapar whoops, forgot to include the group in the @BeforeMethod annotation, fixed now. it looks like the check-enforcer has been running for over 21 hours, it might need to be kicked. |
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.
@@ -0,0 +1,95 @@ | |||
package com.azure.cosmos.implementation; |
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.
header is missing.
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.
added header
Two suggestions:
|
.append(" > param: ") | ||
.append(p.getName()) | ||
.append(" = ") | ||
.append(p.getValue(Object.class)) |
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.
also it would be good if we only log the query text not the parameter values.
why would you need parameter values to be logged?
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.
Partly because I was patterning it after hibernate logging
org.hibernate.SQL=debug logs the query
org.hibernate.type=trace logs the bound parameters
And party because they can be extremely useful when tracking down a misbehaving query or stored procedure.
it's worth nothing that spring-data-mongo also supports logging query parameters
org.springframework.data.mongodb.core.MongoTemplate=DEBUG
@mbhaskar I moved the statement to Re: a config option, could you help me understand what that accomplishes? Logging frameworks exist in order to solve this exact problem - to be able to change the output based on desired levels. Someone would have to specifically enable com.azure.cosmos.implementation.SqlQuerySpecLogger=TRACE in order to see the query params (DEBUG shows them the query, TRACE shows them the query + parameters). No other datasource integration that I'm aware of has a separate configuration option (outside of setting different logging levels) for query parameters. Also, as previously noted, query parameters are already being logged at a much higher level (INFO) in |
…ySpecLogger.java Co-authored-by: Mohammad Derakhshani <[email protected]>
6e50cf5
to
1c53e0f
Compare
it looks like this PR #19536 broke the analysis stage, let me know if i need to rebase once it's resolved. |
looking into this failure, will update once this is 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.
Thank you @Blackbaud-MikeLueders for your contribution and iterating on this.
Hello, thanks for your work. It helps a lot. Few remarks: I see 3 different type of logs, could you make it more consistent? Thanks.
Where parameter name is concat from actual paramName and some UUID ?!? Unfortunatelly, I could not find any select query which would cause it. Could it be some automatic pre-load before save operation?
as a result of this query
as a result of
here, it would be great if possible, to log target container/table. Instead of ROOT r log something like ContainerName r |
I'm not sure if this is the right place - it seems to log all the queries I'd be interested in but I'm open to suggestions if there's a better place for it.
fixes #18639