-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
admin: tenant support jobs endpoints
Previously, the Job() and Jobs() endpoints were not implemented on the tenant admin server as there was not a need and we had split the implementation into a tenant-only server. Now that we want to ship the jobs page into CC Console and support it for multi-tenant, the endpoints for the UI should work as expected. This PR edits the `jobHelper` and `jobsHelper` helpers to be functions instead of methods in `adminServer` which allows the implementation to be shared between the two servers. Release note: None Release justification: low risk, high benefit addition to multi-tenant
- Loading branch information
1 parent
e318993
commit 61d6af3
Showing
6 changed files
with
202 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_test") | ||
|
||
go_test( | ||
name = "adminccl_test", | ||
srcs = [ | ||
"main_test.go", | ||
"tenant_admin_test.go", | ||
], | ||
deps = [ | ||
"//pkg/ccl", | ||
"//pkg/ccl/serverccl", | ||
"//pkg/ccl/utilccl", | ||
"//pkg/security/securityassets", | ||
"//pkg/security/securitytest", | ||
"//pkg/server", | ||
"//pkg/server/serverpb", | ||
"//pkg/spanconfig", | ||
"//pkg/sql/tests", | ||
"//pkg/testutils/serverutils", | ||
"//pkg/testutils/skip", | ||
"//pkg/testutils/testcluster", | ||
"//pkg/util/leaktest", | ||
"//pkg/util/log", | ||
"//pkg/util/randutil", | ||
"@com_github_stretchr_testify//require", | ||
], | ||
) | ||
|
||
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,34 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package adminccl | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
_ "github.com/cockroachdb/cockroach/pkg/ccl" | ||
"github.com/cockroachdb/cockroach/pkg/ccl/utilccl" | ||
"github.com/cockroachdb/cockroach/pkg/security/securityassets" | ||
"github.com/cockroachdb/cockroach/pkg/security/securitytest" | ||
"github.com/cockroachdb/cockroach/pkg/server" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster" | ||
"github.com/cockroachdb/cockroach/pkg/util/randutil" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
defer utilccl.TestingEnableEnterprise()() | ||
securityassets.SetLoader(securitytest.EmbeddedAssets) | ||
randutil.SeedForTests() | ||
serverutils.InitTestServerFactory(server.TestServerFactory) | ||
serverutils.InitTestClusterFactory(testcluster.TestClusterFactory) | ||
os.Exit(m.Run()) | ||
} | ||
|
||
//go:generate ../../../util/leaktest/add-leaktest.sh *_test.go |
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,65 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package adminccl | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/ccl/serverccl" | ||
"github.com/cockroachdb/cockroach/pkg/server/serverpb" | ||
"github.com/cockroachdb/cockroach/pkg/spanconfig" | ||
"github.com/cockroachdb/cockroach/pkg/sql/tests" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/skip" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTenantAdminAPI(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
// The liveness session might expire before the stress race can finish. | ||
skip.UnderStressRace(t, "expensive tests") | ||
|
||
ctx := context.Background() | ||
|
||
knobs := tests.CreateTestingKnobs() | ||
knobs.SpanConfig = &spanconfig.TestingKnobs{ | ||
// Some of these subtests expect multiple (uncoalesced) tenant ranges. | ||
StoreDisableCoalesceAdjacent: true, | ||
} | ||
|
||
testHelper := serverccl.NewTestTenantHelper(t, 3 /* tenantClusterSize */, knobs) | ||
defer testHelper.Cleanup(ctx, t) | ||
|
||
t.Run("tenant_jobs", func(t *testing.T) { | ||
testJobsRPCs(ctx, t, testHelper) | ||
}) | ||
} | ||
|
||
func testJobsRPCs(ctx context.Context, t *testing.T, helper serverccl.TenantTestHelper) { | ||
http := helper.TestCluster().TenantAdminHTTPClient(t, 1) | ||
defer http.Close() | ||
|
||
_ = helper.TestCluster().TenantConn(1).Exec(t, "CREATE TABLE test (id INT)") | ||
_ = helper.TestCluster().TenantConn(1).Exec(t, "ALTER TABLE test ADD COLUMN name STRING") | ||
|
||
jobsResp := serverpb.JobsResponse{} | ||
http.GetJSON("/_admin/v1/jobs", &jobsResp) | ||
require.NotEmpty(t, jobsResp.Jobs) | ||
|
||
jobResp := serverpb.JobResponse{} | ||
job := jobsResp.Jobs[0] | ||
http.GetJSON(fmt.Sprintf("/_admin/v1/jobs/%d", job.ID), &jobResp) | ||
|
||
require.Equal(t, jobResp.ID, job.ID) | ||
} |
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