-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sqlstats: generate PCT_RUNTIME sort when requested
Previously, when a request was made to the combined stats endpoint on CRDB with a `PCT_RUNTIME` sort, we'd default to a `svcLatency` sort instead because of a missing switch case. This change fills that gap and adds some datadriven tests to inspect the resulting `WHERE` clauses. Fixes: #123841 Epic: CRDB-37544 Release note (ui change): Viewing SQL Activity sorted by `% of Runtime` now correctly sorts entries by the runtime amount.
- Loading branch information
1 parent
0ad22c6
commit e563642
Showing
4 changed files
with
200 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2024 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 server | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/server/serverpb" | ||
"github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sqlstats" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/datapathutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/datadriven" | ||
) | ||
|
||
func TestGetCombinedStatementsQueryClausesAndArgs(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
settings := cluster.MakeClusterSettings() | ||
testingKnobs := &sqlstats.TestingKnobs{} | ||
|
||
datadriven.RunTest(t, datapathutils.TestDataPath(t, "combined_statement_stats"), func(t *testing.T, d *datadriven.TestData) string { | ||
switch d.Cmd { | ||
case "query": | ||
var limit int | ||
var sortString string | ||
var internal bool | ||
d.ScanArgs(t, "sort", &sortString) | ||
d.ScanArgs(t, "limit", &limit) | ||
d.ScanArgs(t, "internal", &internal) | ||
|
||
gotWhereClause, gotOrderAndLimitClause, gotArgs := getCombinedStatementsQueryClausesAndArgs( | ||
&serverpb.CombinedStatementsStatsRequest{ | ||
FetchMode: &serverpb.CombinedStatementsStatsRequest_FetchMode{ | ||
StatsType: serverpb.CombinedStatementsStatsRequest_StmtStatsOnly, | ||
Sort: serverpb.StatsSortOptions(serverpb.StatsSortOptions_value[sortString]), | ||
}, | ||
}, | ||
testingKnobs, | ||
internal, | ||
settings, | ||
) | ||
|
||
return fmt.Sprintf("--WHERE--\n%s\n--ORDER AND LIMIT--\n%s\n--ARGS--\n%v", gotWhereClause, gotOrderAndLimitClause, gotArgs) | ||
default: | ||
t.Fatalf("unknown cmd: %s", d.Cmd) | ||
} | ||
return "" | ||
}) | ||
} |
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,136 @@ | ||
query sort=PCT_RUNTIME limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY ((statistics -> 'statistics' -> 'svcLat' ->> 'mean')::FLOAT * | ||
(statistics -> 'statistics' ->> 'cnt')::FLOAT) DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=SERVICE_LAT limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'statistics' -> 'svcLat' ->> 'mean')::FLOAT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=CPU_TIME limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'execution_statistics' -> 'cpuSQLNanos' ->> 'mean')::FLOAT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=EXECUTION_COUNT limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'statistics' ->> 'cnt')::INT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=P99_STMTS_ONLY limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'statistics' -> 'latencyInfo' ->> 'p99')::FLOAT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=CONTENTION_TIME limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'execution_statistics' -> 'contentionTime' ->> 'mean')::FLOAT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=LATENCY_INFO_P50 limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'statistics' -> 'latencyInfo' ->> 'p50')::FLOAT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=LATENCY_INFO_P90 limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'statistics' -> 'latencyInfo' ->> 'p90')::FLOAT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=LATENCY_INFO_MIN limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'statistics' -> 'latencyInfo' ->> 'min')::FLOAT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=LATENCY_INFO_MAX limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'statistics' -> 'latencyInfo' ->> 'max')::FLOAT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=ROWS_PROCESSED limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY ((statistics -> 'statistics' -> 'rowsRead' ->> 'mean')::FLOAT + | ||
(statistics -> 'statistics' -> 'rowsWritten' ->> 'mean')::FLOAT) DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=MAX_MEMORY limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'execution_statistics' -> 'maxMemUsage' ->> 'mean')::FLOAT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=NETWORK limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'execution_statistics' -> 'networkBytes' ->> 'mean')::FLOAT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=RETRIES limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'statistics' ->> 'maxRetries')::INT DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] | ||
|
||
query sort=LAST_EXEC limit=100 internal=false | ||
---- | ||
--WHERE-- | ||
WHERE app_name NOT LIKE '$ internal%' AND app_name NOT LIKE '$$ %' | ||
--ORDER AND LIMIT-- | ||
ORDER BY (statistics -> 'statistics' ->> 'lastExecAt') DESC LIMIT $1 | ||
--ARGS-- | ||
[20000] |