-
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
cluster-ui: move database details endpoint to use sql-over-http #93209
Conversation
d2b6166
to
867fe2f
Compare
Converted to draft due to upcoming changes for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice.
Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @THardy98)
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 175 at r1 (raw file):
): DatabaseDetailsQuery<DatabaseRangesRow> => { const stmt: SqlStatement = { sql: `SELECT
if you want this to be robust and version-independent, you could expand it into a join across crdb_internal.tables
, using crdb_internal.table_span
, then join on crdb_internal.ranges_no_leases
, then call crdb_internal.range_stats
manually to get the size.
or use SHOW RANGES FROM DATABASE when it's there.
pkg/ui/workspaces/cluster-ui/src/api/util.ts
line 50 at r1 (raw file):
// "region=us-east3,az=d" // ] export function parseReplicaLocalities(localities: string[]): string[] {
Ask Eric to teach you about SQL unnest
and split_part
, he got to it recently and this seems to be relevant here.
867fe2f
to
229d2e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @knz)
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 175 at r1 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
if you want this to be robust and version-independent, you could expand it into a join across
crdb_internal.tables
, usingcrdb_internal.table_span
, then join oncrdb_internal.ranges_no_leases
, then callcrdb_internal.range_stats
manually to get the size.or use SHOW RANGES FROM DATABASE when it's there.
Followed your first suggestion. Let me know if this is accurate to what you had in mind. Particularly uncertain with joining on the range's start key with crdb_internal.table_span(t.table_id)[1]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @THardy98)
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 175 at r1 (raw file):
Previously, THardy98 (Thomas Hardy) wrote…
Followed your first suggestion. Let me know if this is accurate to what you had in mind. Particularly uncertain with joining on the range's start key with
crdb_internal.table_span(t.table_id)[1]
.
yeah that condition isn't sufficient.
Run SHOW RANGES FROM DATABASE xxx WITH EXPLAIN
in a shell and look at the generated SQL. It will tell you what you need.
pkg/ui/workspaces/cluster-ui/src/api/util.ts
line 50 at r1 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
Ask Eric to teach you about SQL
unnest
andsplit_part
, he got to it recently and this seems to be relevant here.
Still applicable.
3239dda
to
b2f9c30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @knz)
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 175 at r1 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
yeah that condition isn't sufficient.
RunSHOW RANGES FROM DATABASE xxx WITH EXPLAIN
in a shell and look at the generated SQL. It will tell you what you need.
Used the join condition from the EXPLAIN
, joining on table_spans
and the start/end key conditionals between table_spans
and ranges_no_leases
.
Aside, is calling range_stats
on just the range's start key correct to get the range's statistics?
pkg/ui/workspaces/cluster-ui/src/api/util.ts
line 50 at r1 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
Still applicable.
Using unnest
and split_part
to parse regions, return as an ARRAY
.
b2f9c30
to
647d2fe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @THardy98)
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 175 at r1 (raw file):
Aside, is calling range_stats on just the range's start key correct to get the range's statistics?
yes.
But it gives you range statistics. Not table statistics.
So this means this way to gather size information is incorrect if your goal is to get per-table size estimates. See: https://cockroachlabs.atlassian.net/browse/CRDB-22711
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 187 at r4 (raw file):
coalesce((crdb_internal.range_stats(s.start_key)->>'range_val_bytes')::INT, 0) AS range_size FROM crdb_internal.tables as t JOIN ${dbName}.crdb_internal.table_spans as s ON s.descriptor_id = t.table_id
I'm not familiar with this syntax ${dbName}
. What does it do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @knz)
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 175 at r1 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
Aside, is calling range_stats on just the range's start key correct to get the range's statistics?
yes.
But it gives you range statistics. Not table statistics.
So this means this way to gather size information is incorrect if your goal is to get per-table size estimates. See: https://cockroachlabs.atlassian.net/browse/CRDB-22711
Yes, but as I understand it, there currently is no alternative to get per-table size estimates. Consequently, I decided to follow the approach on the existing structured endpoint. I suppose the alternative is to simply omit this data but not sure if that would reflect well for UX if we remove metrics that existed on former versions.
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 187 at r4 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
I'm not familiar with this syntax
${dbName}
. What does it do?
The ${...}
syntax is shorthand for string formatting, it adds the variable string value dbName
to the query string. Similar in function to fmt.Sprintf
. With that said, I feel like this isn't particularly safe practice, but I'm not sure how to achieve the same thing without string formatting (as SQL arguments in this case do not work).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @j82w and @THardy98)
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 175 at r1 (raw file):
Previously, THardy98 (Thomas Hardy) wrote…
Yes, but as I understand it, there currently is no alternative to get per-table size estimates. Consequently, I decided to follow the approach on the existing structured endpoint. I suppose the alternative is to simply omit this data but not sure if that would reflect well for UX if we remove metrics that existed on former versions.
Yes it's ok to keep this as-is for now but with the knowledge it's broken. I encourage you to try this manually (make two tables: one with little/no data and the other one with more data, e.g. via generate_series
, and then look at the result) and report what you find to your team for tracking.
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 187 at r4 (raw file):
Previously, THardy98 (Thomas Hardy) wrote…
The
${...}
syntax is shorthand for string formatting, it adds the variable string valuedbName
to the query string. Similar in function tofmt.Sprintf
. With that said, I feel like this isn't particularly safe practice, but I'm not sure how to achieve the same thing without string formatting (as SQL arguments in this case do not work).
It's super important that you figure this out. Also ensure there is a unit test that uses a database name containing a space.
I know that @j82w looked at this area recently.
I suspect we already have something elsewhere in the UI code; it's should be a common problem? Worth asking on obs-infra.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @j82w)
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 187 at r4 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
It's super important that you figure this out. Also ensure there is a unit test that uses a database name containing a space.
I know that @j82w looked at this area recently.I suspect we already have something elsewhere in the UI code; it's should be a common problem? Worth asking on obs-infra.
Talked with Jake about it and opened discussion for this on the obs-infra channel.
826e464
to
57a5b4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @j82w and @knz)
pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts
line 187 at r4 (raw file):
Previously, THardy98 (Thomas Hardy) wrote…
Talked with Jake about it and opened discussion for this on the obs-infra channel.
Ported the safesql
package from managed-service to cluster-ui (#96286), using it to safely quote identifiers.
e51da02
to
0566eef
Compare
beed3af
to
d359688
Compare
4647493
to
ec52ed3
Compare
This is what it looks like for the
|
I've removed the code that adds the |
TYFR :) |
bors r+ |
Build failed (retrying...): |
Build failed (retrying...): |
bors r- |
Canceled. |
bors r+ |
bors r- |
Canceled. |
This change establishes preliminary work to move the existing database details endpoint to use sql-over-http, making it tenant-scoped. Currently, this change is missing a couple existing fields: - `approximate_disk_bytes`, used to display the size of the database - `node_ids`, used to display the nodes that the database uses The data for database details is populated using 5 queries, which fetch the database's: - ID - grants - tables - range statistics - index usage statistics This PR also changes the structure of the database details response. Each field within the overlying database details response encapsulates the response of one of the queries. Query failures are captured at the top-level of the response and within the corresponding response field for the query (scoping query failures to each transaction). Release note: None
This change establishes preliminary work to move the existing database details endpoint to use sql-over-http, making it tenant-scoped. Currently, this change is missing a couple existing fields: - `approximate_disk_bytes`, used to display the size of the database - `node_ids`, used to display the nodes that the database uses The data for database details is populated using 5 queries, which fetch the database's: - ID - grants - tables - range statistics - index usage statistics This PR also changes the structure of the database details response. Each field within the overlying database details response encapsulates the response of one of the queries. Query failures are captured at the top-level of the response and within the corresponding response field for the query (scoping query failures to each transaction). Release note: None
bors r+ |
Build failed (retrying...): |
Build failed: |
This change moves the existing database details endpoint to use sql-over-http. The data for database details is populated using 7 queries, which fetch the database's: - ID - grants - tables - replicas and regions - index usage statistics - zone configuration - span statistics This PR also changes the structure of the database details response. Each field within the overlying database details response encapsulates the response of one of the queries. Query failures are captured at the top-level of the response and within the corresponding response field for the query (scoping query failures to each transaction). Release note: None
ec52ed3
to
51ccd38
Compare
bors r+ |
Build failed (retrying...): |
Build succeeded: |
Part of: #89429
Addresses: #90261
This change moves the existing database details endpoint to use sql-over-http.
The data for database details is populated using 7 queries, which fetch
the database's:
This PR also changes the structure of the database details response.
Each field within the overlying database details response encapsulates
the response of one of the queries. Query failures are captured at the
top-level of the response and within the corresponding response field
for the query (scoping query failures to each transaction).
Additionally, we no longer fetch
missing_tables
as we are no longer fetching table stats per table, but in a single query.DEMO
https://www.loom.com/share/3a51bf5a8f3c41089fc5acae9ff29fcf
Release note: None