-
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.
74112: ui/server: add ability to create conditional statement diagnostics r=lindseyjin a=lindseyjin Resolves #57634 Previously, we did not have the ability to create conditional statement diagnostics in the frontend. This commit adds in the ability to specify a minimum execution latency and an expiry time when creating a statement diagnostics request. These changes apply to both DB and CC console. Since expired requests are not surfaced at all in the frontend, we have also modified the statement diagnostics API response to not return already expired and incomplete requests. Lastly, this commit also deletes some unused code related to statement diagnostics modals. Release note (ui change): Add ability to create conditional statement diagnostics by adding two new fields 1) minimum execution latency, which specifies the limit for when a statement should be tracked and 2) expiry time, which specifies when a diagnostics request should expire. 74145: streamingccl: Ensure appropriate privileges when replicating. r=miretskiy a=miretskiy Add checks to replication stream manager to ensure appropriate privileges and require enterprise license when executing streaming replication. Release Notes: None Co-authored-by: Lindsey Jin <[email protected]> Co-authored-by: Yevgeniy Miretskiy <[email protected]>
- Loading branch information
Showing
30 changed files
with
670 additions
and
362 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
88 changes: 88 additions & 0 deletions
88
pkg/ccl/streamingccl/streamproducer/replication_manager_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,88 @@ | ||
// Copyright 2021 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 streamproducer | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/ccl/utilccl" | ||
"github.com/cockroachdb/cockroach/pkg/security" | ||
"github.com/cockroachdb/cockroach/pkg/sql" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb" | ||
"github.com/cockroachdb/cockroach/pkg/streaming" | ||
"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/cockroach/pkg/util/protoutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestReplicationManagerRequiresAdminRole(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
ctx := context.Background() | ||
s, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{}) | ||
defer s.Stopper().Stop(ctx) | ||
tDB := sqlutils.MakeSQLRunner(sqlDB) | ||
|
||
var sessionData sessiondatapb.SessionData | ||
{ | ||
var sessionSerialized []byte | ||
tDB.QueryRow(t, "SELECT crdb_internal.serialize_session()").Scan(&sessionSerialized) | ||
require.NoError(t, protoutil.Unmarshal(sessionSerialized, &sessionData)) | ||
} | ||
|
||
getManagerForUser := func(u string) (streaming.ReplicationStreamManager, error) { | ||
sqlUser, err := security.MakeSQLUsernameFromUserInput(u, security.UsernameValidation) | ||
require.NoError(t, err) | ||
execCfg := s.ExecutorConfig().(sql.ExecutorConfig) | ||
txn := kvDB.NewTxn(ctx, "test") | ||
p, cleanup := sql.NewInternalPlanner("test", txn, sqlUser, &sql.MemoryMetrics{}, &execCfg, sessionData) | ||
defer cleanup() | ||
ec := p.(interface{ EvalContext() *tree.EvalContext }).EvalContext() | ||
return newReplicationStreamManagerWithPrivilegesCheck(ec) | ||
} | ||
|
||
for _, tc := range []struct { | ||
user string | ||
expErr string | ||
isEnterprise bool | ||
}{ | ||
{user: "admin", expErr: "", isEnterprise: true}, | ||
{user: "root", expErr: "", isEnterprise: true}, | ||
{user: "nobody", expErr: "replication restricted to ADMIN role", isEnterprise: true}, | ||
{user: "admin", expErr: "use of REPLICATION requires an enterprise license", isEnterprise: false}, | ||
{user: "root", expErr: "use of REPLICATION requires an enterprise license", isEnterprise: false}, | ||
{user: "nobody", expErr: "replication restricted to ADMIN role", isEnterprise: false}, | ||
} { | ||
t.Run(fmt.Sprintf("%s/ent=%t", tc.user, tc.isEnterprise), func(t *testing.T) { | ||
if tc.isEnterprise { | ||
defer utilccl.TestingEnableEnterprise()() | ||
} else { | ||
defer utilccl.TestingDisableEnterprise()() | ||
} | ||
|
||
m, err := getManagerForUser(tc.user) | ||
if tc.expErr == "" { | ||
require.NoError(t, err) | ||
require.NotNil(t, m) | ||
} else { | ||
require.Regexp(t, tc.expErr, err) | ||
require.Nil(t, m) | ||
} | ||
}) | ||
} | ||
|
||
} |
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
Oops, something went wrong.