8000 config: dynamic proxy config by xhebox · Pull Request #56 · pingcap/tiproxy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

config: dynamic proxy config #56

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

Merged
merged 16 commits into from
Aug 26, 2022
Merged

config: dynamic proxy config #56

merged 16 commits into from
Aug 26, 2022

Conversation

xhebox
Copy link
Collaborator
@xhebox xhebox commented Aug 24, 2022

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

What problem does this PR solve?

Issue Number: ref #11

Problem Summary: Dynamic config keep alive and max connections for proxy server.

What is changed and how it works:

  1. In short, added background service for config manager to poll online config regularlly/watch etcd event. It will then be applied to the running server.
  2. API return value minor improvement. Added /api/admin/config/proxy for online proxy config.
  3. Configs have yaml, toml, json all struct tags
  4. errors.Wrap(f) will return nil for nil error
  5. Makefile minor improvement

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
./bin/weirproxy ...
echo '{"max_connections": 0}' | ./bin/weirctl config proxy
zero connection error
echo '{"max_connections": 1}' | ./bin/weirctl config proxy

start two mysql client, and one of them will be rejected by the server
  • No code

Notable changes

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

Release note

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

Support dynamic configuration for some proxy server options

Signed-off-by: xhe <xw897002528@gmail.com>
@xhebox xhebox requested a review from djshow832 August 24, 2022 08:04
Signed-off-by: xhe <xw897002528@gmail.com>
@xhebox xhebox mentioned this pull request Aug 24, 2022
Signed-off-by: xhe <xw897002528@gmail.com>
Copy link
Collaborator
@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

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

https://github.com/pingcap/TiProxy/blob/a9b15514f5f0bc282b35678df69b0ab07f053b61/cmd/weirctl/util.go#L46
I think it should be for _, i := range rand.Perm(len(bctx.CUrls)) {?

@xhebox
Copy link
Collaborator Author
xhebox commented Aug 24, 2022

https://github.com/pingcap/TiProxy/blob/a9b15514f5f0bc282b35678df69b0ab07f053b61/cmd/weirctl/util.go#L46

I think it should be for _, i := range rand.Perm(len(bctx.CUrls)) {?

Nope, I am using it as bctx.CUrls[i]. If you like this style, I can change it.

@djshow832
Copy link
Collaborator

https://github.com/pingcap/TiProxy/blob/a9b15514f5f0bc282b35678df69b0ab07f053b61/cmd/weirctl/util.go#L46

I think it should be for _, i := range rand.Perm(len(bctx.CUrls)) {?

Nope, I am using it as bctx.CUrls[i]. If you like this style, I can change it.

for i := range rand.Perm(len(bctx.CUrls)) {
	req.URL.Host = bctx.CUrls[i]

is just equivalent to

for _, host := bctx.CUrls {
	req.URL.Host = host

because i is always an increasing integer. It's the index of the array rand.Perm(len(bctx.CUrls)).

Co-authored-by: djshow832 <zhangming@pingcap.com>
@xhebox
Copy link
Collaborator Author
xhebox commented Aug 24, 2022

https://github.com/pingcap/TiProxy/blob/a9b15514f5f0bc282b35678df69b0ab07f053b61/cmd/weirctl/util.go#L46

I think it should be for _, i := range rand.Perm(len(bctx.CUrls)) {?

Nope, I am using it as bctx.CUrls[i]. If you like this style, I can change it.

for i := range rand.Perm(len(bctx.CUrls)) {
	req.URL.Host = bctx.CUrls[i]

is just equivalent to

for _, host := bctx.CUrls {
	req.URL.Host = host

because i is always an increasing integer. It's the index of the array rand.Perm(len(bctx.CUrls)).

Addressed.

xhebox added 4 commits August 24, 2022 20:51
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
@xhebox xhebox requested a review from djshow832 August 24, 2022 14:52
Signed-off-by: xhe <xw897002528@gmail.com>
xhebox and others added 4 commits August 25, 2022 11:31
Co-authored-by: djshow832 <zhangming@pingcap.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
@xhebox xhebox requested a review from djshow832 August 25, 2022 03:47
}

type ConfigManager struct {
IgnoreWrongNamespace bool `yaml:"ignore_wrong_namespace"`
IgnoreWrongNamespace bool `yaml:"ignore_wrong_namespace" toml:"ignore_wrong_namespace" json:"ignore_wrong_namespace"`
WatchInterval string `yaml:"watch_interval" toml:"watch_interval" json:"watch_interval"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought about this, it's hard to explain what this really means to the user.
For common cases, the config will be refreshed once updated. This interval is only used for defensive programming.
As for TiDB, the refresh interval for privileges and global variables are not exposed to users either, and nobody complains about it.

Copy link
Collaborator Author
@xhebox xhebox Aug 25, 2022

Choose a reason for hiding this comment

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

We could categorize them into KNOW WHAT YOU ARE DOING options and provide a resonable default. If one don't understand, just don't set.

You can choose to use the default good config, or make one step further into the internal. That is users' freedom. BTW, these are possibly useful for debugging online.

Copy link
Collaborator Author
@xhebox xhebox Aug 25, 2022

Choose a reason for hiding this comment

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

As for TiDB, the refresh interval for privileges and global variables are not exposed to users either, and nobody complains about it.

There is no choice. They don't even know about that. Maybe they have a guess in their mind, and thought it is correct. If we have a documentation said the priv interval is XXX. Maybe someone will complain that it is too short or too long.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As for TiDB, the refresh interval for privileges and global variables are not exposed to users either, and nobody complains about it.

There is no choice. They don't even know about that. Maybe they have a guess in their mind, and thought it is correct. If we have a documentation said the priv interval is XXX. Maybe someone will complain that it is too short or too long.

If we make it as a config, we must document it, and then users are confused and complain. I sometimes encounter the situation where a user saw a config and doesn't understand what it means and then asks us. It just brings us trouble. If we're removing it, it again brings compatibility problems.

Copy link
Collaborator Author
@xhebox xhebox Aug 25, 2022

Choose a reason for hiding this comment

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

I would not consider it a problem. First of all, TiProxy will have much less options. It is much simpler and not that hard to understand.

My point is that documentation of complex options can be highlighted, in another section or another page with a large NOTE. The example for these options can be separated into another file, or commented by default.

If users feel normal options are enough, they surely won't dig deep into these complicated options. Moreover, we recommend you not to use these options unless you understand it. TiDB docs has none of these guidance or classifications. And description for system variables usually do not have any external link to the related page or doc.

Signed-off-by: xhe <xw897002528@gmail.com>
@xhebox xhebox requested a review from djshow832 August 25, 2022 06:52
xhebox added 2 commits August 25, 2022 14:55
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
@djshow832 djshow832 merged commit bacaced into pingcap:main Aug 26, 2022
@xhebox xhebox deleted the config_2 branch August 26, 2022 03:10
This was referenced Aug 31, 2022
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.

2 participants
0