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: add builtin to request statement bundles #79693

Merged
merged 1 commit into from
May 7, 2022

Conversation

Azhng
Copy link
Contributor

@Azhng Azhng commented Apr 8, 2022

Makes #79547 less painful.

Previously, there was no way to request statement bundle builtins for
internal statements.
This commit introduces crdb_internal.request_statement_bundle builtin
which allows statement bundle being requested from SQL CLI. The new
builtin takes three parameters:

  • statement fingerprint text
  • minimum execution latency for the statement
  • length of duration the statement bundle request will stay valid for
    VIEWACTIVITY or ADMIN role option is required to use this builtin. If user has
    VIEWACTIVITYREDACTED role option, user is not allowed to use this builtin.

Release note (sql change): new crdb_internal.request_statement_bundle builtin
allows statement bundle being requested from SQL CLI. The new builtin takes
three parameters:

  • statement fingerprint text
  • minimum execution latency for the statement
  • length of duration the statement bundle request will stay valid for.
    VIEWACTIVITY or ADMIN role option is required to use this builtin. If user has
    VIEWACTIVITYREDACTED role option, user is not allowed to use this builtin.

@Azhng Azhng requested a review from a team April 8, 2022 20:28
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@Azhng Azhng marked this pull request as ready for review April 11, 2022 17:32
@Azhng Azhng requested a review from a team as a code owner April 11, 2022 17:32
@Azhng Azhng requested a review from a team April 11, 2022 17:32
@Azhng Azhng requested a review from a team as a code owner April 11, 2022 17:32
Copy link
Contributor

@matthewtodd matthewtodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

ReturnType: tree.FixedReturnType(types.Bool),
Fn: func(evalCtx *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
hasViewActivityRedacted, err := evalCtx.SessionAccessor.HasRoleOption(
evalCtx.Ctx(), roleoption.VIEWACTIVITYREDACTED)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: this is problematic, view activity redacted should not be able to request statement bundles

Copy link
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 6 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @Azhng and @maryliag)


-- commits, line 23 at r1:
VIEWACTIVITYREDACTED should not have access to statement bundle, only VIEWACTIVITY


pkg/sql/sem/builtins/builtins.go, line 6894 at r1 (raw file):

Previously, Azhng (Archer Zhang) wrote…

Note to self: this is problematic, view activity redacted should not be able to request statement bundles

from your comment, this should not be here, VIEWACTIVITYREDACTED should not have access to statement bundle, so check for admin and VIEWACTIVITY
we do have function about require VIEWACTIVITY and NOT VIEWACTIVITYREDACTED


pkg/server/status_test.go, line 2753 at r1 (raw file):

	})

	t.Run("builtin", func(t *testing.T) {

after you make the changes to allow only admin and VIEWACTIVITY, create a test that checks those have access but that it will fail for VIEWACTIVITYREDACTED


return tree.DBoolTrue, nil
},
Volatility: tree.VolatilityVolatile,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably add an info field

@otan otan requested review from otan and removed request for otan April 25, 2022 23:49
@Azhng Azhng force-pushed the builtin-diag branch 4 times, most recently from abf6a5d to d5c5152 Compare May 6, 2022 18:08
Copy link
Contributor Author

@Azhng Azhng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @maryliag and @otan)


-- commits line 23 at r1:

Previously, maryliag (Marylia Gutierrez) wrote…

VIEWACTIVITYREDACTED should not have access to statement bundle, only VIEWACTIVITY

Done.


pkg/sql/sem/builtins/builtins.go line 6894 at r1 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

from your comment, this should not be here, VIEWACTIVITYREDACTED should not have access to statement bundle, so check for admin and VIEWACTIVITY
we do have function about require VIEWACTIVITY and NOT VIEWACTIVITYREDACTED

Done.


pkg/sql/sem/builtins/builtins.go line 6925 at r1 (raw file):

Previously, otan (Oliver Tan) wrote…

we should probably add an info field

Done.


pkg/server/status_test.go line 2753 at r1 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

after you make the changes to allow only admin and VIEWACTIVITY, create a test that checks those have access but that it will fail for VIEWACTIVITYREDACTED

Added the check in the TestCreateStatementDiagnosticsReportWithViewActivityOptions below

Copy link
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nits from me

Reviewed 2 of 8 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng, @maryliag, and @otan)


pkg/sql/sem/builtins/builtins.go line 6894 at r1 (raw file):

Previously, Azhng (Archer Zhang) wrote…

Done.

you can move this part to just below the if !hasViewActivity { check, so you don't need to make this check if the user is not admin or doesn't have view activity role


pkg/sql/sem/builtins/builtins.go line 7004 at r2 (raw file):

				if !hasViewActivity {
					return nil, errors.New("requesting statement bundle requires " +
						"VIEWACTIVITY option")

nit: VIEWACTIVITY or ADMIN


pkg/sql/sem/builtins/builtins.go line 7006 at r2 (raw file):

						"VIEWACTIVITY option")
				}

move to here


pkg/sql/sem/builtins/builtins.go line 7029 at r2 (raw file):

			Volatility: volatility.Volatile,
			Info: `Used to request statement bundle for a given statement fingerprint
that has execution latency than the 'minExecutionLatency'. If the 'expiresAfter'

nit: ...latency greater than the...


pkg/sql/sem/eval/context.go line 208 at r2 (raw file):

	// StmtDiagnosticsRequestInserter is used by the
	// crdb_internal.request_statement_bundle builtin to insert statement bundle

nit: insert a statement


pkg/sql/sem/eval/deps.go line 494 at r2 (raw file):

// StmtDiagnosticsRequestInsertFunc is an interface embedded in EvalCtx that can
// be used by the builtins to insert statement diagnostics request. This

nit: insert a statement


pkg/server/status_test.go line 2810 at r2 (raw file):

		"SELECT crdb_internal.request_statement_bundle('SELECT _', 0::INTERVAL, 0::INTERVAL)",
	)
	require.Contains(t, err.Error(), "requesting statement bundle requires VIEWACTIVITY option")

nit: or ADMIN

@Azhng Azhng force-pushed the builtin-diag branch 2 times, most recently from cc41448 to f248c50 Compare May 6, 2022 19:58
Copy link
Contributor Author

@Azhng Azhng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @maryliag and @otan)


pkg/sql/sem/builtins/builtins.go line 7004 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

nit: VIEWACTIVITY or ADMIN

Done.


pkg/sql/sem/builtins/builtins.go line 7006 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

move to here

Done.


pkg/sql/sem/builtins/builtins.go line 7029 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

nit: ...latency greater than the...

Done.


pkg/sql/sem/eval/context.go line 208 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

nit: insert a statement

Done.


pkg/sql/sem/eval/deps.go line 494 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

nit: insert a statement

Done.


pkg/server/status_test.go line 2810 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

nit: or ADMIN

Done.

Copy link
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 6 of 6 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @maryliag and @otan)

Makes cockroachdb#79547 less painful.

Previously, there was no way to request statement bundle builtins for
internal statements.
This commit introduces crdb_internal.request_statement_bundle builtin
which allows statement bundle being requested from SQL CLI. The new
builtin takes three parameters:
* statement fingerprint text
* minimum execution latency for the statement
* length of duration the statement bundle request will stay valid for
VIEWACTIVITY or ADMIN role option is required to use this builtin. If user has
VIEWACTIVITYREDACTED role option, user is not allowed to use this builtin.

Release note (sql change): new crdb_internal.request_statement_bundle builtin
allows statement bundle being requested from SQL CLI. The new builtin takes
three parameters:
* statement fingerprint text
* minimum execution latency for the statement
* length of duration the statement bundle request will stay valid for.
VIEWACTIVITY or ADMIN role option is required to use this builtin. If user has
VIEWACTIVITYREDACTED role option, user is not allowed to use this builtin.
@Azhng
Copy link
Contributor Author

Azhng commented May 6, 2022

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented May 7, 2022

Build succeeded:

@craig craig bot merged commit e04373b into cockroachdb:master May 7, 2022
@blathers-crl
Copy link

blathers-crl bot commented May 7, 2022

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from ce606f5 to blathers/backport-release-22.1-79693: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 22.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants