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

server: http requests always fallback to system tenant #120707

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/ccl/serverccl/server_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,32 @@ func TestServerStartStop(t *testing.T) {
s.Stopper().Stop(ctx)
}

func TestServerControllerSystemTenantHTTPFallback(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

ctx := context.Background()

srv, db, _ := serverutils.StartServer(t, base.TestServerArgs{
DefaultTestTenant: base.TestControlsTenantsExplicitly,
})
defer srv.Stopper().Stop(ctx)

_, err := db.Exec("CREATE VIRTUAL CLUSTER 'demo'")
require.NoError(t, err)
_, err = db.Exec("SET CLUSTER SETTING server.controller.default_target_cluster = 'demo'")
require.NoError(t, err)

s := srv.ApplicationLayer()
c, err := s.GetUnauthenticatedHTTPClient()
require.NoError(t, err)

resp, err := c.Get(s.AdminURL().String())
require.NoError(t, err)
defer resp.Body.Close()
require.Equal(t, 200, resp.StatusCode)
}

func TestServerControllerLoginLogout(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
Expand Down
17 changes: 15 additions & 2 deletions pkg/server/server_controller_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/server/authserver"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/errors"
)
Expand Down Expand Up @@ -107,8 +108,20 @@ func (c *serverController) httpMux(w http.ResponseWriter, r *http.Request) {
defaultTenantName := roachpb.TenantName(multitenant.DefaultTenantSelect.Get(&c.st.SV))
s, _, err = c.getServer(ctx, defaultTenantName)
if err != nil {
log.Warningf(ctx, "unable to find server for default tenant %q: %v", defaultTenantName, err)
w.WriteHeader(http.StatusInternalServerError)
if log.V(1) {
// This could get triggered often if a customer has the default
// tenant set up but not active yet. Every DB Console HTTP
// request will go through this branch in that scenario.
log.Warningf(ctx, "unable to find server for default tenant %q: %v", defaultTenantName, err)
}
sys, _, errSystem := c.getServer(ctx, catconstants.SystemTenantName)
if errSystem != nil {
log.Warningf(ctx, "unable to find server for default tenant %q: %v", defaultTenantName, err)
log.Warningf(ctx, "unable to find server for system tenant: %v", errSystem)
w.WriteHeader(http.StatusInternalServerError)
return
}
sys.getHTTPHandlerFn()(w, r)
return
}
s.getHTTPHandlerFn()(w, r)
Expand Down
Loading