-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
cli: provide auto_trace
as replacement to SHOW TRACE FOR <stmt>
#27805
Merged
Conversation
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
The SHOW TRACE FOR <stmt> syntax form was removed from CockroachDB SQL because it was hard to implement correctly server-side. However this does not mean that the need for it did not exist. Folk were moderately unhappy to lose a feature that was exploited productively during performance analysis and general troubleshooting. To respond to the need, this patch instead provides a feature in `cockroach sql` that replaces the previous SHOW TRACE FOR <stmt> syntax. For example: ``` > \set auto_trace on > SELECT 1 +----------+ | ?column? | +----------+ | 1 | +----------+ (1 row) Time: 327.38µs +----------------------------------+------------+------------------------------------------------------------------+---------------------------------------+----------+-------------------+------+ | timestamp | age | message | tag | location | operation | span | +----------------------------------+------------+------------------------------------------------------------------+---------------------------------------+----------+-------------------+------+ | 2018-07-20 15:25:29.09039+00:00 | 0s | === SPAN START: session recording === | | | session recording | 0 | | 2018-07-20 15:25:29.09041+00:00 | 19µs997ns | [NoTxn pos:22] executing Sync | [n1,client=127.0.0.1:16847,user=root] | | session recording | 0 | | 2018-07-20 15:25:29.09048+00:00 | 89µs917ns | [NoTxn pos:23] executing ExecStmt: SELECT 1 | [n1,client=127.0.0.1:16847,user=root] | | session recording | 0 | [...] +----------------------------------+------------+------------------------------------------------------------------+---------------------------------------+----------+-------------------+------+ (22 rows) Time: 1.836533ms ``` That is, for every statement executed, the shell also produces the trace for that statement in a separate result below. A trace is also produced in case the statement produces a SQL error. It works as follows: - a new client-side option `auto_trace` is provided (configurable with `\set`). - when set to non-off, it causes every subsequent statement to be enclosed in: - `SET tracing = off; SET tracing = on, <options...>` at the beginning where `<options...>` is the content of the variable `auto_trace`. - `SET tracing = off; SHOW <option> TRACE FOR SESSION` at the end, where `<option>` is either empty or `kv` if `auto_trace` contains `kv`. Release note (cli change): A new client-side option `auto_trace` is provided to facilitate usage of session tracing.
cc @tschottdorf you may have an opinion on the usability |
LGTM. This makes me wonder whether we should also add a non-"auto" version of this, e.g. |
@jordanlewis that was my first idea but the architecture of our CLI does not allow this without a major rewrite. So no (not yet). |
TFYR bors r+ |
craig bot
pushed a commit
that referenced
this pull request
Jul 20, 2018
27802: distsqlrun: plumb kv tracing into distsql r=jordanlewis a=jordanlewis Previously, kv tracing only worked in local SQL. Now, FlowSetupRequest and FlowCtx are augmented with traceKV flags, so DistSQL can get in on the fun as well. Release note (sql change): kv traces (SHOW KV TRACE FOR SESSION) now work for distsql-executed queries as well. 27805: cli: provide `auto_trace` as replacement to SHOW TRACE FOR <stmt> r=knz a=knz The SHOW TRACE FOR <stmt> syntax form was removed from CockroachDB SQL because it was hard to implement correctly server-side. However this does not mean that the need for it did not exist. Folk were moderately unhappy to lose a feature that was exploited productively during performance analysis and general troubleshooting. To respond to the need, this patch instead provides a feature in `cockroach sql` that replaces the previous SHOW TRACE FOR <stmt> syntax. For example: ``` > \set auto_trace on > SELECT 1 +----------+ | ?column? | +----------+ | 1 | +----------+ (1 row) Time: 327.38µs +----------------------------------+------------+------------------------------------------------------------------+---------------------------------------+----------+-------------------+------+ | timestamp | age | message | tag | location | operation | span | +----------------------------------+------------+------------------------------------------------------------------+---------------------------------------+----------+-------------------+------+ | 2018-07-20 15:25:29.09039+00:00 | 0s | === SPAN START: session recording === | | | session recording | 0 | | 2018-07-20 15:25:29.09041+00:00 | 19µs997ns | [NoTxn pos:22] executing Sync | [n1,client=127.0.0.1:16847,user=root] | | session recording | 0 | | 2018-07-20 15:25:29.09048+00:00 | 89µs917ns | [NoTxn pos:23] executing ExecStmt: SELECT 1 | [n1,client=127.0.0.1:16847,user=root] | | session recording | 0 | [...] +----------------------------------+------------+------------------------------------------------------------------+---------------------------------------+----------+-------------------+------+ (22 rows) Time: 1.836533ms ``` That is, for every statement executed, the shell also produces the trace for that statement in a separate result below. A trace is also produced in case the statement produces a SQL error. It works as follows: - a new client-side option `auto_trace` is provided (configurable with `\set`). - when set to non-off, it causes every subsequent statement to be enclosed in: - `SET tracing = off; SET tracing = on, <options...>` at the beginning where `<options...>` is the content of the variable `auto_trace`. - `SET tracing = off; SHOW <option> TRACE FOR SESSION` at the end, where `<option>` is either empty or `kv` if `auto_trace` contains `kv`. Release note (cli change): A new client-side option `auto_trace` is provided to facilitate usage of session tracing. Co-authored-by: Jordan Lewis <jordanthelewis@gmail.com> Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
Build succeeded |
I like this, thanks Raphael!
On Fri, Jul 20, 2018 at 6:28 PM craig[bot] ***@***.***> wrote:
Merged #27805 <#27805>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#27805 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AE135PdHpI-z1IUO5tI-W3l3JMA9m4wSks5uIgUVgaJpZM4VYOf3>
.
--
…-- Tobias
|
This was referenced Jul 31, 2018
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.
The SHOW TRACE FOR syntax form was removed from CockroachDB SQL
because it was hard to implement correctly server-side.
However this does not mean that the need for it did not exist. Folk
were moderately unhappy to lose a feature that was exploited
productively during performance analysis and general troubleshooting.
To respond to the need, this patch instead provides a feature in
cockroach sql
that replaces the previous SHOW TRACE FORsyntax. For example:
That is, for every statement executed, the shell also produces the
trace for that statement in a separate result below.
A trace is also produced in case the statement produces a SQL error.
It works as follows:
auto_trace
is provided (configurable with\set
).enclosed in:
SET tracing = off; SET tracing = on, <options...>
at thebeginning where
<options...>
is the content of the variableauto_trace
.SET tracing = off; SHOW <option> TRACE FOR SESSION
at the end,where
<option>
is either empty orkv
ifauto_trace
containskv
.Release note (cli change): A new client-side option
auto_trace
isprovided to facilitate usage of session tracing.