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

cli,cliccl: move some mt commands to cliccl #93618

Merged
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
11 changes: 11 additions & 0 deletions pkg/ccl/cliccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ go_library(
name = "cliccl",
srcs = [
"cliccl.go",
"context.go",
"debug.go",
"demo.go",
"ear.go",
"flags.go",
"mt.go",
"mt_proxy.go",
"mt_test_directory.go",
"start.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/ccl/cliccl",
Expand All @@ -16,21 +21,27 @@ go_library(
"//pkg/base",
"//pkg/ccl/baseccl",
"//pkg/ccl/cliccl/cliflagsccl",
"//pkg/ccl/sqlproxyccl",
"//pkg/ccl/sqlproxyccl/tenantdirsvr",
"//pkg/ccl/storageccl/engineccl/enginepbccl",
"//pkg/ccl/utilccl",
"//pkg/ccl/workloadccl/cliccl",
"//pkg/cli",
"//pkg/cli/clierrorplus",
"//pkg/cli/cliflagcfg",
"//pkg/cli/cliflags",
"//pkg/cli/democluster",
"//pkg/storage",
"//pkg/storage/enginepb",
"//pkg/util/log",
"//pkg/util/log/severity",
"//pkg/util/protoutil",
"//pkg/util/stop",
"//pkg/util/timeutil",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_errors//oserror",
"@com_github_cockroachdb_pebble//vfs",
"@com_github_cockroachdb_redact//:redact",
"@com_github_spf13_cobra//:cobra",
],
)
Expand Down
51 changes: 51 additions & 0 deletions pkg/ccl/cliccl/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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 cliccl

import (
"time"

"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl"
)

func init() {
setProxyContextDefaults()
setTestDirectorySvrContextDefaults()
}

// proxyContext captures the command-line parameters of the `mt start-proxy` command.
var proxyContext sqlproxyccl.ProxyOptions

func setProxyContextDefaults() {
proxyContext.Denylist = ""
proxyContext.ListenAddr = "127.0.0.1:46257"
proxyContext.ListenCert = ""
proxyContext.ListenKey = ""
proxyContext.MetricsAddress = "0.0.0.0:8080"
proxyContext.RoutingRule = ""
proxyContext.DirectoryAddr = ""
proxyContext.SkipVerify = false
proxyContext.Insecure = false
proxyContext.RatelimitBaseDelay = 50 * time.Millisecond
proxyContext.ValidateAccessInterval = 30 * time.Second
proxyContext.PollConfigInterval = 30 * time.Second
proxyContext.ThrottleBaseDelay = time.Second
proxyContext.DisableConnectionRebalancing = false
}

var testDirectorySvrContext struct {
port int
certsDir string
kvAddrs string
tenantBaseDir string
}

func setTestDirectorySvrContextDefaults() {
testDirectorySvrContext.port = 36257
}
45 changes: 45 additions & 0 deletions pkg/ccl/cliccl/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 cliccl

import (
"github.com/cockroachdb/cockroach/pkg/cli"
"github.com/cockroachdb/cockroach/pkg/cli/cliflagcfg"
"github.com/cockroachdb/cockroach/pkg/cli/cliflags"
)

func init() {
// Multi-tenancy proxy command flags.
{
f := mtStartSQLProxyCmd.Flags()
cliflagcfg.StringFlag(f, &proxyContext.Denylist, cliflags.DenyList)
cliflagcfg.StringFlag(f, &proxyContext.ListenAddr, cliflags.ProxyListenAddr)
cliflagcfg.StringFlag(f, &proxyContext.ListenCert, cliflags.ListenCert)
cliflagcfg.StringFlag(f, &proxyContext.ListenKey, cliflags.ListenKey)
cliflagcfg.StringFlag(f, &proxyContext.MetricsAddress, cliflags.ListenMetrics)
cliflagcfg.StringFlag(f, &proxyContext.RoutingRule, cliflags.RoutingRule)
cliflagcfg.StringFlag(f, &proxyContext.DirectoryAddr, cliflags.DirectoryAddr)
cliflagcfg.BoolFlag(f, &proxyContext.SkipVerify, cliflags.SkipVerify)
cliflagcfg.BoolFlag(f, &proxyContext.Insecure, cliflags.InsecureBackend)
cliflagcfg.DurationFlag(f, &proxyContext.ValidateAccessInterval, cliflags.ValidateAccessInterval)
cliflagcfg.DurationFlag(f, &proxyContext.PollConfigInterval, cliflags.PollConfigInterval)
cliflagcfg.DurationFlag(f, &proxyContext.ThrottleBaseDelay, cliflags.ThrottleBaseDelay)
cliflagcfg.BoolFlag(f, &proxyContext.DisableConnectionRebalancing, cliflags.DisableConnectionRebalancing)
}

// Multi-tenancy test directory command flags.
cli.RegisterFlags(func() {
f := mtTestDirectorySvr.Flags()
cliflagcfg.IntFlag(f, &testDirectorySvrContext.port, cliflags.TestDirectoryListenPort)
cliflagcfg.StringFlag(f, &testDirectorySvrContext.certsDir, cliflags.TestDirectoryTenantCertsDir)
cliflagcfg.StringFlag(f, &testDirectorySvrContext.tenantBaseDir, cliflags.TestDirectoryTenantBaseDir)
// Use StringFlagDepth to avoid conflicting with the already registered KVAddrs env var.
cliflagcfg.StringFlagDepth(1, f, &testDirectorySvrContext.kvAddrs, cliflags.KVAddrs)
})
}
18 changes: 18 additions & 0 deletions pkg/ccl/cliccl/mt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 cliccl

import "github.com/cockroachdb/cockroach/pkg/cli"

func init() {
cli.MTCmd.AddCommand(mtStartSQLProxyCmd)
cli.RegisterCommandWithCustomLogging(mtStartSQLProxyCmd)
cli.MTCmd.AddCommand(mtTestDirectorySvr)
cli.RegisterCommandWithCustomLogging(mtTestDirectorySvr)
}
29 changes: 10 additions & 19 deletions pkg/cli/mt_proxy.go → pkg/ccl/cliccl/mt_proxy.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// Copyright 2021 The Cockroach Authors.
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
// 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
//
// 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.
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt

package cli
package cliccl

import (
"context"
Expand All @@ -19,6 +17,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl"
"github.com/cockroachdb/cockroach/pkg/cli"
"github.com/cockroachdb/cockroach/pkg/cli/clierrorplus"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/log/severity"
Expand Down Expand Up @@ -97,18 +96,10 @@ func runStartSQLProxy(cmd *cobra.Command, args []string) (returnErr error) {
}

func initLogging(cmd *cobra.Command) (ctx context.Context, stopper *stop.Stopper, err error) {
// Remove the default store, which avoids using it to set up logging.
// Instead, we'll default to logging to stderr unless --log-dir is
// specified. This makes sense since the standalone SQL server is
// at the time of writing stateless and may not be provisioned with
// suitable storage.
serverCfg.Stores.Specs = nil
serverCfg.ClusterName = ""

ctx = context.Background()
stopper, err = setupAndInitializeLoggingAndProfiling(ctx, cmd, false /* isServerCmd */)
stopper, err = cli.ClearStoresAndSetupLoggingForMTCommands(cmd, ctx)
if err != nil {
return
return ctx, nil, err
}
ctx, _ = stopper.WithCancelOnQuiesce(ctx)
return ctx, stopper, err
Expand All @@ -123,7 +114,7 @@ func waitForSignals(
) (returnErr error) {
// Need to alias the signals if this has to run on non-unix OSes too.
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, drainSignals...)
signal.Notify(signalCh, cli.DrainSignals...)

select {
case err := <-errChan:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
// Copyright 2021 The Cockroach Authors.
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
// 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
//
// 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.
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt

package cli
package cliccl

import (
"context"
"fmt"
"net"

"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl/tenantdirsvr"
"github.com/cockroachdb/cockroach/pkg/cli"
"github.com/cockroachdb/cockroach/pkg/cli/clierrorplus"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -48,9 +47,7 @@ test-directory command will always add the following arguments (in that order):

func runDirectorySvr(cmd *cobra.Command, args []string) (returnErr error) {
ctx := context.Background()
serverCfg.Stores.Specs = nil

stopper, err := setupAndInitializeLoggingAndProfiling(ctx, cmd, false /* isServerCmd */)
stopper, err := cli.ClearStoresAndSetupLoggingForMTCommands(cmd, ctx)
if err != nil {
return err
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ go_library(
"log_flags.go",
"mt.go",
"mt_cert.go",
"mt_proxy.go",
"mt_start_sql.go",
"mt_test_directory.go",
"node.go",
"nodelocal.go",
"prefixer.go",
Expand Down Expand Up @@ -101,8 +99,6 @@ go_library(
deps = [
"//pkg/base",
"//pkg/build",
"//pkg/ccl/sqlproxyccl",
"//pkg/ccl/sqlproxyccl/tenantdirsvr",
"//pkg/cli/clicfg",
"//pkg/cli/clientflags",
"//pkg/cli/clienturl",
Expand Down
34 changes: 0 additions & 34 deletions pkg/cli/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl"
"github.com/cockroachdb/cockroach/pkg/cli/clicfg"
"github.com/cockroachdb/cockroach/pkg/cli/clisqlcfg"
"github.com/cockroachdb/cockroach/pkg/cli/clisqlclient"
Expand Down Expand Up @@ -64,8 +63,6 @@ func initCLIDefaults() {
setStmtDiagContextDefaults()
setAuthContextDefaults()
setImportContextDefaults()
setProxyContextDefaults()
setTestDirectorySvrContextDefaults()
setUserfileContextDefaults()
setCertContextDefaults()
setDebugRecoverContextDefaults()
Expand Down Expand Up @@ -663,37 +660,6 @@ func setImportContextDefaults() {
importCtx.rowLimit = 0
}

// proxyContext captures the command-line parameters of the `mt start-proxy` command.
var proxyContext sqlproxyccl.ProxyOptions

func setProxyContextDefaults() {
proxyContext.Denylist = ""
proxyContext.ListenAddr = "127.0.0.1:46257"
proxyContext.ListenCert = ""
proxyContext.ListenKey = ""
proxyContext.MetricsAddress = "0.0.0.0:8080"
proxyContext.RoutingRule = ""
proxyContext.DirectoryAddr = ""
proxyContext.SkipVerify = false
proxyContext.Insecure = false
proxyContext.RatelimitBaseDelay = 50 * time.Millisecond
proxyContext.ValidateAccessInterval = 30 * time.Second
proxyContext.PollConfigInterval = 30 * time.Second
proxyContext.ThrottleBaseDelay = time.Second
proxyContext.DisableConnectionRebalancing = false
}

var testDirectorySvrContext struct {
port int
certsDir string
kvAddrs string
tenantBaseDir string
}

func setTestDirectorySvrContextDefaults() {
testDirectorySvrContext.port = 36257
}

// userfileCtx captures the command-line parameters of the
// `userfile` command.
// See below for defaults.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/debug_synctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func runSyncer(
}

ch := make(chan os.Signal, 1)
signal.Notify(ch, drainSignals...)
signal.Notify(ch, DrainSignals...)

write := func() (_ int64, err error) {
defer func() {
Expand Down
33 changes: 6 additions & 27 deletions pkg/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,33 +914,6 @@ func init() {
}
}

// Multi-tenancy proxy command flags.
{
f := mtStartSQLProxyCmd.Flags()
cliflagcfg.StringFlag(f, &proxyContext.Denylist, cliflags.DenyList)
cliflagcfg.StringFlag(f, &proxyContext.ListenAddr, cliflags.ProxyListenAddr)
cliflagcfg.StringFlag(f, &proxyContext.ListenCert, cliflags.ListenCert)
cliflagcfg.StringFlag(f, &proxyContext.ListenKey, cliflags.ListenKey)
cliflagcfg.StringFlag(f, &proxyContext.MetricsAddress, cliflags.ListenMetrics)
cliflagcfg.StringFlag(f, &proxyContext.RoutingRule, cliflags.RoutingRule)
cliflagcfg.StringFlag(f, &proxyContext.DirectoryAddr, cliflags.DirectoryAddr)
cliflagcfg.BoolFlag(f, &proxyContext.SkipVerify, cliflags.SkipVerify)
cliflagcfg.BoolFlag(f, &proxyContext.Insecure, cliflags.InsecureBackend)
cliflagcfg.DurationFlag(f, &proxyContext.ValidateAccessInterval, cliflags.ValidateAccessInterval)
cliflagcfg.DurationFlag(f, &proxyContext.PollConfigInterval, cliflags.PollConfigInterval)
cliflagcfg.DurationFlag(f, &proxyContext.ThrottleBaseDelay, cliflags.ThrottleBaseDelay)
cliflagcfg.BoolFlag(f, &proxyContext.DisableConnectionRebalancing, cliflags.DisableConnectionRebalancing)
}

// Multi-tenancy test directory command flags.
{
f := mtTestDirectorySvr.Flags()
cliflagcfg.IntFlag(f, &testDirectorySvrContext.port, cliflags.TestDirectoryListenPort)
cliflagcfg.StringFlag(f, &testDirectorySvrContext.certsDir, cliflags.TestDirectoryTenantCertsDir)
cliflagcfg.StringFlag(f, &testDirectorySvrContext.tenantBaseDir, cliflags.TestDirectoryTenantBaseDir)
cliflagcfg.StringFlag(f, &testDirectorySvrContext.kvAddrs, cliflags.KVAddrs)
}

// userfile upload command.
{
cliflagcfg.BoolFlag(userFileUploadCmd.Flags(), &userfileCtx.recursive, cliflags.Recursive)
Expand Down Expand Up @@ -1201,3 +1174,9 @@ func mtStartSQLFlagsInit(cmd *cobra.Command) error {
}
return nil
}

// RegisterFlags exists so that other packages can register flags using the
// Register<Type>FlagDepth functions and end up in a call frame in the cli
// package rather than the cliccl package to defeat the duplicate envvar
// registration logic.
func RegisterFlags(f func()) { f() }
Loading