From 7abac2e3af23c3e59044e3c130120840e1805001 Mon Sep 17 00:00:00 2001 From: Przemyslaw Kadej Date: Fri, 8 Apr 2022 23:15:17 +0200 Subject: [PATCH 1/6] PMM-4879 Added support for defaultsfile parameter. --- commands/management/add_mysql.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/commands/management/add_mysql.go b/commands/management/add_mysql.go index 9327812e..e5b277ce 100644 --- a/commands/management/add_mysql.go +++ b/commands/management/add_mysql.go @@ -93,6 +93,7 @@ type addMySQLCommand struct { ServiceName string Username string Password string + DefaultsFile string AgentPassword string Environment string Cluster string @@ -201,6 +202,7 @@ func (cmd *addMySQLCommand) Run() (commands.Result, error) { ReplicationSet: cmd.ReplicationSet, Username: cmd.Username, Password: cmd.Password, + DefaultsFile: cmd.DefaultsFile, AgentPassword: cmd.AgentPassword, CustomLabels: customLabels, @@ -253,6 +255,7 @@ func init() { AddMySQLC.Flag("username", "MySQL username").Default("root").StringVar(&AddMySQL.Username) AddMySQLC.Flag("password", "MySQL password").StringVar(&AddMySQL.Password) + AddMySQLC.Flag("defaults-file", "Path to defaults file").Default("~/.my.cnf").StringVar(&AddMySQL.DefaultsFile) AddMySQLC.Flag("agent-password", "Custom password for /metrics endpoint").StringVar(&AddMySQL.AgentPassword) querySources := []string{mysqlQuerySourceSlowLog, mysqlQuerySourcePerfSchema, mysqlQuerySourceNone} // TODO add "auto", make it default From 5585aa0de1721eed7a2074d2945ca123f6d841e7 Mon Sep 17 00:00:00 2001 From: Przemyslaw Kadej Date: Fri, 15 Apr 2022 02:44:39 +0200 Subject: [PATCH 2/6] PMM-4879 Removing default value for defaults-file. --- commands/management/add_mysql.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/management/add_mysql.go b/commands/management/add_mysql.go index e5b277ce..77579d8b 100644 --- a/commands/management/add_mysql.go +++ b/commands/management/add_mysql.go @@ -255,7 +255,7 @@ func init() { AddMySQLC.Flag("username", "MySQL username").Default("root").StringVar(&AddMySQL.Username) AddMySQLC.Flag("password", "MySQL password").StringVar(&AddMySQL.Password) - AddMySQLC.Flag("defaults-file", "Path to defaults file").Default("~/.my.cnf").StringVar(&AddMySQL.DefaultsFile) + AddMySQLC.Flag("defaults-file", "Path to defaults file").StringVar(&AddMySQL.DefaultsFile) AddMySQLC.Flag("agent-password", "Custom password for /metrics endpoint").StringVar(&AddMySQL.AgentPassword) querySources := []string{mysqlQuerySourceSlowLog, mysqlQuerySourcePerfSchema, mysqlQuerySourceNone} // TODO add "auto", make it default From 352922c55007594bc6d0ac881cdc5bdc86370d7d Mon Sep 17 00:00:00 2001 From: Przemyslaw Kadej Date: Thu, 21 Apr 2022 06:15:35 +0200 Subject: [PATCH 3/6] PMM-4879 Removing default value for username. --- commands/management/add_mysql.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/management/add_mysql.go b/commands/management/add_mysql.go index 77579d8b..a57e9ed6 100644 --- a/commands/management/add_mysql.go +++ b/commands/management/add_mysql.go @@ -253,7 +253,7 @@ func init() { AddMySQLC.Flag("node-id", "Node ID (default is autodetected)").StringVar(&AddMySQL.NodeID) AddMySQLC.Flag("pmm-agent-id", "The pmm-agent identifier which runs this instance (default is autodetected)").StringVar(&AddMySQL.PMMAgentID) - AddMySQLC.Flag("username", "MySQL username").Default("root").StringVar(&AddMySQL.Username) + AddMySQLC.Flag("username", "MySQL username").StringVar(&AddMySQL.Username) AddMySQLC.Flag("password", "MySQL password").StringVar(&AddMySQL.Password) AddMySQLC.Flag("defaults-file", "Path to defaults file").StringVar(&AddMySQL.DefaultsFile) AddMySQLC.Flag("agent-password", "Custom password for /metrics endpoint").StringVar(&AddMySQL.AgentPassword) From f07e024632998afdc95851a2c8f5f1c4bc109a9a Mon Sep 17 00:00:00 2001 From: Przemyslaw Kadej Date: Fri, 22 Apr 2022 20:16:53 +0200 Subject: [PATCH 4/6] PMM-4879 Removing passing default MySQL address if not specified. --- commands/management/add_mysql.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/management/add_mysql.go b/commands/management/add_mysql.go index a57e9ed6..5fb74c11 100644 --- a/commands/management/add_mysql.go +++ b/commands/management/add_mysql.go @@ -126,7 +126,8 @@ func (cmd *addMySQLCommand) GetAddress() string { } func (cmd *addMySQLCommand) GetDefaultAddress() string { - return "127.0.0.1:3306" + // address may be specified in defaults file + return "" } func (cmd *addMySQLCommand) GetSocket() string { From 3f9a4870af27b1d87a371a28e8e575f084996dd7 Mon Sep 17 00:00:00 2001 From: Przemyslaw Kadej Date: Fri, 29 Apr 2022 01:09:02 +0200 Subject: [PATCH 5/6] PMM-4879 Code review adjustments. --- commands/management/add_mysql.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/commands/management/add_mysql.go b/commands/management/add_mysql.go index 5fb74c11..18dfbed8 100644 --- a/commands/management/add_mysql.go +++ b/commands/management/add_mysql.go @@ -126,8 +126,15 @@ func (cmd *addMySQLCommand) GetAddress() string { } func (cmd *addMySQLCommand) GetDefaultAddress() string { - // address may be specified in defaults file - return "" + if cmd.DefaultsFile != "" { + // address might be specified in defaults file + return "" + } + return "127.0.0.1:3306" +} + +func (cmd *addMySQLCommand) GetDefaultUsername() string { + return "root" } func (cmd *addMySQLCommand) GetSocket() string { @@ -181,6 +188,8 @@ func (cmd *addMySQLCommand) Run() (commands.Result, error) { return nil, err } + username := defaultsFileUsernameCheck(cmd) + tablestatsGroupTableLimit := int32(cmd.DisableTablestatsLimit) if cmd.DisableTablestats { if tablestatsGroupTableLimit != 0 { @@ -201,7 +210,7 @@ func (cmd *addMySQLCommand) Run() (commands.Result, error) { Environment: cmd.Environment, Cluster: cmd.Cluster, ReplicationSet: cmd.ReplicationSet, - Username: cmd.Username, + Username: username, Password: cmd.Password, DefaultsFile: cmd.DefaultsFile, AgentPassword: cmd.AgentPassword, @@ -288,3 +297,17 @@ func init() { AddMySQLC.Flag("disable-collectors", "Comma-separated list of collector names to exclude from exporter").StringVar(&AddMySQL.DisableCollectors) addGlobalFlags(AddMySQLC) } + +func defaultsFileUsernameCheck(cmd *addMySQLCommand) string { + // defaults file specified, but passed username has higher priority + if cmd.Username != "" && cmd.DefaultsFile != "" { + return cmd.Username + } + + // username not specified, but can be in defaults files + if cmd.Username == "" && cmd.DefaultsFile != "" { + return "" + } + + return cmd.GetDefaultUsername() +} From 17077751a14a6ff43cd6a305d944ae0fd33e01c7 Mon Sep 17 00:00:00 2001 From: Przemyslaw Kadej Date: Sat, 30 Apr 2022 22:11:00 +0200 Subject: [PATCH 6/6] PMM-4879 Switching API to percona/pmm repository. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7d218db1..1eace5f6 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/AlekSi/pointer v1.2.0 github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d github.com/go-openapi/runtime v0.23.3 - github.com/percona/pmm v0.0.0-20220425171601-f7d00530d1ae + github.com/percona/pmm v0.0.0-20220425222533-a6e4e7330135 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.7.1 diff --git a/go.sum b/go.sum index 7cd33314..cb1d0c2d 100644 --- a/go.sum +++ b/go.sum @@ -111,8 +111,8 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= -github.com/percona/pmm v0.0.0-20220425171601-f7d00530d1ae h1:7URruB9o4o7ooKOUmFcyjhykgx5mfy9BdmIspGWCXlM= -github.com/percona/pmm v0.0.0-20220425171601-f7d00530d1ae/go.mod h1:FFbpyZXm+Ilg8M/GewuhdjJhPaW1/v1zjRRerYhCfEA= +github.com/percona/pmm v0.0.0-20220425222533-a6e4e7330135 h1:n0FRmvraxr+uAMl7qUcmz5ADj5XHb1PrNhE28fKEt8M= +github.com/percona/pmm v0.0.0-20220425222533-a6e4e7330135/go.mod h1:FFbpyZXm+Ilg8M/GewuhdjJhPaW1/v1zjRRerYhCfEA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=