Skip to content
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

sql, insights: record error message for failed stmts #110565

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -327,25 +327,25 @@ SELECT * FROM crdb_internal.node_inflight_trace_spans WHERE span_id < 0
----
trace_id parent_span_id span_id goroutine_id finished start_time duration operation

query TTTBTTTTTIITITTTTTTTTTTTTIT colnames
query TTTBTTTTTIITITTTTTTTTTTTTITT colnames
SELECT * FROM crdb_internal.cluster_execution_insights WHERE query = ''
----
session_id txn_id txn_fingerprint_id stmt_id stmt_fingerprint_id problem causes query status start_time end_time full_scan user_name app_name database_name plan_gist rows_read rows_written priority retries last_retry_reason exec_node_ids contention index_recommendations implicit_txn cpu_sql_nanos error_code
session_id txn_id txn_fingerprint_id stmt_id stmt_fingerprint_id problem causes query status start_time end_time full_scan user_name app_name database_name plan_gist rows_read rows_written priority retries last_retry_reason exec_node_ids contention index_recommendations implicit_txn cpu_sql_nanos error_code last_error_redactable

query TTTBTTTTTIITITTTTTTTTTTTTIT colnames
query TTTBTTTTTIITITTTTTTTTTTTTITT colnames
SELECT * FROM crdb_internal.node_execution_insights WHERE query = ''
----
session_id txn_id txn_fingerprint_id stmt_id stmt_fingerprint_id problem causes query status start_time end_time full_scan user_name app_name database_name plan_gist rows_read rows_written priority retries last_retry_reason exec_node_ids contention index_recommendations implicit_txn cpu_sql_nanos error_code
session_id txn_id txn_fingerprint_id stmt_id stmt_fingerprint_id problem causes query status start_time end_time full_scan user_name app_name database_name plan_gist rows_read rows_written priority retries last_retry_reason exec_node_ids contention index_recommendations implicit_txn cpu_sql_nanos error_code last_error_redactable

query TTTBTTTTTIITITTTTTITT colnames
query TTTBTTTTTIITITTTTTITTT colnames
SELECT * FROM crdb_internal.cluster_txn_execution_insights WHERE query = ''
----
txn_id txn_fingerprint_id query implicit_txn session_id start_time end_time user_name app_name rows_read rows_written priority retries last_retry_reason contention problems causes stmt_execution_ids cpu_sql_nanos last_error_code status
txn_id txn_fingerprint_id query implicit_txn session_id start_time end_time user_name app_name rows_read rows_written priority retries last_retry_reason contention problems causes stmt_execution_ids cpu_sql_nanos last_error_code last_error_redactable status

query TTTBTTTTTIITITTTTTITT colnames
query TTTBTTTTTIITITTTTTITTT colnames
SELECT * FROM crdb_internal.node_txn_execution_insights WHERE query = ''
----
txn_id txn_fingerprint_id query implicit_txn session_id start_time end_time user_name app_name rows_read rows_written priority retries last_retry_reason contention problems causes stmt_execution_ids cpu_sql_nanos last_error_code status
txn_id txn_fingerprint_id query implicit_txn session_id start_time end_time user_name app_name rows_read rows_written priority retries last_retry_reason contention problems causes stmt_execution_ids cpu_sql_nanos last_error_code last_error_redactable status

query ITTI
SELECT range_id, start_pretty, end_pretty, lease_holder FROM crdb_internal.ranges
Expand Down
8 changes: 8 additions & 0 deletions pkg/cli/zip_table_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ var zipInternalTablesPerCluster = DebugZipTableRegistry{
"index_recommendations",
"retries",
"last_retry_reason",
"error_code",
"crdb_internal.redact(last_error_redactable) as last_error_redactable",
},
},
"crdb_internal.cluster_locks": {
Expand Down Expand Up @@ -283,6 +285,8 @@ var zipInternalTablesPerCluster = DebugZipTableRegistry{
"problems",
"causes",
"stmt_execution_ids",
"last_error_code",
"crdb_internal.redact(last_error_redactable) as last_error_redactable",
},
},
`"".crdb_internal.create_function_statements`: {
Expand Down Expand Up @@ -698,6 +702,8 @@ var zipInternalTablesPerNode = DebugZipTableRegistry{
"priority",
"retries",
"exec_node_ids",
"error_code",
"crdb_internal.redact(last_error_redactable) as last_error_redactable",
},
},
"crdb_internal.node_inflight_trace_spans": {
Expand Down Expand Up @@ -947,6 +953,8 @@ var zipInternalTablesPerNode = DebugZipTableRegistry{
"problems",
"causes",
"stmt_execution_ids",
"last_error_code",
"crdb_internal.redact(last_error_redactable) as last_error_redactable",
},
},
"crdb_internal.node_txn_stats": {
Expand Down
34 changes: 22 additions & 12 deletions pkg/sql/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,25 +1022,35 @@ func (p *planner) HasOwnershipOnSchema(
return hasOwnership, nil
}

// HasViewActivityOrViewActivityRedactedRole implements the AuthorizationAccessor interface.
// HasViewActivityOrViewActivityRedactedRole is part of the eval.SessionAccessor interface.
// It returns 2 boolean values - the first indicating if we have either privilege requested,
// and the second indicating whether or not it was VIEWACTIVITYREDACTED.
// Requires a valid transaction to be open.
func (p *planner) HasViewActivityOrViewActivityRedactedRole(ctx context.Context) (bool, error) {
func (p *planner) HasViewActivityOrViewActivityRedactedRole(
ctx context.Context,
) (hasPrivs bool, shouldRedact bool, err error) {
if hasAdmin, err := p.HasAdminRole(ctx); err != nil {
return hasAdmin, err
return hasAdmin, false, err
} else if hasAdmin {
return true, nil
}
if hasView, err := p.HasViewActivity(ctx); err != nil {
return false, err
} else if hasView {
return true, nil
return true, false, nil
}

// We check for VIEWACTIVITYREDACTED first as users can have both
// VIEWACTIVITY and VIEWACTIVITYREDACTED, where VIEWACTIVITYREDACTED
// takes precedence (i.e. we must redact senstitive values).
if hasViewRedacted, err := p.HasViewActivityRedacted(ctx); err != nil {
return false, err
return false, false, err
} else if hasViewRedacted {
return true, nil
return true, true, nil
}
return false, nil

if hasView, err := p.HasViewActivity(ctx); err != nil {
return false, false, err
} else if hasView {
return true, false, nil
}

return false, false, nil
}

func (p *planner) HasViewActivityRedacted(ctx context.Context) (bool, error) {
Expand Down
Loading
Loading