util/tracing,sql: add builtin to set trace spans' verbosity#61353
util/tracing,sql: add builtin to set trace spans' verbosity#61353craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
314412d to
0ff746d
Compare
erikgrinaker
left a comment
There was a problem hiding this comment.
Reviewed 6 of 7 files at r1.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @angelapwen, @irfansharif, @knz, and @tbg)
pkg/sql/tests/tracing_sql_test.go, line 38 at r1 (raw file):
Quoted 5 lines of code…
r.Exec( t, "SELECT * FROM crdb_internal.set_verbosity_of_root_span_and_descendants($1, true)", rootID, )
It would be nice to check the return value here, both for a hit and a miss (we sort of do this in the SQL logic test, but only for the negative case).
0ff746d to
eb11088
Compare
|
pkg/sql/tests/tracing_sql_test.go, line 38 at r1 (raw file): Previously, erikgrinaker (Erik Grinaker) wrote…
Done. Thanks for the suggestion! It looked like |
eb11088 to
3ee0d2d
Compare
erikgrinaker
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @angelapwen, @irfansharif, @knz, and @tbg)
pkg/sql/tests/tracing_sql_test.go, line 38 at r1 (raw file):
Previously, angelapwen (Angela P Wen) wrote…
Done. Thanks for the suggestion! It looked like
SQLRunner.Execdidn't surface the right return value (justLastInsertIdandRowsAffected) so played around withSQLRunner.CheckQueryResultswhich does what we want! 😺
Awesome, thanks!
26b6e18 to
1e3e468
Compare
irfansharif
left a comment
There was a problem hiding this comment.
Reviewed 1 of 5 files at r2.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @angelapwen, @erikgrinaker, @knz, and @tbg)
pkg/sql/sem/builtins/builtins.go, line 3638 at r2 (raw file):
), // TODO(angelapwen): Does it make more sense for this builtin to take a trace ID?
It does, and we should do it. It avoids the UX clarification we're making here around asking the user to specify the root span ID rather than a span ID. The mapping from a trace ID to span ID is a bit manual, and the DB is well suited to do it directly. Especially given the vtable schema associates a trace ID per span. The way we have it now, we're asking the user to walk up the list of parent span IDs to get to the root, which is unnecessary.
pkg/sql/sem/builtins/builtins.go, line 3647 at r2 (raw file):
{"verbosity", types.Bool}, }, ReturnType: tree.FixedReturnType(types.Bool),
Is an erroneous call (for a missing span/trace) best represented by a false return? Can we not do better for built ins? (like, erroring out informatively?)
pkg/util/tracing/tracer.go, line 670 at r2 (raw file):
func (t *Tracer) setAllChildrenSpanVerbosity(rootCrdbSpan *crdbSpan, to bool) { // TODO(angelapwen): Do we need to check that root is not a noop the way we do in `SetVerbose`? for _, child := range rootCrdbSpan.mu.recording.children {
We're not grabbing the right locks here; this is unsafe (for when children are added and removed from the parent span's list).
1e3e468 to
002b1a1
Compare
angelapwen
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @angelapwen, @erikgrinaker, @irfansharif, @knz, and @tbg)
pkg/sql/sem/builtins/builtins.go, line 3638 at r2 (raw file):
Previously, irfansharif (irfan sharif) wrote…
It does, and we should do it. It avoids the UX clarification we're making here around asking the user to specify the root span ID rather than a span ID. The mapping from a trace ID to span ID is a bit manual, and the DB is well suited to do it directly. Especially given the vtable schema associates a trace ID per span. The way we have it now, we're asking the user to walk up the list of parent span IDs to get to the root, which is unnecessary.
👍 that makes sense. I'll use this PR as a starting point and modify to take in a trace ID.
I'm thinking about how I would surface a particular trace ID via the test, to pass it in. Perhaps using the crdb_internal.trace_id builtin would surface the correct trace, but I'm not 100% sure on that.
pkg/sql/sem/builtins/builtins.go, line 3647 at r2 (raw file):
Previously, irfansharif (irfan sharif) wrote…
Is an erroneous call (for a missing span/trace) best represented by a false return? Can we not do better for built ins? (like, erroring out informatively?)
Yes, we can throw a pgerror. I remembered though that @knz mentioned in the trace_id builtin PR that when there was no active trace span, we should return null instead of throwing an error so the transaction could continue link to comment and so I thought this would be the equivalent.
It is a bit more confusing as the return value is a boolean, so I cannot return null (only true or false) — I meant the boolean to represent "success" which I believe is a common pattern.
pkg/util/tracing/tracer.go, line 670 at r2 (raw file):
Previously, irfansharif (irfan sharif) wrote…
We're not grabbing the right locks here; this is unsafe (for when children are added and removed from the parent span's list).
Done, thanks for catching this!
002b1a1 to
4f478cc
Compare
angelapwen
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @angelapwen, @erikgrinaker, @irfansharif, @knz, and @tbg)
pkg/sql/sem/builtins/builtins.go, line 3638 at r2 (raw file):
Previously, angelapwen (Angela P Wen) wrote…
👍 that makes sense. I'll use this PR as a starting point and modify to take in a trace ID.
I'm thinking about how I would surface a particular trace ID via the test, to pass it in. Perhaps using the
crdb_internal.trace_idbuiltin would surface the correct trace, but I'm not 100% sure on that.
Done. The builtin now takes a trace ID and queries for the root span ID internally.
pkg/util/tracing/tracer.go, line 670 at r2 (raw file):
Previously, angelapwen (Angela P Wen) wrote…
Done, thanks for catching this!
I just realized that adding the locks here resulted in deadlock because child.enableRecording also calls parent.addChild which acquires the lock on the parent span, and that's the span that's locked here.
I don't think we can lock the parent here as is considering we are doing two conflicting things: iterating through its children list and in each iteration, potentially adding a child to the children list.
(As a side note, is there something wrong with the logic here? It seems that for every child in the children list, we are calling enableRecording with a non-nil parent, and the child is redundantly appended to the parent's children list. I think I need to add a check here that only calls enableRecording when verbosity was false originally, and only calls disableRecording() if it was originally true.
4f478cc to
edf0b5d
Compare
|
pkg/util/tracing/tracer.go, line 670 at r2 (raw file): Previously, angelapwen (Angela P Wen) wrote…
Ok, I think I have worked this out now — indeed because the child is already recorded as part of this parent, we should pass in |
856cd02 to
12ae9f3
Compare
8045dc3 to
a640ce1
Compare
a640ce1 to
1778358
Compare
|
pkg/util/tracing/tracer.go, line 669 at r2 (raw file):
I convinced myself that we do not need to check whether the root or the children On the other hand, there is a concern around whether the real root span (passed into the |
1778358 to
2f7c05a
Compare
6a97c1a to
31f0227
Compare
irfansharif
left a comment
There was a problem hiding this comment.
LGTM, though I think you'll need a @tbg stamp given we're in stability.
Previously there was no way to change a span's verbosity via the SQL shell. We want to be able to set a specific long-running span's verbosity on to retrieve its recordings. This patch adds a builtin, `crdb_internal.set_trace_verbose` that takes in a trace ID and a bool representing verbose or not verbose. It sets the verbosity of all spans in this trace. Note that we would prefer to toggle individual span verbosity, but this would require a registry of Span objects that is not added to the 21.1 release. If this Span registry were added in the future, we could access a Span given its span ID. Release justification: Adds a crdb_internal tool meant for on-call engineers, TSEs, etc to debug. Release note (sql change): Adds a new builtin that sets the verbosity of all spans in a given trace. Syntax: crdb_internal.set_trace_verbose($traceID,$verbosityAsBool).
31f0227 to
d4f9b02
Compare
|
bors r=irfansharif,erikgrinaker |
|
@angelapwen, because of the new span inner file, this will merge conflict with #61359. I'd recommend rebasing on top of that, or just waiting for that to merge first. Otherwise the entire batch will get cancelled. You'll hate me for this, but I'll cancel the bors batch for now. bors r- |
|
Canceled. |
|
(to make up for it I'm happy to rebase it forward for you - enjoy your weekend!) |
|
@irfansharif Hahaha — I'm happy to rebase it when the other PR has merged tomorrow too. Thanks for the head's up 😸 |
|
(you should be good to go) |
|
bors r=irfansharif,erikgrinaker |
|
Build succeeded: |
Resolves #61180.
Previously there was no way to change a span's verbosity via the
SQL shell. We want to be able to set a specific long-running
span's verbosity on to retrieve its recordings. This patch adds a
builtin,
crdb_internal.set_trace_verbosethat takes in atrace ID and a bool representing verbose or not
verbose. It sets the verbosity of all spans in this trace.
Note that we would prefer to toggle individual span verbosity,
but this would require a registry of Span objects that
is not added to the 21.1 release. If this Span registry were added
in the future, we could access a Span given its span ID.
Release justification: Adds a crdb_internal tool meant for on-call
engineers, TSEs, etc to debug.
Release note (sql change): Adds a new builtin that sets the verbosity
of all spans in a given trace. Syntax:
crdb_internal.set_trace_verbose($traceID,$verbosityAsBool).