Skip to content

Commit

Permalink
roachpb, server, ui: add fingerprint ID to details pages
Browse files Browse the repository at this point in the history
Previously, there was no easy way to get a statement or
fingerprint id from their respective details pages,
allowing then the value to be found on our internal tables
using cli.
This commit adds the fingerprint id on the response of
the statement details page.
It also adds the fingeprint ID to the Statement Details
page and Transaction Details page.

Fixes cockroachdb#91763

Release note (ui change): Add fingerprint ID in hex format
to the Statement Details page and Transaction Details page.
  • Loading branch information
maryliag committed Nov 15, 2022
1 parent e3447ad commit be2cf04
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/roachpb/app_stats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ message AggregatedStatementMetadata {
optional int64 full_scan_count = 10 [(gogoproto.nullable) = false];
optional int64 vec_count = 11 [(gogoproto.nullable) = false];
optional int64 total_count = 12 [(gogoproto.nullable) = false];
optional string fingerprint_id = 13 [(gogoproto.nullable) = false, (gogoproto.customname) = "FingerprintID"];
}

// CollectedStatementStatistics wraps collected timings and metadata for some
Expand Down
12 changes: 8 additions & 4 deletions pkg/server/combined_statement_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func getStatementDetailsQueryClausesAndArgs(
return whereClause, args, nil
}

// getTotalStatementDetails return all the statistics for the selectec statement combined.
// getTotalStatementDetails return all the statistics for the selected statement combined.
func getTotalStatementDetails(
ctx context.Context, ie *sql.InternalExecutor, whereClause string, args []interface{},
) (serverpb.StatementDetailsResponse_CollectedStatementSummary, error) {
Expand All @@ -490,13 +490,15 @@ func getTotalStatementDetails(
aggregation_interval,
array_agg(app_name) as app_names,
crdb_internal.merge_statement_stats(array_agg(statistics)) AS statistics,
max(sampled_plan) as sampled_plan
max(sampled_plan) as sampled_plan,
encode(fingerprint_id, 'hex') as fingerprint_id
FROM crdb_internal.statement_statistics %s
GROUP BY
aggregation_interval
aggregation_interval,
fingerprint_id
LIMIT 1`, whereClause)

const expectedNumDatums = 5
const expectedNumDatums = 6
var statement serverpb.StatementDetailsResponse_CollectedStatementSummary

row, err := ie.QueryRowEx(ctx, "combined-stmts-details-total", nil,
Expand Down Expand Up @@ -552,6 +554,8 @@ func getTotalStatementDetails(
cfg.LineWidth = tree.ConsoleLineWidth
aggregatedMetadata.FormattedQuery = cfg.Pretty(queryTree.AST)

aggregatedMetadata.FingerprintID = string(tree.MustBeDString(row[5]))

statement = serverpb.StatementDetailsResponse_CollectedStatementSummary{
Metadata: aggregatedMetadata,
AggregationInterval: time.Duration(aggInterval.Nanos()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ func BuildTxnStatisticsJSON(statistics *roachpb.CollectedTransactionStatistics)
// "properties": {
// "stmtType": { "type": "string" },
// "query": { "type": "string" },
// "fingerprintID": { "type": "string" },
// "querySummary": { "type": "string" },
// "formattedQuery": { "type": "string" },
// "implicitTxn": { "type": "boolean" },
// "distSQLCount": { "type": "number" },
// "failedCount": { "type": "number" },
Expand All @@ -280,6 +282,12 @@ func BuildTxnStatisticsJSON(statistics *roachpb.CollectedTransactionStatistics)
// "type": "string"
// }
// },
// "appNames": {
// "type": "array",
// "items": {
// "type": "string"
// }
// },
// }
// }
func BuildStmtDetailsMetadataJSON(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ func TestSQLStatsJsonEncoding(t *testing.T) {
"fullScanCount": {{.Int64}},
"totalCount": {{.Int64}},
"db": [{{joinStrings .StringArray}}],
"appNames": [{{joinStrings .StringArray}}]
"appNames": [{{joinStrings .StringArray}}],
"fingerprintID": "{{.String}}"
}
`
expectedAggregatedMetadataStr := fillTemplate(t, expectedAggregatedMetadataStrTemplate, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (s *aggregatedMetadata) jsonFields() jsonFields {
{"stmtType", (*jsonString)(&s.StmtType)},
{"vecCount", (*jsonInt)(&s.VecCount)},
{"totalCount", (*jsonInt)(&s.TotalCount)},
{"fingerprintID", (*jsonString)(&s.FingerprintID)},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { AlignedData, Options } from "uplot";
import {
appAttr,
appNamesAttr,
CheckHexValue,
DATE_FORMAT_24_UTC,
intersperse,
queryByName,
Expand Down Expand Up @@ -72,7 +73,6 @@ import {
import { Delayed } from "../delayed";
import moment from "moment";
import {
CancelStmtDiagnosticRequest,
InsertStmtDiagnosticRequest,
StatementDiagnosticsReport,
} from "../api";
Expand Down Expand Up @@ -514,6 +514,7 @@ export class StatementDetails extends React.Component<
const {
app_names,
databases,
fingerprint_id,
failed_count,
full_scan_count,
vec_count,
Expand Down Expand Up @@ -651,6 +652,10 @@ export class StatementDetails extends React.Component<
", ",
)}
/>
<SummaryCardItem
label="Fingerprint ID"
value={CheckHexValue(fingerprint_id)}
/>
</SummaryCard>
</Col>
<Col className="gutter-row" span={12}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { SummaryCard, SummaryCardItem } from "../summaryCard";
import {
Bytes,
calculateTotalWorkload,
CheckHexValue,
Duration,
formatNumberForDisplay,
unset,
Expand Down Expand Up @@ -410,6 +411,14 @@ export class TransactionDetails extends React.Component<
: unset
}
/>
<SummaryCardItem
label="Fingerprint ID"
value={CheckHexValue(
transaction?.stats_data.transaction_fingerprint_id.toString(
16,
),
)}
/>
<p
className={summaryCardStylesCx(
"summary--card__divider",
Expand Down

0 comments on commit be2cf04

Please sign in to comment.