-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
mysql: Refactor out usage of servenv #14732
mysql: Refactor out usage of servenv #14732
Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
vtgate.RegisterPluginInitializer(func() { mysql.InitAuthServerClientCert() }) | ||
servenv.OnParseFor("vtgate", func(fs *pflag.FlagSet) { | ||
fs.StringVar(&clientcertAuthMethod, "mysql_clientcert_auth_method", string(mysql.MysqlClearPassword), "client-side authentication method to use. Supported values: mysql_clear_password, dialog.") | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one and others still have the same flags, but now moved into vtgate
which I think is a better place anyway to have them set up.
fs.StringVar(&mysqlAuthServerStaticFile, "mysql_auth_server_static_file", "", "JSON File to read the users/passwords from.") | ||
fs.StringVar(&mysqlAuthServerStaticString, "mysql_auth_server_static_string", "", "JSON representation of the users/passwords config.") | ||
fs.DurationVar(&mysqlAuthServerStaticReloadInterval, "mysql_auth_static_reload_interval", 0, "Ticker to reload credentials") | ||
fs.DurationVar(&mysqlServerFlushDelay, "mysql_server_flush_delay", mysqlServerFlushDelay, "Delay after which buffered response will be flushed to the client.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag was in a very wrong place. It was in the auth plugin, but it's a MySQL protocol config flag! It was moved to the vtgate mysql plugin server instead which seems much more appropriate.
@@ -263,6 +263,8 @@ func getHostPort(t *testing.T, a net.Addr) (string, int) { | |||
return host, port | |||
} | |||
|
|||
const mysqlVersion = "8.0.30-Vitess" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only used for testing here, so better to just copy a static value than depending on the whole servenv
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are a few places i saw where you missed using this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajm188 I'll fix up the ones I missed, but it can't be used in all cases, since this is in the test file only. That's deliberate so it doesn't get used accidentally.
@@ -97,6 +99,7 @@ func registerPluginFlags(fs *pflag.FlagSet) { | |||
fs.DurationVar(&mysqlQueryTimeout, "mysql_server_query_timeout", mysqlQueryTimeout, "mysql query timeout") | |||
fs.BoolVar(&mysqlConnBufferPooling, "mysql-server-pool-conn-read-buffers", mysqlConnBufferPooling, "If set, the server will pool incoming connection read buffers") | |||
fs.DurationVar(&mysqlKeepAlivePeriod, "mysql-server-keepalive-period", mysqlKeepAlivePeriod, "TCP period between keep-alives") | |||
fs.DurationVar(&mysqlServerFlushDelay, "mysql_server_flush_delay", mysqlServerFlushDelay, "Delay after which buffered response will be flushed to the client.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has underscores since this moves the flag to its appropriate location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can also define a new flag and fs.MarkDeprecated
this one to support both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep it this way. Dunno if we have a generic plan to do this? Since I wouldn't want to do it just for a one off flag then which only happens due to a refactor that for most end users is not really relevant anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah let's not do a one-off flag rename/deprecation. We should tackle all of them together.
@@ -1470,12 +1472,10 @@ func TestParseConnAttrs(t *testing.T) { | |||
} | |||
|
|||
func TestServerFlush(t *testing.T) { | |||
defer func(saved time.Duration) { mysqlServerFlushDelay = saved }(mysqlServerFlushDelay) | |||
mysqlServerFlushDelay = 10 * time.Millisecond |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removes global state modification which is a great win imho.
The servenv package is something that is use for server environments like vtgate, vttablet etc. But the go/mysql package should really be independent code for things like the MySQL protocol bits. This change refactors things so that go/mysql doesn't depend anymore on servenv. This makes it easier to be used as a library for example. The remaining bits here are in collations, which is something to tackle separately as it's very invasive. Signed-off-by: Dirkjan Bussink <[email protected]>
a84ee7a
to
1e8b3b3
Compare
vtgate.RegisterPluginInitializer(func() { ldapauthserver.Init() }) | ||
Main.Flags().StringVar(&ldapAuthConfigFile, "mysql_ldap_auth_config_file", "", "JSON File from which to read LDAP server config.") | ||
Main.Flags().StringVar(&ldapAuthConfigString, "mysql_ldap_auth_config_string", "", "JSON representation of LDAP server config.") | ||
Main.Flags().StringVar(&ldapAuthMethod, "mysql_ldap_auth_method", string(mysql.MysqlClearPassword), "client-side authentication method to use. Supported values: mysql_clear_password, dialog.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajm188 Had to use Main.Flags()
here since the on parse callbacks don't work as it's too late since cli.go
init
s first, but dunno if this is the right fix then? Or if there's another way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that's what we're currently doing? https://github.com/vitessio/vitess/blob/main/go/cmd/vtgate/cli/cli.go#L187-L189 i'm not sure if that answers your question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good! few small things but lgtm after those
vtgate.RegisterPluginInitializer(func() { ldapauthserver.Init() }) | ||
Main.Flags().StringVar(&ldapAuthConfigFile, "mysql_ldap_auth_config_file", "", "JSON File from which to read LDAP server config.") | ||
Main.Flags().StringVar(&ldapAuthConfigString, "mysql_ldap_auth_config_string", "", "JSON representation of LDAP server config.") | ||
Main.Flags().StringVar(&ldapAuthMethod, "mysql_ldap_auth_method", string(mysql.MysqlClearPassword), "client-side authentication method to use. Supported values: mysql_clear_password, dialog.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that's what we're currently doing? https://github.com/vitessio/vitess/blob/main/go/cmd/vtgate/cli/cli.go#L187-L189 i'm not sure if that answers your question
@@ -327,7 +327,7 @@ func FuzzTLSServer(data []byte) int { | |||
Password: "password1", | |||
}} | |||
defer authServer.close() | |||
l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false) | |||
l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, 0, "8.0.30-Vitess") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, this one can't use it as it's not in the test file(s).
@@ -263,6 +263,8 @@ func getHostPort(t *testing.T, a net.Addr) (string, int) { | |||
return host, port | |||
} | |||
|
|||
const mysqlVersion = "8.0.30-Vitess" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are a few places i saw where you missed using this
@@ -97,6 +99,7 @@ func registerPluginFlags(fs *pflag.FlagSet) { | |||
fs.DurationVar(&mysqlQueryTimeout, "mysql_server_query_timeout", mysqlQueryTimeout, "mysql query timeout") | |||
fs.BoolVar(&mysqlConnBufferPooling, "mysql-server-pool-conn-read-buffers", mysqlConnBufferPooling, "If set, the server will pool incoming connection read buffers") | |||
fs.DurationVar(&mysqlKeepAlivePeriod, "mysql-server-keepalive-period", mysqlKeepAlivePeriod, "TCP period between keep-alives") | |||
fs.DurationVar(&mysqlServerFlushDelay, "mysql_server_flush_delay", mysqlServerFlushDelay, "Delay after which buffered response will be flushed to the client.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can also define a new flag and fs.MarkDeprecated
this one to support both
@@ -348,7 +348,7 @@ func TestGracefulShutdown(t *testing.T) { | |||
|
|||
vh := newVtgateHandler(&VTGate{executor: executor, timings: timings, rowsReturned: rowsReturned, rowsAffected: rowsAffected}) | |||
th := &testHandler{} | |||
listener, err := mysql.NewListener("tcp", "127.0.0.1:", mysql.NewAuthServerNone(), th, 0, 0, false, false, 0) | |||
listener, err := mysql.NewListener("tcp", "127.0.0.1:", mysql.NewAuthServerNone(), th, 0, 0, false, false, 0, 0, "8.0.30-Vitess") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed one here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not an exposed constant, so it can't be used here. I can turn these two into their own constant? I thought about it and didn't know if it was worth it for 2 or not then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah tests-only seems fine this way
@@ -378,7 +378,7 @@ func TestGracefulShutdownWithTransaction(t *testing.T) { | |||
|
|||
vh := newVtgateHandler(&VTGate{executor: executor, timings: timings, rowsReturned: rowsReturned, rowsAffected: rowsAffected}) | |||
th := &testHandler{} | |||
listener, err := mysql.NewListener("tcp", "127.0.0.1:", mysql.NewAuthServerNone(), th, 0, 0, false, false, 0) | |||
listener, err := mysql.NewListener("tcp", "127.0.0.1:", mysql.NewAuthServerNone(), th, 0, 0, false, false, 0, 0, "8.0.30-Vitess") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall. Not looking forward to fixing collations
.
@@ -80,7 +51,7 @@ type AuthServerVault struct { | |||
} | |||
|
|||
// InitAuthServerVault - entrypoint for initialization of Vault AuthServer implementation | |||
func InitAuthServerVault() { | |||
func InitAuthServerVault(vaultAddr string, vaultTimeout time.Duration, vaultCACert, vaultPath string, vaultCacheTTL time.Duration, vaultTokenFile, vaultRoleID, vaultRoleSecretIDFile, vaultRoleMountPoint string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are quite a few args. Maybe enough that we should construct a struct out of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but we already use the whole list one call site down as well. So I don't consider it to really be anything significantly worse than before.
Signed-off-by: Dirkjan Bussink <[email protected]>
The servenv package is something that is use for server environments like vtgate, vttablet etc. But the go/mysql package should really be independent code for things like the MySQL protocol bits.
This change refactors things so that go/mysql doesn't depend anymore on servenv. This makes it easier to be used as a library for example.
The remaining bits here are in collations, which is something to tackle separately as it's very invasive.
Related Issue(s)
Part of #14717
Checklist