-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
98466: cli,server: static configuration profiles r=stevendanna a=knz Epic: CRDB-23559 Informs #98431. Fixes #94856. (Based off #98459) Supersedes #98380. This change introduces a mechanism through which an operator can select a "configuration profile" via the command-line flag `--config-profile` or env var `COCKROACH_CONFIG_PROFILE`. The SQL initialization defined by the profile is applied during server start-up. The profiles are (currently) hardcoded inside CockroachDB. The following profiles are predefined: - `default`: no configuration. - `multitenant+noapp`: no pre-defined `application` tenant, but with a predefined application tenant template that is used whenever a new tenant is defined. This config profile is meant for use for C2C replication target clusters. - `multitenant+app+sharedservice`: shared-process multitenancy with pre-defined `application` tenant, based off the same configuration as `multitenant+noapp`. Release note: None 101907: multitenant: misc fixes related to tenant capabilities r=arulajmani a=knz See individual commits for details. The last commit in particular probably addresses #99087. Epic: CRDB-23559 101935: sql: add issue number to todo r=rharding6373 a=rharding6373 Epic: none Informs: #101934 Release note: none Co-authored-by: Raphael 'kena' Poss <[email protected]> Co-authored-by: rharding6373 <[email protected]>
- Loading branch information
Showing
52 changed files
with
1,359 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "configprofiles", | ||
srcs = [ | ||
"doc.go", | ||
"profiles.go", | ||
"provider.go", | ||
"setter.go", | ||
], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/configprofiles", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/clusterversion", | ||
"//pkg/server/autoconfig/acprovider", | ||
"//pkg/server/autoconfig/autoconfigpb", | ||
"//pkg/util/log", | ||
"//pkg/util/syncutil", | ||
"@com_github_cockroachdb_errors//:errors", | ||
"@com_github_spf13_pflag//:pflag", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "configprofiles_test", | ||
srcs = [ | ||
"datadriven_test.go", | ||
"main_test.go", | ||
"profiles_test.go", | ||
], | ||
args = ["-test.timeout=295s"], | ||
data = glob(["testdata/**"]) + ["//c-deps:libgeos"], | ||
embed = [":configprofiles"], | ||
deps = [ | ||
"//pkg/base", | ||
"//pkg/build", | ||
"//pkg/ccl", | ||
"//pkg/security/securityassets", | ||
"//pkg/security/securitytest", | ||
"//pkg/server", | ||
"//pkg/server/autoconfig/acprovider", | ||
"//pkg/server/autoconfig/autoconfigpb", | ||
"//pkg/testutils", | ||
"//pkg/testutils/serverutils", | ||
"//pkg/testutils/sqlutils", | ||
"//pkg/testutils/testcluster", | ||
"//pkg/util/leaktest", | ||
"//pkg/util/log", | ||
"@com_github_cockroachdb_datadriven//:datadriven", | ||
], | ||
) | ||
|
||
get_x_data(name = "get_x_data") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package configprofiles_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/configprofiles" | ||
"github.com/cockroachdb/cockroach/pkg/server" | ||
"github.com/cockroachdb/cockroach/pkg/server/autoconfig/acprovider" | ||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/datadriven" | ||
) | ||
|
||
func TestDataDriven(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
ctx := context.Background() | ||
|
||
datadriven.Walk(t, "testdata", func(t *testing.T, path string) { | ||
var alreadyStarted bool | ||
var provider acprovider.Provider | ||
var s serverutils.TestServerInterface | ||
var db *sqlutils.SQLRunner | ||
defer func() { | ||
if s == nil { | ||
return | ||
} | ||
s.Stopper().Stop(ctx) | ||
}() | ||
|
||
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string { | ||
switch d.Cmd { | ||
case "profile": | ||
if alreadyStarted { | ||
t.Fatalf("%s: cannot use profile more than once", d.Pos) | ||
} | ||
setter := configprofiles.NewProfileSetter(&provider) | ||
if err := setter.Set(d.Input); err != nil { | ||
t.Fatalf("%s: %v", d.Pos, err) | ||
} | ||
var res strings.Builder | ||
fmt.Fprintf(&res, "canonical profile name: %s\n", setter.String()) | ||
|
||
numExpectedTasks := len(configprofiles.TestingGetProfiles()[setter.String()]) | ||
|
||
s, _, _ = serverutils.StartServer(t, base.TestServerArgs{ | ||
AutoConfigProvider: provider, | ||
// This test does not exercise security parameters, so we | ||
// keep the configuration simpler to keep the test code also | ||
// simple. | ||
Insecure: true, | ||
// The test controls secondary tenants manually. | ||
DefaultTestTenant: base.TestTenantDisabled, | ||
}) | ||
// We need to force the connection to the system tenant, | ||
// because at least one of the config profiles changes the | ||
// default tenant. | ||
sysTenantDB := serverutils.OpenDBConn(t, s.SQLAddr(), "cluster:system/defaultdb", | ||
true /* insecure */, s.Stopper()) | ||
db = sqlutils.MakeSQLRunner(sysTenantDB) | ||
res.WriteString("server started\n") | ||
|
||
testutils.SucceedsSoon(t, func() error { | ||
var numTasksCompleted int | ||
db.QueryRow(t, `SELECT count(*) | ||
FROM [SHOW AUTOMATIC JOBS] | ||
WHERE job_type = 'AUTO CONFIG TASK' | ||
AND status = 'succeeded'`).Scan(&numTasksCompleted) | ||
if numTasksCompleted < numExpectedTasks { | ||
return fmt.Errorf("expected %d tasks to be completed, got %d", numExpectedTasks, numTasksCompleted) | ||
} | ||
return nil | ||
}) | ||
|
||
alreadyStarted = true | ||
|
||
return res.String() | ||
|
||
case "system-sql": | ||
if !alreadyStarted { | ||
t.Fatalf("%s: must use profile before sql", d.Pos) | ||
} | ||
var res strings.Builder | ||
rows := db.QueryStr(t, d.Input) | ||
if len(rows) == 0 { | ||
res.WriteString("<no rows>\n") | ||
} else { | ||
for _, row := range rows { | ||
res.WriteString(strings.Join(row, " ")) | ||
res.WriteString("\n") | ||
} | ||
} | ||
return res.String() | ||
|
||
case "connect-tenant": | ||
if !alreadyStarted { | ||
t.Fatalf("%s: must use profile before sql", d.Pos) | ||
} | ||
sqlAddr := s.(*server.TestServer).SQLAddr() | ||
testutils.SucceedsSoon(t, func() error { | ||
goDB := serverutils.OpenDBConn(t, sqlAddr, "cluster:"+d.Input+"/defaultdb", true /* insecure */, s.Stopper()) | ||
return goDB.Ping() | ||
}) | ||
return "ok" | ||
|
||
default: | ||
t.Fatalf("unknown command: %s", d.Cmd) | ||
} | ||
return "" | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
// Package configprofiles contain static configuration profiles embedded | ||
// inside the CockroachDB binary. | ||
// | ||
// Configuration profiles are ways to initialize CockroachDB clusters | ||
// differently (upon cluster creation) depending on purpose. | ||
package configprofiles |
Oops, something went wrong.