-
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
builtins: add tenant_span_stats
generator function
#97534
Conversation
a856f12
to
41d4292
Compare
41d4292
to
2bd3d8a
Compare
2bd3d8a
to
a864d4d
Compare
Not sure how to add logic tests for this builtin. Is there a way to set deterministic values for |
My 2-cents - Perhaps it would be sufficient to only test this function up to the boundary with Another test idea would be to make sure that each overloaded function returns the correct column values with respect to database and table. |
26b82c4
to
bc7d252
Compare
Yes, considering that SpanStats is already tested there's no need to test the values being returned by SpanStats. Rather, I've added tests ensuring that returned values are scoped correctly (to the correct database, or database + table) and a couple checks to ensure the validity of passed in arguments (no negative values). |
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! 1 of 0 LGTMs obtained
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.
Can you partially test the non-deterministic columns with something like SELECT ... approximate_disk_bytes > 0, live_bytes > 0, etc
to make sure the columns are being populated and aren't just defaulting to a zero value to cover this part of the code
tree.NewDInt(tree.DInt(tssi.currStatsResponse.RangeCount)),
tree.NewDInt(tree.DInt(tssi.currStatsResponse.ApproximateDiskBytes)),
tree.NewDInt(tree.DInt(liveBytes)),
tree.NewDInt(tree.DInt(totalBytes)),
tree.NewDFloat(tree.DFloat(livePercentage)),
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @THardy98)
pkg/sql/planner.go
line 857 at r2 (raw file):
ctx context.Context, dbId int, tableId int, ) (eval.InternalRows, error) { query := `SELECT parent_id, table_id from crdb_internal.tables`
Could you capitalize FROM/WHERE/AND/etc for consistency
pkg/sql/planner.go
line 867 at r2 (raw file):
args = append(args, dbId) } else { query += ` where parent_id != $1`
Why is this parent_id != 0
instead of no WHERE clause?
bc7d252
to
2c83a7e
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.
Added a test to check for non-deterministic columns. Omitted approximate_disk_bytes
, as we weren't recording any disk bytes until I generated a large series (1mil), which I didn't feel was particularly valuable. I think this its probably sufficient enough to check that our other span stats are being populated, but if there's a simple way to ensure that a table has disk bytes, than I can make the change.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ecwall)
pkg/sql/planner.go
line 857 at r2 (raw file):
Previously, ecwall (Evan Wall) wrote…
Could you capitalize FROM/WHERE/AND/etc for consistency
Done.
pkg/sql/planner.go
line 867 at r2 (raw file):
Previously, ecwall (Evan Wall) wrote…
Why is this
parent_id != 0
instead of no WHERE clause?
Some tables belonging to crdb_internal.tables
are not affiliated with a database and have a parent_id
of 0 (usually crdb_internal or pg catalog tables), which aren't useful to the user.
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.
Looks good just a couple minor comments before merging
Reviewable status: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @THardy98)
pkg/sql/planner.go
line 867 at r2 (raw file):
Previously, THardy98 (Thomas Hardy) wrote…
Some tables belonging to
crdb_internal.tables
are not affiliated with a database and have aparent_id
of 0 (usually crdb_internal or pg catalog tables), which aren't useful to the user.
Can you add this as a brief comment here since it was not obvious to me.
pkg/sql/planner.go
line 871 at r3 (raw file):
} it, err := p.QueryIteratorEx(
You can just return p.QueryIteratorEx(...)
instead of doing this assignment.
pkg/sql/sem/builtins/generator_builtins.go
line 2958 at r3 (raw file):
var next bool var err error next, err = tssi.it.Next(ctx)
Remove the separate declarations and use next, err :=
.
2c83a7e
to
96c4eb0
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.
Addressed the nits, TYFR :)
Reviewable status: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @ecwall)
pkg/sql/planner.go
line 867 at r2 (raw file):
tables belonging to crdb_internal.tables are not affiliated with a database and have a parent_id of 0 (usually crdb_internal or pg catalog tables), which aren't useful to the user.
Added a comment.
pkg/sql/planner.go
line 871 at r3 (raw file):
Previously, ecwall (Evan Wall) wrote…
You can just
return p.QueryIteratorEx(...)
instead of doing this assignment.
Done
pkg/sql/sem/builtins/generator_builtins.go
line 2958 at r3 (raw file):
Previously, ecwall (Evan Wall) wrote…
Remove the separate declarations and use
next, err :=
.
Done
96c4eb0
to
0f826d8
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 2 of 7 files at r2, 1 of 2 files at r3, 5 of 5 files at r4, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @ecwall and @THardy98)
pkg/sql/sem/builtins/generator_builtins.go
line 3017 at r4 (raw file):
return nil, err } if !isAdmin {
Should this also be allowed for the same roles as HasViewActivityOrViewActivityRedactedRole
to match the crdb_internal view role check?
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 (and 2 stale) (waiting on @ecwall and @j82w)
pkg/sql/sem/builtins/generator_builtins.go
line 3017 at r4 (raw file):
Previously, j82w (Jake) wrote…
Should this also be allowed for the same roles as
HasViewActivityOrViewActivityRedactedRole
to match the crdb_internal view role check?
I had kept it to admin as the SpanStats
endpoint is scoped to admin privileges.
Previously, THardy98 (Thomas Hardy) wrote…
Does the database page work with view activity permission? Will the ui using sql-over-http still work if this requires admin? |
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! 1 of 0 LGTMs obtained (and 2 stale) (waiting on @ecwall and @THardy98)
0f826d8
to
10fdf97
Compare
After some discussion offline, opened up the builtin to anyone with |
10fdf97
to
eedcc27
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 5 files at r5.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 3 stale) (waiting on @ecwall and @THardy98)
pkg/sql/authorization.go
line 462 at r5 (raw file):
// HasViewActivity implements the AuthorizationAccessor interface. // Requires a valid transaction to be open. func (p *planner) HasViewActivity(ctx context.Context) (bool, error) {
Why not use the existing HasViewActivityOrViewActivityRedactedRole
which the crdb_internal views use?
Not sure how I missed that, will use it instead. |
eedcc27
to
be984c2
Compare
Done |
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 2 of 2 files at r6, 5 of 5 files at r7, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 3 stale) (waiting on @ecwall and @THardy98)
pkg/sql/sem/builtins/generator_builtins.go
line 3018 at r7 (raw file):
} if !hasViewActivity { return nil, pgerror.Newf(pgcode.InsufficientPrivilege, "user needs the VIEWACTIVITY or VIEWACTIVITYREDACTED permission to view span statistics")
Should this include admin?
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 (and 3 stale) (waiting on @ecwall and @j82w)
pkg/sql/sem/builtins/generator_builtins.go
line 3018 at r7 (raw file):
Previously, j82w (Jake) wrote…
Should this include admin?
Added.
Part of: cockroachdb#94332 Part of: cockroachdb#94330 Added new builtin function `tenant_span_stats` that retrieves span statistics for the current tenant. `tenant_span_stats` can be called as: - `crdb_internal.tenant_span_stats()`: returns table span statistics for all of the tenants tables - `crdb_internal.tenant_span_stats(database_id)`: returns table span statistics for the tenant's tables belonging to the specified database id - `crdb_internal.tenant_span_stats(database_id, table_id)`: returns the tenant's table span statistics for the provided table id Release note (sql change): new builtin function `tenants_span_stats`, retrieves the span statistics for the current tenant.
305ce5d
to
5d38cb0
Compare
TYFR :) |
bors r+ |
Build succeeded: |
Part of: #94332
Part of: #94330
Added new builtin function
tenant_span_stats
that retrieves spanstatistics for the current tenant.
tenant_span_stats
can be called as:crdb_internal.tenant_span_stats()
: returns table span statistics for all of the tenants tablescrdb_internal.tenant_span_stats(database_id)
: returns table span statistics for the tenant's tables belonging to the specified database idcrdb_internal.tenant_span_stats(database_id, table_id)
: returns the tenant's table span statistics for the provided table idReturned rows take the format:
Note: This implementation is naive - it calls
SpanStats
for each table span. Future work will entail expanding the endpoint to be able to fetch span statistics for multiple spans at once.Release note (sql change): new builtin function
tenants_span_stats
,retrieves the span statistics for the current tenant.