-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util/tracing,sql: add builtin to set trace spans' verbosity
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).
- Loading branch information
angelapwen
committed
Mar 5, 2021
1 parent
9ccda03
commit d4f9b02
Showing
9 changed files
with
456 additions
and
229 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package tests | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/tracing" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSetTraceSpansVerbosityBuiltin(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{}) | ||
defer s.Stopper().Stop(context.Background()) | ||
r := sqlutils.MakeSQLRunner(db) | ||
|
||
tr := s.Tracer().(*tracing.Tracer) | ||
|
||
// Try to toggle the verbosity of a trace that doesn't exist, returns false. | ||
// NB: Technically this could return true in the unlikely scenario that there | ||
// is a trace with ID of 0. | ||
r.CheckQueryResults( | ||
t, | ||
"SELECT * FROM crdb_internal.set_trace_verbose(0, true)", | ||
[][]string{{`false`}}, | ||
) | ||
|
||
root := tr.StartSpan("root", tracing.WithForceRealSpan()) | ||
defer root.Finish() | ||
require.False(t, root.IsVerbose()) | ||
|
||
child := tr.StartSpan("root.child", tracing.WithParentAndAutoCollection(root)) | ||
defer child.Finish() | ||
require.False(t, child.IsVerbose()) | ||
|
||
childChild := tr.StartSpan("root.child.child", tracing.WithParentAndAutoCollection(child)) | ||
defer childChild.Finish() | ||
require.False(t, childChild.IsVerbose()) | ||
|
||
// Toggle the trace's verbosity and confirm all spans are verbose. | ||
traceID := root.TraceID() | ||
query := fmt.Sprintf( | ||
"SELECT * FROM crdb_internal.set_trace_verbose(%d, true)", | ||
traceID, | ||
) | ||
r.CheckQueryResults( | ||
t, | ||
query, | ||
[][]string{{`true`}}, | ||
) | ||
|
||
require.True(t, root.IsVerbose()) | ||
require.True(t, child.IsVerbose()) | ||
require.True(t, childChild.IsVerbose()) | ||
|
||
// New child of verbose child span should also be verbose by default. | ||
childNewChild := tr.StartSpan("root.child.newchild", tracing.WithParentAndAutoCollection(child)) | ||
defer childNewChild.Finish() | ||
require.True(t, childNewChild.IsVerbose()) | ||
|
||
// Toggle the trace's verbosity and confirm none of the spans are verbose. | ||
query = fmt.Sprintf( | ||
"SELECT * FROM crdb_internal.set_trace_verbose(%d, false)", | ||
traceID, | ||
) | ||
r.CheckQueryResults( | ||
t, | ||
query, | ||
[][]string{{`true`}}, | ||
) | ||
|
||
require.False(t, root.IsVerbose()) | ||
require.False(t, child.IsVerbose()) | ||
require.False(t, childChild.IsVerbose()) | ||
require.False(t, childNewChild.IsVerbose()) | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.