contrib/database/sql: properly annotate DB operations with execution trace tasks#2060
Merged
Merged
Conversation
BenchmarksBenchmark execution time: 2023-06-26 12:38:46 Comparing candidate commit 57fe40d in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 24 metrics, 0 unstable metrics. |
nsrip-dd
force-pushed
the
nick.ripley/fix-sql-span-trace-coverage
branch
from
June 21, 2023 17:52
ee66e21 to
8f30854
Compare
…tion trace tasks After #336, spans for database operations are created *after* the operation. This is necessary because some operations may return ErrSkip if they aren't supported, and creating spans with those errors is very noisy. But because of this, execution trace tasks associated with those spans would appear to be only a few microseconds long since they are created alongside the span and thus only cover the very end of the operation. This commit creates execution trace tasks (if the execution tracer is enabled) before the operations, and provides a way of communicating to the APM tracer that it doesn't need to create a task for the span. The APM tracer will still annotate the task with the span ID even if a task was already created. Still TODO: add tests
nsrip-dd
force-pushed
the
nick.ripley/fix-sql-span-trace-coverage
branch
from
June 21, 2023 18:31
8f30854 to
509dc34
Compare
We test that a few spans show up as execution trace tasks, and have the correct annotations.
This doesn't cover absolutely everything, but it is better.
ajgajg1134
requested changes
Jun 23, 2023
ajgajg1134
left a comment
Contributor
There was a problem hiding this comment.
Overall looks good to me, it definitely adds a bit of complication to the database/sql contrib code, but unfortunately I can't see a better way to deal with the driver.ErrSkip business that causes this contrib to be so complicated.
nsrip-dd
commented
Jun 23, 2023
nsrip-dd
left a comment
Contributor
Author
There was a problem hiding this comment.
Thanks for the review Andrew!
2 tasks
nsrip-dd
added a commit
that referenced
this pull request
Jun 26, 2023
Missed in #2060 after adding a new dependency.
Merged
nsrip-dd
added a commit
that referenced
this pull request
Jun 26, 2023
Missed in #2060 after adding a new dependency
3 tasks
nsrip-dd
added a commit
that referenced
this pull request
Aug 14, 2023
The context used to prepare a statement and the context used to execute a statement need not be the same (see https://pkg.go.dev/database/sql#DB.PrepareContext) The execution trace task changes added in #2060 incorrectly used the statement's context from preparation to derive the execution trace task. We should be using the context provided for executing the statement instead. Fixes #2172
nsrip-dd
added a commit
that referenced
this pull request
Aug 14, 2023
…ts (#2173) The context used to prepare a statement and the context used to execute a statement need not be the same (see https://pkg.go.dev/database/sql#DB.PrepareContext) The execution trace task changes added in #2060 incorrectly used the statement's context from preparation to derive the execution trace task. We should be using the context provided for executing the statement instead. Fixes #2172
ajgajg1134
pushed a commit
that referenced
this pull request
Sep 5, 2023
…ts (#2173) The context used to prepare a statement and the context used to execute a statement need not be the same (see https://pkg.go.dev/database/sql#DB.PrepareContext) The execution trace task changes added in #2060 incorrectly used the statement's context from preparation to derive the execution trace task. We should be using the context provided for executing the statement instead. Fixes #2172
5 tasks
nsrip-dd
added a commit
that referenced
this pull request
Jul 16, 2024
Port the contrib/database/sql execution tracer test to use the new golang.org/x/exp/trace parser. The test is slightly cleaned up, but for the most part covers the same logic as its predecessor (see #2060). The primary difference is that, rather than hooking into a mock database/sql driver, we use a real one (sqlite3). To simulate a slow operation, the test registers a sleep function and also sleeps on connection. The purpose of this is to ensure, where we can, the tracer tasks cover the whole operation and not just the end of it. We no longer hook into _every_ operation, though, so we drop some time assertions.
6 tasks
nsrip-dd
added a commit
that referenced
this pull request
Jul 16, 2024
Port the contrib/database/sql execution tracer test to use the new golang.org/x/exp/trace parser. The test is slightly cleaned up, but for the most part covers the same logic as its predecessor (see #2060). The primary difference is that, rather than hooking into a mock database/sql driver, we use a real one (sqlite3). To simulate a slow operation, the test registers a sleep function and also sleeps on connection. The purpose of this is to ensure, where we can, the tracer tasks cover the whole operation and not just the end of it. We no longer hook into _every_ operation, though, so we drop some time assertions.
nsrip-dd
added a commit
that referenced
this pull request
Jul 17, 2024
Port the contrib/database/sql execution tracer test to use the new golang.org/x/exp/trace parser. The test is slightly cleaned up, but for the most part covers the same logic as its predecessor (see #2060). The primary difference is that, rather than hooking into a mock database/sql driver, we use a real one (sqlite3). To simulate a slow operation, the test registers a sleep function and also sleeps on connection. The purpose of this is to ensure, where we can, the tracer tasks cover the whole operation and not just the end of it. We no longer hook into _every_ operation, though, so we drop some time assertions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR creates execution trace tasks (if the execution tracer is enabled)
before the operations, and provides a way of communicating to the APM tracer
that it doesn't need to create a task for the span. The APM tracer will still
annotate the task with the span ID even if a task was already created.
Motivation
After #336, spans for database operations are created after the operation.
This is necessary because some operations may return ErrSkip if they aren't
supported, and creating spans with those errors is very noisy. But because of
this, execution trace tasks associated with those spans would appear to be only
a few microseconds long since they are created alongside the span and thus only
cover the very end of the operation.
Describe how to test/QA your changes
This PR adds a unit test which checks that spans get associated tasks with
a realistic duration.
I've tested this locally using a simple program which connects to Postgres and
pg_sleeps:
Before:
After:
Reviewer's Checklist