-
Notifications
You must be signed in to change notification settings - Fork 59
[PECOBLR-1383] Add statement execution hooks for telemetry collection #321
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
Changes from 2 commits
8fe174d
0af46e7
4e38383
746974e
a027510
bae0836
3cbc0ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,6 +127,21 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name | |
| log, ctx = client.LoggerAndContext(ctx, exStmtResp) | ||
| stagingErr := c.execStagingOperation(exStmtResp, ctx) | ||
|
|
||
| // Telemetry: track statement execution | ||
| var statementID string | ||
| if c.telemetry != nil && exStmtResp != nil && exStmtResp.OperationHandle != nil && exStmtResp.OperationHandle.OperationId != nil { | ||
| statementID = client.SprintGuid(exStmtResp.OperationHandle.OperationId.GUID) | ||
| ctx = c.telemetry.BeforeExecute(ctx, statementID) | ||
| defer func() { | ||
| finalErr := err | ||
| if stagingErr != nil { | ||
| finalErr = stagingErr | ||
| } | ||
| c.telemetry.AfterExecute(ctx, finalErr) | ||
| c.telemetry.CompleteStatement(ctx, statementID, finalErr != nil) | ||
| }() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the CloseOperation call fails below, that error is logged but never reflected in telemetry so we're missing capturing some errors in telemetry. Not sure if that's intended?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, fixing this. |
||
| } | ||
|
|
||
| if exStmtResp != nil && exStmtResp.OperationHandle != nil { | ||
| // since we have an operation handle we can close the operation if necessary | ||
| alreadyClosed := exStmtResp.DirectResults != nil && exStmtResp.DirectResults.CloseOperation != nil | ||
|
|
@@ -172,6 +187,17 @@ func (c *conn) QueryContext(ctx context.Context, query string, args []driver.Nam | |
| log, ctx = client.LoggerAndContext(ctx, exStmtResp) | ||
| defer log.Duration(msg, start) | ||
|
|
||
| // Telemetry: track statement execution | ||
| var statementID string | ||
| if c.telemetry != nil && exStmtResp != nil && exStmtResp.OperationHandle != nil && exStmtResp.OperationHandle.OperationId != nil { | ||
| statementID = client.SprintGuid(exStmtResp.OperationHandle.OperationId.GUID) | ||
| ctx = c.telemetry.BeforeExecute(ctx, statementID) | ||
|
samikshya-db marked this conversation as resolved.
Outdated
|
||
| defer func() { | ||
| c.telemetry.AfterExecute(ctx, err) | ||
| c.telemetry.CompleteStatement(ctx, statementID, err != nil) | ||
| }() | ||
| } | ||
|
|
||
| if err != nil { | ||
| log.Err(err).Msg("databricks: failed to run query") // To log query we need to redact credentials | ||
| return nil, dbsqlerrint.NewExecutionError(ctx, dbsqlerr.ErrQueryExecution, err, opStatusResp) | ||
|
|
||
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.
shouldn't this be before runQuery?
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.
we should write some correctness tests. how do we know the values telemetry is sending are even correct (so that we avoid bugs like these)
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 the review @vikrantpuppala
The follow up PR #322 already covers a lot of mock based tests on telemetry. And, it also addresses the runQuery issue in
QueryContext, I will add more of these correctness tests in #322 PR.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.
can we fix the fact that ctx = c.telemetry.BeforeExecute(ctx, statementID) needs to be called before runQuery?
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.
Accidentally deleted my previous comment inplace of editing it :
Both ExecContext and QueryContext now capture the complete query execution time in telemetry
for both PRs.