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

testutils: add GrantTenantCapabilities to test interfaces #141490

Merged
merged 1 commit into from
Feb 21, 2025

Conversation

shubhamdhama
Copy link
Contributor

Many tests require granting a capability when using external-process mode. Since this pattern is repeated in multiple places, it makes sense to provide it as a utility.

As part of this cleanup, I've also adjusted when it runs: it now applies only to external-process tenants, as shared-process tenants always have all capabilities.

Informs: #138912
Epic: CRDB-38970
Release note: None

@shubhamdhama shubhamdhama requested review from a team as code owners February 14, 2025 11:49
@shubhamdhama shubhamdhama requested review from kev-cao, asg0451, srosenberg, golgeek, angles-n-daemons and DrewKimball and removed request for a team February 14, 2025 11:49
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

This looks like a nice improvement. I do wonder if we want to go even further. We could add this to TestServerArgs and then handle them as part of this code:

func (ts *testServer) grantDefaultTenantCapabilities(
ctx context.Context, tenantID roachpb.TenantID, skipTenantCheck bool,
) error {
ie := ts.InternalExecutor().(*sql.InternalExecutor)
for _, setting := range []settings.Setting{
sql.SecondaryTenantScatterEnabled,
sql.SecondaryTenantSplitAtEnabled,
sqlclustersettings.SecondaryTenantZoneConfigsEnabled,
sql.SecondaryTenantsMultiRegionAbstractionsEnabled,
} {
// Update the override for this setting. We need to do this
// instead of calling .Override() on the setting directly: certain
// tests expect to be able to change the value afterwards using
// another ALTER VC SET CLUSTER SETTING statement, which is not
// possible with regular overrides.
_, err := ie.Exec(ctx, "testserver-alter-tenant-cap", nil,
fmt.Sprintf("ALTER VIRTUAL CLUSTER [$1] SET CLUSTER SETTING %s = true", setting.Name()), tenantID.ToUint64())
if err != nil {
if skipTenantCheck {
log.Infof(ctx, "ignoring error changing setting because SkipTenantCheck is true: %v", err)
} else {
return err
}
}
}
// Waiting for capabilities can take time. To avoid paying this cost in all
// cases, we only set the nodelocal storage capability if the caller has
// configured an ExternalIODir since nodelocal storage only works with that
// configured.
shouldGrantNodelocalCap := ts.params.ExternalIODir != ""
if shouldGrantNodelocalCap {
_, err := ie.Exec(ctx, "testserver-alter-tenant-cap", nil,
"ALTER TENANT [$1] GRANT CAPABILITY can_use_nodelocal_storage", tenantID.ToUint64())
if err != nil {
if skipTenantCheck {
log.Infof(ctx, "ignoring error granting capability because SkipTenantCheck is true: %v", err)
} else {
return err
}
} else {
if err := ts.WaitForTenantCapabilities(ctx, tenantID, map[tenantcapabilities.ID]string{
tenantcapabilities.CanUseNodelocalStorage: "true",
}, ""); err != nil {
return err
}
}
}
return nil
}

To avoid waiting for capabilities longer than we have to. Don't let this suggestion get in the way of this improvement though, I think both functions are useful.

@shubhamdhama
Copy link
Contributor Author

This looks like a nice improvement. I do wonder if we want to go even further. We could add this to TestServerArgs and then handle them as part of this code:

It's a great suggestion. I'm working on it as a follow-up.

Copy link
Contributor

@cthumuluru-crdb cthumuluru-crdb left a comment

Choose a reason for hiding this comment

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

Except for one or two minor comments, this looks great!

Copy link
Contributor

@cthumuluru-crdb cthumuluru-crdb left a comment

Choose a reason for hiding this comment

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

Except for one or two minor comments, this looks great!

@asg0451 asg0451 removed their request for review February 20, 2025 20:31
Many tests require granting a capability when using external-process mode.
Since this pattern is repeated in multiple places, it makes sense to
provide it as a utility.

As part of this cleanup, I've also adjusted when it runs: it now applies
only to external-process tenants, as shared-process tenants always have all
capabilities.

Informs: cockroachdb#138912
Epic: CRDB-38970
Release note: None
@shubhamdhama shubhamdhama force-pushed the add-grant-capability-utility branch from 3fed02c to 2ea4166 Compare February 21, 2025 08:27
@shubhamdhama
Copy link
Contributor Author

TFTRs!

bors r=stevendanna,cthumuluru-crdb

@craig
Copy link
Contributor

craig bot commented Feb 21, 2025

@craig craig bot merged commit fbcabe0 into cockroachdb:master Feb 21, 2025
24 checks passed
shubhamdhama added a commit to shubhamdhama/cockroach that referenced this pull request Feb 21, 2025
(Stacked on cockroachdb#141490.)

This PR continues the work from cockroachdb#140447, replacing occurrences of
`createTestServerParams` with `createTestServerParamsAllowTenants`
to enable tenant testing in these tests.

Informs: cockroachdb#140446
Epic: CRDB-38970
Release note: None
@shubhamdhama shubhamdhama changed the title testutils: add GrantTenantCapability to test interfaces testutils: add GrantTenantCapabilities to test interfaces Feb 21, 2025
@shubhamdhama shubhamdhama deleted the add-grant-capability-utility branch February 21, 2025 12:54
sambhav-jain-16 pushed a commit to sambhav-jain-16/cockroach that referenced this pull request Mar 10, 2025
(Stacked on cockroachdb#141490.)

This PR continues the work from cockroachdb#140447, replacing occurrences of
`createTestServerParams` with `createTestServerParamsAllowTenants`
to enable tenant testing in these tests.

Informs: cockroachdb#140446
Epic: CRDB-38970
Release note: None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants