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

settings: Add syntax for cluster settings #76929

Merged
merged 1 commit into from
Mar 2, 2022

Conversation

ajstorm
Copy link
Collaborator

@ajstorm ajstorm commented Feb 23, 2022

Before this commit, there was no syntax to SET or SHOW cluster settings which
exist for a given tenant. This commit adds the following syntax:

  • ALTER TENANT SET CLUSTER SETTING =
  • ALTER TENANT ALL SET CLUSTER SETTING =
  • ALTER TENANT RESET CLUSTER SETTING
  • ALTER TENANT ALL RESET CLUSTER SETTING
  • SHOW CLUSTER SETTING FOR TENANT
  • SHOW [ALL] CLUSTER SETTINGS FOR TENANT

Note that the syntax is added but the underlying commands are currently
unimplemented. The implementation of these commands will come with a subsequent
commit.

Release note (sql change): Added syntax for modifying cluster settings at the
tenant level.

Informs: #73857.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@RaduBerinde RaduBerinde requested review from ajwerner and dt February 23, 2022 16:29
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

just had nits and needs tests!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @ajwerner, @dt, and @RaduBerinde)


pkg/sql/set_cluster_setting.go, line 178 at r1 (raw file):

	if n.tenantID.IsSet() || n.tenantAll {
		return errors.UnimplementedError(

nit: use unimplemented.NewWithIssue


pkg/sql/show_cluster_setting.go, line 122 at r1 (raw file):

) (planNode, error) {
	if n.TenantID.IsSet() {
		return nil, errors.UnimplementedError(

nit: use unimplemented.NewWithIssue


pkg/sql/delegate/show_all_cluster_settings.go, line 26 at r1 (raw file):

) (tree.Statement, error) {
	if stmt.TenantID.IsSet() {
		return nil, errors.UnimplementedError(

nit: use unimplemented.NewWithIssue


pkg/sql/sem/tree/set.go, line 81 at r1 (raw file):

// Format implements the NodeFormatter interface.
func (node *SetClusterSetting) Format(ctx *FmtCtx) {

we should test this formatting logic as well. could you add test cases to pkg/sql/parser/testdata/show and pkg/sql/parser/testdata/set (or a new test file if you like)

@ajstorm ajstorm requested a review from a team February 24, 2022 14:37
@ajstorm ajstorm force-pushed the ajstorm-cs-syntax branch 4 times, most recently from ac18423 to e2d0312 Compare February 24, 2022 15:55
@ajstorm ajstorm requested a review from rafiss February 24, 2022 18:22
Copy link
Collaborator Author

@ajstorm ajstorm left a comment

Choose a reason for hiding this comment

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

Thanks Rafi.

I've addressed your comments, but you might want to have another full look. I reworked things considerably due to @RaduBerinde's suggestion that we create a new tree node for alter tenant.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @dt, @RaduBerinde, and @rafiss)


pkg/sql/sem/tree/set.go, line 81 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

we should test this formatting logic as well. could you add test cases to pkg/sql/parser/testdata/show and pkg/sql/parser/testdata/set (or a new test file if you like)

Done.

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

looks good overall! just one comment on the formatting

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @ajwerner, @dt, @RaduBerinde, and @rafiss)


pkg/sql/sem/tree/alter_tenant.go, line 33 at r2 (raw file):

		ctx.WriteString("ALTER TENANT ALL ")
	} else if node.TenantID.IsSet() {
		s := fmt.Sprintf("ALTER TENANT %d ", node.TenantID.ToUint64())

i don't think we should make the TenantID skip the FmtCtx flags (unless there's a specific reason?)

so we'd want:

ctx.WriteString("ALTER TENANT ")
ctx.FormatNode(node.TenantID)
ctx.WriteString(" ")

(same goes for SHOW formatting)


pkg/sql/parser/testdata/alter_tenant, line 6 at r2 (raw file):

ALTER TENANT 1 SET CLUSTER SETTING a = 3
ALTER TENANT 1 SET CLUSTER SETTING a = (3) -- fully parenthesized
ALTER TENANT 1 SET CLUSTER SETTING a = _ -- literals removed

i would expect the 1 to be removed in the "literals removed" step.

@ajstorm ajstorm requested a review from rafiss February 28, 2022 15:57
Copy link
Collaborator Author

@ajstorm ajstorm 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 (waiting on @ajstorm, @ajwerner, @dt, @RaduBerinde, and @rafiss)


pkg/sql/sem/tree/alter_tenant.go, line 33 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i don't think we should make the TenantID skip the FmtCtx flags (unless there's a specific reason?)

so we'd want:

ctx.WriteString("ALTER TENANT ")
ctx.FormatNode(node.TenantID)
ctx.WriteString(" ")

(same goes for SHOW formatting)

I was thinking that the tenant ID would never contain PII, but could be useful in debugging in all cases? Is this the proper justification for having it skip the flags?

@rafiss
Copy link
Collaborator

rafiss commented Feb 28, 2022

I was thinking that the tenant ID would never contain PII, but could be useful in debugging in all cases? Is this the proper justification for having it skip the flags?

It's a good intuition, but our formatting logic has two separate notions:

	// FmtHideConstants instructs the pretty-printer to produce a
	// representation that does not disclose query-specific data. It
	// also shorten long lists in tuples, VALUES and array expressions.
	FmtHideConstants

	// FmtAnonymize instructs the pretty-printer to remove
	// any name but function names.
	FmtAnonymize

FmtHideConstants only hides literal constants, but not identifiers. It is used, for example, (1) in the DB console statements page, to group statements together to be able to view query stats and (2) by the optimizer to cache query plans. (Neither (1) nor (2) seem that important for ALTER TENANT ... SET, but it's worth using the same formatting principles across our entire SQL syntax.)

FmtAnonymize is used to hide PII like names and identifiers, but not literal constants. For logging and telemetry, I believe FmtAnonymize and FmtHideConstants are both used.

Copy link
Collaborator Author

@ajstorm ajstorm 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 (waiting on @ajwerner, @dt, @RaduBerinde, and @rafiss)


pkg/sql/sem/tree/alter_tenant.go, line 33 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

I was thinking that the tenant ID would never contain PII, but could be useful in debugging in all cases? Is this the proper justification for having it skip the flags?

As mentioned on Slack, I'm going to leave this as-is for now, pending the broader investigation as to what to do here.


pkg/sql/parser/testdata/alter_tenant, line 6 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i would expect the 1 to be removed in the "literals removed" step.

Does this key off of the Format function? If so I think we're stuck with showing this literal pending the investigation mentioned above.

Copy link
Collaborator Author

@ajstorm ajstorm left a comment

Choose a reason for hiding this comment

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

I'm going to hold off on that change to the TenantID formatting. This should be RFAL now.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @dt, @RaduBerinde, and @rafiss)

Copy link
Collaborator

@rafiss rafiss 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! 0 of 0 LGTMs obtained (waiting on @ajstorm, @ajwerner, @dt, @RaduBerinde, and @rafiss)


pkg/sql/parser/testdata/alter_tenant, line 6 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Does this key off of the Format function? If so I think we're stuck with showing this literal pending the investigation mentioned above.

yeah, this is the result of formatting with FmtHideConstants. we can address it during the stability period

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm: modulo one comment

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajstorm, @ajwerner, @dt, and @rafiss)


pkg/sql/alter_tenant.go, line 60 at r3 (raw file):

	}

	if setting.Class() == settings.SystemOnly && !p.execCfg.Codec.ForSystemTenant() {

Here we need to error out if it is a SystemOnly setting. For all others, we need to check ForSystemTenant() and only allow that (I think that should be the first thing to check - this is a "system/operator only" statement).

Copy link
Collaborator Author

@ajstorm ajstorm 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 @ajstorm, @ajwerner, @dt, @RaduBerinde, and @rafiss)


pkg/sql/alter_tenant.go, line 60 at r3 (raw file):

Previously, RaduBerinde wrote…

Here we need to error out if it is a SystemOnly setting. For all others, we need to check ForSystemTenant() and only allow that (I think that should be the first thing to check - this is a "system/operator only" statement).

@RaduBerinde I don't think I fully appreciated how we should error out here from a first read of the RFC. I took another crack at this logic based on your comments and I think I've got it right now. PTAL (assuming you're still checking email) and let me know what you think.

@ajstorm ajstorm force-pushed the ajstorm-cs-syntax branch 3 times, most recently from c9983f7 to 3975247 Compare March 1, 2022 13:38
@ajstorm ajstorm force-pushed the ajstorm-cs-syntax branch from 3975247 to 30eb035 Compare March 1, 2022 14:22
@ajstorm ajstorm requested a review from a team as a code owner March 1, 2022 14:22
@ajstorm ajstorm force-pushed the ajstorm-cs-syntax branch 2 times, most recently from 5ddcb3b to 382c4da Compare March 1, 2022 19:35
Copy link
Member

@RaduBerinde RaduBerinde 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 @ajstorm, @ajwerner, @dt, @RaduBerinde, and @rafiss)


pkg/sql/alter_tenant.go, line 67 at r5 (raw file):

			"%s is a system-only setting and must be set using SET CLUSTER SETTING", name)
	}
	if !p.execCfg.Codec.ForSystemTenant() && setting.Class() != settings.TenantWritable {

This should just be `if !ForSystemTenant() and I'd move it to be the first check.

ALTER TENANT should only be runnable by the system tenant. Non-system tenants can only use SET CLUSTER SETTING to change their settings. ALTER TENANT is only about operator-set overrides. It's very similar to calling crdb_internal.create_tenant() from the standpoint of who can run it.

@ajstorm ajstorm force-pushed the ajstorm-cs-syntax branch 2 times, most recently from 638fe16 to c130708 Compare March 2, 2022 01:38
@ajstorm ajstorm requested a review from RaduBerinde March 2, 2022 01:39
Copy link
Collaborator Author

@ajstorm ajstorm 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 @ajstorm, @ajwerner, @dt, @RaduBerinde, and @rafiss)


pkg/sql/alter_tenant.go, line 67 at r5 (raw file):

Previously, RaduBerinde wrote…

This should just be `if !ForSystemTenant() and I'd move it to be the first check.

ALTER TENANT should only be runnable by the system tenant. Non-system tenants can only use SET CLUSTER SETTING to change their settings. ALTER TENANT is only about operator-set overrides. It's very similar to calling crdb_internal.create_tenant() from the standpoint of who can run it.

Done.

Before this commit, there was no syntax to SET or SHOW cluster settings which
exist for a given tenant. This commit adds the following syntax:

* ALTER TENANT <id> SET CLUSTER SETTING <setting> = <value>
* ALTER TENANT ALL SET CLUSTER SETTING <setting> = <value>
* ALTER TENANT <id> RESET CLUSTER SETTING <setting>
* ALTER TENANT ALL RESET CLUSTER SETTING <setting>
* SHOW CLUSTER SETTING <setting> FOR TENANT <id>
* SHOW [ALL] CLUSTER SETTINGS FOR TENANT <id>

Note that the syntax is added but the underlying commands are currently
unimplemented. The implementation of these commands will come with a subsequent
commit.

Release note (sql change): Added syntax for modifying cluster settings at the
tenant level.

Release justification: Completion of feature for 22.1.
@ajstorm ajstorm force-pushed the ajstorm-cs-syntax branch from c130708 to 89091fe Compare March 2, 2022 01:43
@ajstorm
Copy link
Collaborator Author

ajstorm commented Mar 2, 2022

TFTR!

bors r=raduberinde,rafiss

@craig
Copy link
Contributor

craig bot commented Mar 2, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Mar 2, 2022

Build succeeded:

Copy link
Member

@RaduBerinde RaduBerinde 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

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.

4 participants