Skip to content

Commit

Permalink
sql: surface the trace_id associated to a job
Browse files Browse the repository at this point in the history
This change adds the trace_id associated with the
current execution of the job via the crdb_internal.jobs
table and as a column in `SHOW JOBS`. This will allow
users to pull the inflight traces for a job for debugging
purposes.

Release note (sql change): `SHOW JOBS` now shows the `trace_id`
of the trace that is associated with the current execution of the
job. This allows pulling inflight traces for a job for debugging
purposes.
  • Loading branch information
adityamaru committed May 18, 2021
1 parent 67a3392 commit 9a02327
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
10 changes: 7 additions & 3 deletions pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,8 @@ CREATE TABLE crdb_internal.jobs (
fraction_completed FLOAT,
high_water_timestamp DECIMAL,
error STRING,
coordinator_id INT
coordinator_id INT,
trace_id INT
)`,
comment: `decoded job metadata from system.jobs (KV scan)`,
generator: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, _ *stop.Stopper) (virtualTableGenerator, cleanupFunc, error) {
Expand Down Expand Up @@ -671,9 +672,10 @@ CREATE TABLE crdb_internal.jobs (
id, status, created, payloadBytes, progressBytes := r[0], r[1], r[2], r[3], r[4]

var jobType, description, statement, username, descriptorIDs, started, runningStatus,
finished, modified, fractionCompleted, highWaterTimestamp, errorStr, leaseNode = tree.DNull,
finished, modified, fractionCompleted, highWaterTimestamp, errorStr, leaseNode,
traceID = tree.DNull, tree.DNull, tree.DNull, tree.DNull, tree.DNull, tree.DNull,
tree.DNull, tree.DNull, tree.DNull, tree.DNull, tree.DNull, tree.DNull, tree.DNull,
tree.DNull, tree.DNull, tree.DNull, tree.DNull, tree.DNull
tree.DNull

// Extract data from the payload.
payload, err := jobs.UnmarshalPayload(payloadBytes)
Expand Down Expand Up @@ -726,6 +728,7 @@ CREATE TABLE crdb_internal.jobs (
leaseNode = tree.NewDInt(tree.DInt(payload.Lease.NodeID))
}
errorStr = tree.NewDString(payload.Error)
traceID = tree.NewDInt(tree.DInt(payload.TraceID))
}

// Extract data from the progress field.
Expand Down Expand Up @@ -781,6 +784,7 @@ CREATE TABLE crdb_internal.jobs (
highWaterTimestamp,
errorStr,
leaseNode,
traceID,
)
return container, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/delegate/show_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SHOW JOBS SELECT id FROM system.jobs WHERE created_by_type='%s' and created_by_i
const (
selectClause = `SELECT job_id, job_type, description, statement, user_name, status,
running_status, created, started, finished, modified,
fraction_completed, error, coordinator_id
fraction_completed, error, coordinator_id, trace_id
FROM crdb_internal.jobs`
)
var typePredicate, whereClause, orderbyClause string
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/crdb_internal
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ Channel


# The validity of the rows in this table are tested elsewhere; we merely assert the columns.
query ITTTTTTTTTTTRTTI colnames
query ITTTTTTTTTTTRTTII colnames
SELECT * FROM crdb_internal.jobs WHERE false
----
job_id job_type description statement user_name descriptor_ids status running_status created started finished modified fraction_completed high_water_timestamp error coordinator_id
job_id job_type description statement user_name descriptor_ids status running_status created started finished modified fraction_completed high_water_timestamp error coordinator_id trace_id

query IITTITTT colnames
SELECT * FROM crdb_internal.schema_changes WHERE table_id < 0
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ Channel


# The validity of the rows in this table are tested elsewhere; we merely assert the columns.
query ITTTTTTTTTTTRTTI colnames
query ITTTTTTTTTTTRTTII colnames
SELECT * FROM crdb_internal.jobs WHERE false
----
job_id job_type description statement user_name descriptor_ids status running_status created started finished modified fraction_completed high_water_timestamp error coordinator_id
job_id job_type description statement user_name descriptor_ids status running_status created started finished modified fraction_completed high_water_timestamp error coordinator_id trace_id

query IITTITTT colnames
SELECT * FROM crdb_internal.schema_changes WHERE table_id < 0
Expand Down
6 changes: 4 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/create_statements
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ CREATE TABLE crdb_internal.jobs (
fraction_completed FLOAT8 NULL,
high_water_timestamp DECIMAL NULL,
error STRING NULL,
coordinator_id INT8 NULL
coordinator_id INT8 NULL,
trace_id INT8 NULL
) CREATE TABLE crdb_internal.jobs (
job_id INT8 NULL,
job_type STRING NULL,
Expand All @@ -444,7 +445,8 @@ CREATE TABLE crdb_internal.jobs (
fraction_completed FLOAT8 NULL,
high_water_timestamp DECIMAL NULL,
error STRING NULL,
coordinator_id INT8 NULL
coordinator_id INT8 NULL,
trace_id INT8 NULL
) {} {}
CREATE TABLE crdb_internal.kv_node_status (
node_id INT8 NOT NULL,
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,10 @@ SELECT * FROM [SHOW COMPACT TRACE FOR SESSION] LIMIT 0
----
age message tag operation

query ITTTTTTTTTTRTI colnames
query ITTTTTTTTTTRTII colnames
SELECT * FROM [SHOW JOBS] LIMIT 0
----
job_id job_type description statement user_name status running_status created started finished modified fraction_completed error coordinator_id
job_id job_type description statement user_name status running_status created started finished modified fraction_completed error coordinator_id trace_id

query TT colnames
SELECT * FROM [SHOW SYNTAX 'select 1; select 2']
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/exec/execbuilder/testdata/explain
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ distribution: local
vectorized: true
·
• sort
│ order: -column18,-started
│ order: -column19,-started
└── • render
Expand Down

0 comments on commit 9a02327

Please sign in to comment.