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

[RFC] Standardized viper framework for vitess configuration parameters #11456

Merged
merged 100 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
115da66
Taking a stab at a way to standardize viper usage
Oct 9, 2022
5b40343
port go/trace to viper-bound flags
Oct 10, 2022
41dd81c
add viperget subpackage
Oct 12, 2022
893e000
add viperget subpackage
Oct 12, 2022
6a65f86
Ensure viper values are bound prior to access
Oct 13, 2022
c107a39
wip: workin on my docs
Oct 13, 2022
35365b2
WIP: config reading
Oct 17, 2022
1ad9054
lol whoops
Oct 17, 2022
16931c8
wip: vipersync for threadsafe(ish) watched configs
Oct 18, 2022
714f38f
Some threadsafety improvements, not quite there yet
Oct 19, 2022
a53efce
Add Subscribe/Notify api so live configs don't need to poll for updates
Oct 20, 2022
c13fb66
fix adapter signature to what i meant the first time
Oct 24, 2022
d56f4ac
begrudgingly come crawling back to an RWMutex implementation
Oct 24, 2022
a7f61a3
adjust public Bind method (and only the public version) to allow seco…
Oct 25, 2022
ae1eb1c
add Error handling type for reading in configs
Oct 25, 2022
21f2411
change vipersync Watch signature, also ensure we read in the config a…
Oct 25, 2022
daae99e
refactor vipersync.Viper a bit
Oct 26, 2022
b0566d7
More refactors to vipersync:
Oct 26, 2022
c6db943
WIP WIP WIP checkpointing before i blow away this api for a new version
Oct 31, 2022
601c62d
wip on v2 of viperutil api
Nov 8, 2022
26cc551
WIP WIP WIP: update trace pkg to use new api (mostly)
Nov 8, 2022
4d3fdca
WIP: example of dynamic variable and getting notified of config changes
Nov 8, 2022
bada60a
fix default workdir override
Nov 8, 2022
d8ee263
fix watch for when no config file was used
Nov 8, 2022
ab160d1
provide mechanism to stub values for tests
Nov 9, 2022
9d7f092
update usage in go/trace to new api
Nov 9, 2022
9710c89
update azblobbackupstorage to use new API
Nov 10, 2022
0f4a6c6
fix config-handling parsing
Nov 10, 2022
1cb6ef5
add test for config watching
Nov 10, 2022
99dba7f
cleaning up some TODO markers
Nov 10, 2022
57366b0
starting to work on doc comments
Nov 10, 2022
6722cf2
more docs
Nov 12, 2022
02a976d
document GetPath and add example test
Nov 12, 2022
cabbc13
copyright headers
Nov 12, 2022
9c20ba9
finish switch case for handling config-file finding errors
Nov 12, 2022
5b48d5f
document sync subpackage
Nov 12, 2022
383ab10
document config stuff
Nov 12, 2022
1b0aafb
more docs
Nov 13, 2022
c9ea5cc
document internal/log
Nov 13, 2022
f33c249
document Options and Configure
Nov 15, 2022
35b4328
rename
Nov 15, 2022
59c7c4c
more test cases for GetFuncForType
Nov 15, 2022
2c77187
more cases
Nov 15, 2022
3c67de2
struct support
Nov 15, 2022
0574e0d
support complex types
Nov 15, 2022
fe994d4
map types, realizing we cannot support interfaces
Nov 16, 2022
0b5e4c1
finish tests
Nov 16, 2022
0bcbb4f
preserve usage for seconds decoder
Nov 16, 2022
37d42de
more docs
Nov 16, 2022
02c843b
bye bye v1
Nov 16, 2022
43b114b
mv go/viperutil/v2 => go/viperutil and update everythingggggggggg
Nov 16, 2022
4d5151f
cleanup todo that is done
Nov 18, 2022
1d57625
start documenting new stuff
Nov 20, 2022
1df178c
delete most of the old docs
Nov 20, 2022
d5ff18a
flaggy flag docs
Nov 21, 2022
2410b5d
config file stuff
Nov 21, 2022
4b560ff
docs are done
Nov 21, 2022
9ad7be5
go mod tidy
Nov 21, 2022
7e812e0
gofmt 🙃
Nov 21, 2022
5d4b8e0
document Debug func
Dec 6, 2022
082d9a9
document StringEnum types
Dec 6, 2022
8349ea0
add debug endpoint to see the full config
Mar 28, 2023
2246d6a
add registry.Combined
May 10, 2023
60d0ea1
add Set to Value interface and implementations
May 10, 2023
79d06ae
support re-persistence of in-memory changes for existing debugenv APIs
May 10, 2023
124a745
bugfixes to config persistence
May 14, 2023
625135e
fix sync loading to work with re-persistence
May 14, 2023
cf8b229
make discovery.min_number_serving_vttablets a dynamic viper value
May 14, 2023
cbf55ea
update comments
May 15, 2023
8ff1866
configure the rest of discovery replicationlag settings
May 15, 2023
fa2d48f
remove example code
May 15, 2023
fe2792d
fix bindings now that live gets reset
May 16, 2023
432fd6f
default to ignore
May 16, 2023
fdeb7d4
return empty cancel func to not panic
May 16, 2023
f942159
no double registrations
May 16, 2023
674c256
update flag testdata
May 16, 2023
860c865
dumb dumb
May 16, 2023
c1a77da
templatize (which requires further escaping)
May 16, 2023
d4bd4b5
lint
May 16, 2023
cff1efa
docs
May 17, 2023
fbf2989
Update doc/viper/viper.md
ajm188 May 19, 2023
dae6669
back to "warn on default", update tests to handle it
May 19, 2023
b76a4fe
flag testdata
May 19, 2023
485d09f
fix filtering quirk
May 19, 2023
a00b9a4
better newline handling to avoid double-newline at end
May 20, 2023
67cd23d
refactor to colocate persistence with the sync viper
May 21, 2023
ad52e4e
forgot to copy over non-blocking send
May 22, 2023
2ee8df9
Update doc/viper/viper.md
ajm188 May 23, 2023
2c9f4be
net.JoinHostPort
May 23, 2023
88def22
reorder imports
May 23, 2023
21e0350
cleanup TODO panic
May 23, 2023
cb80b7b
error string formatting
May 23, 2023
0598cbd
update comments
May 23, 2023
be0c895
copyright year update
May 23, 2023
554c38d
delete empty file
May 23, 2023
63ba912
extract function for initializing the viper config
May 23, 2023
52f94b4
update example package
May 23, 2023
098f0d2
more docs
May 23, 2023
dee064f
vterrors
May 23, 2023
0da240e
bigger time interval
May 24, 2023
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
324 changes: 324 additions & 0 deletions doc/viper/viper.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/kr/pretty v0.3.1
github.com/kr/text v0.2.0
github.com/mitchellh/mapstructure v1.5.0
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249
github.com/spf13/jwalterweatherman v1.1.0
github.com/xlab/treeprint v1.2.0
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201
golang.org/x/sync v0.1.0
Expand Down Expand Up @@ -164,7 +166,6 @@ require (
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand All @@ -179,7 +180,6 @@ require (
github.com/secure-systems-lab/go-securesystemslib v0.4.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
Expand Down
25 changes: 21 additions & 4 deletions go/flags/endtoend/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ package flags

import (
"bytes"
_ "embed"
"os"
ajm188 marked this conversation as resolved.
Show resolved Hide resolved
"os/exec"
"testing"
"text/template"

"vitess.io/vitess/go/test/utils"
_ "embed"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/test/utils"
)

var (
Expand Down Expand Up @@ -105,16 +108,30 @@ var (
)

func TestHelpOutput(t *testing.T) {
wd, err := os.Getwd()
require.NoError(t, err)

args := []string{"--help"}
for binary, helptext := range helpOutput {
t.Run(binary, func(t *testing.T) {
tmpl, err := template.New(binary).Parse(helptext)
require.NoError(t, err)

var buf bytes.Buffer
err = tmpl.Execute(&buf, struct {
Workdir string
}{
Workdir: wd,
})
require.NoError(t, err)

cmd := exec.Command(binary, args...)
output := bytes.Buffer{}
cmd.Stderr = &output
cmd.Stdout = &output
err := cmd.Run()
err = cmd.Run()
require.NoError(t, err)
utils.MustMatch(t, helptext, output.String())
utils.MustMatch(t, buf.String(), output.String())
})
}
}
142 changes: 74 additions & 68 deletions go/flags/endtoend/mysqlctl.txt

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions go/flags/endtoend/mysqlctld.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Usage of mysqlctld:
--app_idle_timeout duration Idle timeout for app connections (default 1m0s)
--app_pool_size int Size of the connection pool for app connections (default 40)
--catch-sigpipe catch and ignore SIGPIPE on stdout and stderr if specified
--config-file string Full path of the config file (with extension) to use. If set, --config-path, --config-type, and --config-name are ignored.
--config-file-not-found-handling ConfigFileNotFoundHandling Behavior when a config file is not found. (Options: error, exit, ignore, warn) (default warn)
--config-name string Name of the config file (without extension) to search for. (default "vtconfig")
--config-path strings Paths to search for config files in. (default [{{.Workdir}}])
--config-persistence-min-interval duration minimum interval between persisting dynamic config changes back to disk (if no change has occurred, nothing is done). (default 1s)
--config-type string Config file type (omit to infer config type from file extension).
--db-credentials-file string db credentials file; send SIGHUP to reload this file
--db-credentials-server string db credentials server type ('file' - file implementation; 'vault' - HashiCorp Vault implementation) (default "file")
--db-credentials-vault-addr string URL to Vault server
Expand Down
42 changes: 24 additions & 18 deletions go/flags/endtoend/vtaclcheck.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
Usage of vtaclcheck:
--acl-file string The path of the JSON ACL file to check
--alsologtostderr log to standard error as well as files
-h, --help display usage and exit
--keep_logs duration keep logs for this long (using ctime) (zero to keep forever)
--keep_logs_by_mtime duration keep logs for this long (using mtime) (zero to keep forever)
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--log_err_stacks log stack traces for errors
--log_rotate_max_size uint size in bytes at which logs are rotated (glog.MaxSize) (default 1887436800)
--logtostderr log to standard error instead of files
--pprof strings enable profiling
--purge_logs_interval duration how often try to remove old logs (default 1h0m0s)
--security_policy string the name of a registered security policy to use for controlling access to URLs - empty means allow all for anyone (built-in policies: deny-all, read-only)
--static-auth-file string The path of the auth_server_static JSON file to check
--stderrthreshold severity logs at or above this threshold go to stderr (default 1)
--v Level log level for V logs
-v, --version print binary version
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
--acl-file string The path of the JSON ACL file to check
--alsologtostderr log to standard error as well as files
--config-file string Full path of the config file (with extension) to use. If set, --config-path, --config-type, and --config-name are ignored.
--config-file-not-found-handling ConfigFileNotFoundHandling Behavior when a config file is not found. (Options: error, exit, ignore, warn) (default warn)
--config-name string Name of the config file (without extension) to search for. (default "vtconfig")
--config-path strings Paths to search for config files in. (default [{{.Workdir}}])
--config-persistence-min-interval duration minimum interval between persisting dynamic config changes back to disk (if no change has occurred, nothing is done). (default 1s)
--config-type string Config file type (omit to infer config type from file extension).
Comment on lines +6 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth opting in specific binaries into viper? IOW, do we really need utility binaries like this one (and zkctl etc.) to have the new functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 i don't have a strong preference either way. we'd just need to move the flag regstration from OnParse to OnParseFor here

-h, --help display usage and exit
--keep_logs duration keep logs for this long (using ctime) (zero to keep forever)
--keep_logs_by_mtime duration keep logs for this long (using mtime) (zero to keep forever)
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--log_err_stacks log stack traces for errors
--log_rotate_max_size uint size in bytes at which logs are rotated (glog.MaxSize) (default 1887436800)
--logtostderr log to standard error instead of files
--pprof strings enable profiling
--purge_logs_interval duration how often try to remove old logs (default 1h0m0s)
--security_policy string the name of a registered security policy to use for controlling access to URLs - empty means allow all for anyone (built-in policies: deny-all, read-only)
--static-auth-file string The path of the auth_server_static JSON file to check
--stderrthreshold severity logs at or above this threshold go to stderr (default 1)
--v Level log level for V logs
-v, --version print binary version
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
Loading