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

Remove all package-level flags #175

Merged
merged 2 commits into from
Aug 4, 2022
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
6 changes: 3 additions & 3 deletions go/mysql/auth_server_clientcert.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/dolthub/vitess/go/vt/log"
)

var clientcertAuthMethod = flag.String("mysql_clientcert_auth_method", MysqlClearPassword, "client-side authentication method to use. Supported values: mysql_clear_password, dialog.")
var clientcertAuthMethod = MysqlClearPassword

type AuthServerClientCert struct {
Method string
Expand All @@ -36,11 +36,11 @@ func InitAuthServerClientCert() {
log.Info("Not configuring AuthServerClientCert because mysql_server_ssl_ca is empty")
return
}
if *clientcertAuthMethod != MysqlClearPassword && *clientcertAuthMethod != MysqlDialog {
if clientcertAuthMethod != MysqlClearPassword && clientcertAuthMethod != MysqlDialog {
log.Fatalf("Invalid mysql_clientcert_auth_method value: only support mysql_clear_password or dialog")
}
ascc := &AuthServerClientCert{
Method: *clientcertAuthMethod,
Method: clientcertAuthMethod,
}
RegisterAuthServerImpl("clientcert", ascc)
}
Expand Down
13 changes: 6 additions & 7 deletions go/mysql/auth_server_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package mysql
import (
"bytes"
"encoding/json"
"flag"
"net"
"os"
"os/signal"
Expand All @@ -34,9 +33,9 @@ import (
)

var (
mysqlAuthServerStaticFile = flag.String("mysql_auth_server_static_file", "", "JSON File to read the users/passwords from.")
mysqlAuthServerStaticString = flag.String("mysql_auth_server_static_string", "", "JSON representation of the users/passwords config.")
mysqlAuthServerStaticReloadInterval = flag.Duration("mysql_auth_static_reload_interval", 0, "Ticker to reload credentials")
mysqlAuthServerStaticFile string = ""
mysqlAuthServerStaticString string = ""
mysqlAuthServerStaticReloadInterval time.Duration = 0
)

const (
Expand Down Expand Up @@ -89,18 +88,18 @@ type AuthServerStaticEntry struct {
// InitAuthServerStatic Handles initializing the AuthServerStatic if necessary.
func InitAuthServerStatic() {
// Check parameters.
if *mysqlAuthServerStaticFile == "" && *mysqlAuthServerStaticString == "" {
if mysqlAuthServerStaticFile == "" && mysqlAuthServerStaticString == "" {
// Not configured, nothing to do.
log.Infof("Not configuring AuthServerStatic, as mysql_auth_server_static_file and mysql_auth_server_static_string are empty")
return
}
if *mysqlAuthServerStaticFile != "" && *mysqlAuthServerStaticString != "" {
if mysqlAuthServerStaticFile != "" && mysqlAuthServerStaticString != "" {
// Both parameters specified, can only use one.
log.Fatalf("Both mysql_auth_server_static_file and mysql_auth_server_static_string specified, can only use one.")
}

// Create and register auth server.
RegisterAuthServerStaticFromParams(*mysqlAuthServerStaticFile, *mysqlAuthServerStaticString, *mysqlAuthServerStaticReloadInterval)
RegisterAuthServerStaticFromParams(mysqlAuthServerStaticFile, mysqlAuthServerStaticString, mysqlAuthServerStaticReloadInterval)
}

// NewAuthServerStatic returns a new AuthServerStatic, reading from |file| or
Expand Down
8 changes: 4 additions & 4 deletions go/mysql/auth_server_static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ func TestStaticConfigHUPWithRotation(t *testing.T) {
t.Fatalf("couldn't create temp file: %v", err)
}
defer os.Remove(tmpFile.Name())
*mysqlAuthServerStaticFile = tmpFile.Name()
mysqlAuthServerStaticFile = tmpFile.Name()

savedReloadInterval := *mysqlAuthServerStaticReloadInterval
defer func() { *mysqlAuthServerStaticReloadInterval = savedReloadInterval }()
*mysqlAuthServerStaticReloadInterval = 10 * time.Millisecond
savedReloadInterval := mysqlAuthServerStaticReloadInterval
defer func() { mysqlAuthServerStaticReloadInterval = savedReloadInterval }()
mysqlAuthServerStaticReloadInterval = 10 * time.Millisecond

oldStr := "str1"
jsonConfig := fmt.Sprintf("{\"%s\":[{\"Password\":\"%s\"}]}", oldStr, oldStr)
Expand Down
5 changes: 0 additions & 5 deletions go/mysql/query_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package mysql

import (
"context"
"flag"
"math/rand"
"net"
"strings"
Expand All @@ -27,10 +26,6 @@ import (

var testReadConnBufferSize = DefaultConnBufferSize

func init() {
flag.IntVar(&testReadConnBufferSize, "test.read_conn_buffer_size", DefaultConnBufferSize, "buffer size for reads from connections in tests")
}

const benchmarkQueryPrefix = "benchmark "

func benchmarkQuery(b *testing.B, threads int, query string) {
Expand Down
19 changes: 9 additions & 10 deletions go/stats/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ package stats
import (
"bytes"
"expvar"
"flag"
"fmt"
"strconv"
"sync"
Expand All @@ -39,9 +38,9 @@ import (
"github.com/dolthub/vitess/go/vt/log"
)

var emitStats = flag.Bool("emit_stats", false, "true iff we should emit stats to push-based monitoring/stats backends")
var statsEmitPeriod = flag.Duration("stats_emit_period", time.Duration(60*time.Second), "Interval between emitting stats to all registered backends")
var statsBackend = flag.String("stats_backend", "", "The name of the registered push-based monitoring/stats backend to use")
var emitStats = false
var statsEmitPeriod = time.Duration(60 * time.Second)
var statsBackend = ""

// NewVarHook is the type of a hook to export variables in a different way
type NewVarHook func(name string, v expvar.Var)
Expand Down Expand Up @@ -122,7 +121,7 @@ func RegisterPushBackend(name string, backend PushBackend) {
log.Fatalf("PushBackend %s already exists; can't register the same name multiple times", name)
}
pushBackends[name] = backend
if *emitStats {
if emitStats {
// Start a single goroutine to emit stats periodically
once.Do(func() {
go emitToBackend(statsEmitPeriod)
Expand All @@ -132,19 +131,19 @@ func RegisterPushBackend(name string, backend PushBackend) {

// emitToBackend does a periodic emit to the selected PushBackend. If a push fails,
// it will be logged as a warning (but things will otherwise proceed as normal).
func emitToBackend(emitPeriod *time.Duration) {
ticker := time.NewTicker(*emitPeriod)
func emitToBackend(emitPeriod time.Duration) {
ticker := time.NewTicker(emitPeriod)
defer ticker.Stop()
for range ticker.C {
backend, ok := pushBackends[*statsBackend]
backend, ok := pushBackends[statsBackend]
if !ok {
log.Errorf("No PushBackend registered with name %s", *statsBackend)
log.Errorf("No PushBackend registered with name %s", statsBackend)
return
}
err := backend.PushAll()
if err != nil {
// TODO(aaijazi): This might cause log spam...
log.Warningf("Pushing stats to backend %v failed: %v", *statsBackend, err)
log.Warningf("Pushing stats to backend %v failed: %v", statsBackend, err)
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions go/vt/sqlparser/truncate_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ limitations under the License.

package sqlparser

import (
"flag"
)

var (
// TruncateUILen truncate queries in debug UIs to the given length. 0 means unlimited.
TruncateUILen = flag.Int("sql-max-length-ui", 512, "truncate queries in debug UIs to the given length (default 512)")
TruncateUILen = 512

// TruncateErrLen truncate queries in error logs to the given length. 0 means unlimited.
TruncateErrLen = flag.Int("sql-max-length-errors", 0, "truncate queries in error logs to the given length (default unlimited)")
TruncateErrLen = 0
)

func truncateQuery(query string, max int) string {
Expand All @@ -41,12 +37,12 @@ func truncateQuery(query string, max int) string {
// TruncateForUI is used when displaying queries on various Vitess status pages
// to keep the pages small enough to load and render properly
func TruncateForUI(query string) string {
return truncateQuery(query, *TruncateUILen)
return truncateQuery(query, TruncateUILen)
}

// TruncateForLog is used when displaying queries as part of error logs
// to avoid overwhelming logging systems with potentially long queries and
// bind value data.
func TruncateForLog(query string) string {
return truncateQuery(query, *TruncateErrLen)
return truncateQuery(query, TruncateErrLen)
}
5 changes: 0 additions & 5 deletions go/vt/vterrors/vterrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ package vterrors

import (
"context"
"flag"
"fmt"
"io"

Expand All @@ -98,10 +97,6 @@ import (
// embedded stack trace in the output.
var LogErrStacks bool

func init() {
flag.BoolVar(&LogErrStacks, "log_err_stacks", false, "log stack traces for errors")
}

// New returns an error with the supplied message.
// New also records the stack trace at the point it was called.
func New(code vtrpcpb.Code, message string) error {
Expand Down