From 941368238e07c98eb185ab557f364e9d36b95638 Mon Sep 17 00:00:00 2001 From: Shubham Dhama Date: Thu, 6 Feb 2025 21:36:46 +0530 Subject: [PATCH] testutils: add `DeploymentMode` method to `ApplicationLayerInterface` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Certain tests need to determine the deployment mode of the test server—whether it's single-tenant, shared-process, or external-process. While this can be queried via SQL, a dedicated helper method improves usability. This commit adds `DeploymentMode` to `ApplicationLayerInterface` to provide a simpler way to retrieve this information. Informs: #138912 Epic: CRDB-38970 Release note: None --- pkg/server/testserver.go | 15 +++++++++++++++ pkg/testutils/serverutils/api.go | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/pkg/server/testserver.go b/pkg/server/testserver.go index f698f9ac2cb9..d0f07da67726 100644 --- a/pkg/server/testserver.go +++ b/pkg/server/testserver.go @@ -910,6 +910,9 @@ type testTenant struct { // pgPreServer handles SQL connections prior to routing them to a // specific tenant. pgPreServer *pgwire.PreServeConnHandler + // deploymentMode specifies the tenant's deployment mode. + // Allowed values: ExternalProcess or SharedProcess. + deploymentMode serverutils.DeploymentMode } var _ serverutils.ApplicationLayerInterface = &testTenant{} @@ -1258,6 +1261,11 @@ func (t *testTenant) SettingsWatcher() interface{} { return t.sql.settingsWatcher } +// DeploymentMode is part of the serverutils.ApplicationLayerInterface. +func (t *testTenant) DeploymentMode() serverutils.DeploymentMode { + return t.deploymentMode +} + // WaitForTenantCapabilities is part of the serverutils.TenantControlInterface. func (ts *testServer) WaitForTenantCapabilities( ctx context.Context, @@ -1415,6 +1423,7 @@ func (ts *testServer) StartSharedProcessTenant( pgL: sqlServerWrapper.loopbackPgL, httpTestServer: hts, drain: sqlServerWrapper.drainServer, + deploymentMode: serverutils.SharedProcess, } sqlDB, err := ts.SQLConnE(serverutils.DBName("cluster:" + string(args.TenantName) + "/" + args.UseDatabase)) @@ -1791,6 +1800,7 @@ func (ts *testServer) StartTenant( http: sw.http, drain: sw.drainServer, pgL: sw.loopbackPgL, + deploymentMode: serverutils.ExternalProcess, }, err } @@ -1920,6 +1930,11 @@ func (ts *testServer) MustGetSQLNetworkCounter(name string) int64 { return mustGetSQLCounterForRegistry(reg, name) } +// DeploymentMode is part of the serverutils.ApplicationLayerInterface. +func (ts *testServer) DeploymentMode() serverutils.DeploymentMode { + return serverutils.SingleTenant +} + // Locality is part of the serverutils.ApplicationLayerInterface. func (ts *testServer) Locality() roachpb.Locality { return ts.cfg.Locality diff --git a/pkg/testutils/serverutils/api.go b/pkg/testutils/serverutils/api.go index 820a7a769b42..122b4701c316 100644 --- a/pkg/testutils/serverutils/api.go +++ b/pkg/testutils/serverutils/api.go @@ -130,6 +130,17 @@ type TestServerController interface { RunInitialSQL(ctx context.Context, startSingleNode bool, adminUser, adminPassword string) error } +// DeploymentMode defines the mode of the underlying test server or tenant, +// which can be single-tenant (system-only), shared-process, or +// external-process. +type DeploymentMode uint8 + +const ( + SingleTenant DeploymentMode = iota + SharedProcess + ExternalProcess +) + // ApplicationLayerInterface defines accessors to the application // layer of a test server. Tests written against this interface are // effectively agnostic to whether they use a virtual cluster or not. @@ -451,6 +462,11 @@ type ApplicationLayerInterface interface { // DistSQLPlanningNodeID returns the NodeID to use by the DistSQL span resolver. DistSQLPlanningNodeID() roachpb.NodeID + + // DeploymentMode returns the deployment mode of the underlying server or + // tenant, which can be single-tenant (system-only), shared-process, or + // external-process. + DeploymentMode() DeploymentMode } // TenantControlInterface defines the API of a test server that can