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

config: use fsnotify to do config file reload #191

Merged
merged 10 commits into from
Jan 17, 2023

Conversation

xhebox
Copy link
Collaborator

@xhebox xhebox commented Jan 12, 2023

Signed-off-by: xhe xw897002528@gmail.com

What problem does this PR solve?

Issue Number: close #190

Problem Summary: The best online reload solution for tidb-operator. No more PR for tidb-operator after this adaption. It works forever.

What is changed: Mostly refactors in manager/config

  1. cobra outputs to stderr, small fixes
  2. remove a debugging fmt.Printf at logger in the previous PR
  3. move TestBase/TestConcurrency to namespace_test.go
  4. move e.get/set/list to namespace.go
  5. tiproxyctl and HTTP api changed. config/set accepts toml returns json. config/get just returns toml.
  6. config file is not read in cmd/tiproxy but responsible by manager/config
  7. fix default values of workdir to $PWD/work
  8. TestWatch is replaced by TestConfig

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
./bin/tiproxy --config conf/proxy.toml
edit it online
./bin/tiproxyctl config [get|set] online
  • No code

Notable changes

  • Has configuration change
  • Has HTTP API interfaces change (Don't forget to add the declarative for API)
  • Has tiproxyctl change
  • Other user behavior changes

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: xhe <xw897002528@gmail.com>
Comment on lines +40 to +41
rootCmd.SetOutput(os.Stdout)
rootCmd.SetErr(os.Stderr)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cobra all output defaults to stderr.

configFile := rootCmd.PersistentFlags().String("config", "", "proxy config file path")
logEncoder := rootCmd.PersistentFlags().String("log_encoder", "tidb", "log in format of tidb, console, or json")
logLevel := rootCmd.PersistentFlags().String("log_level", "", "log level")
_ = rootCmd.PersistentFlags().String("cluster_name", "tiproxy", "default cluster name, used to generate node name and differential clusters in dns discovery")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove useless cluster options.

lib/config/proxy.go Outdated Show resolved Hide resolved
pkg/manager/config/config.go Show resolved Hide resolved
logger := logger.CreateLoggerForTest(t)

etcd_cfg := embed.NewConfig()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Useless

})

t.Cleanup(cancel)

return cfgmgr, ctx
}

func TestBase(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to namespace_test.go, no modification.

)

func (e *ConfigManager) get(ctx context.Context, ns, key string) (KVValue, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved from manager.go

select {
case <-ctx.Done():
return
case ach := <-cfgch:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

listener.Accept() will block receiving changes from config channel, causing it blocking. Thus we do it in separate goroutines.

return
}
// setup config manager
if err = srv.ConfigManager.Init(ctx, lg.Named("config"), sctx.ConfigFile, &sctx.Overlay); err != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cfgmgr is inited much earlier to read the config file

@xhebox xhebox changed the title [WIP] config: use fsnotify to do config file reload config: use fsnotify to do config file reload Jan 12, 2023
@xhebox xhebox requested a review from djshow832 January 12, 2023 10:10
lib/config/proxy.go Outdated Show resolved Hide resolved
pkg/manager/config/config.go Show resolved Hide resolved
pkg/manager/config/config.go Show resolved Hide resolved
pkg/manager/config/config_test.go Outdated Show resolved Hide resolved
pkg/manager/config/config_test.go Outdated Show resolved Hide resolved
@xhebox xhebox mentioned this pull request Jan 12, 2023
8 tasks
xhebox and others added 3 commits January 12, 2023 22:59
Co-authored-by: djshow832 <zhangming@pingcap.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
pkg/manager/config/config.go Show resolved Hide resolved
pkg/manager/config/manager.go Outdated Show resolved Hide resolved
pkg/manager/config/manager.go Outdated Show resolved Hide resolved
pkg/manager/config/manager.go Outdated Show resolved Hide resolved
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
@xhebox xhebox requested a review from djshow832 January 16, 2023 05:12
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
@djshow832 djshow832 merged commit e201bdf into pingcap:main Jan 17, 2023
@xhebox xhebox deleted the dedicate_6 branch March 7, 2023 03:18
xhebox added a commit to xhebox/TiProxy that referenced this pull request Mar 7, 2023
xhebox added a commit to xhebox/TiProxy that referenced this pull request Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hot config file reloading
2 participants