Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

PMM-4879 Added support for defaultsfile parameter. #199

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
31 changes: 29 additions & 2 deletions commands/management/add_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type addMySQLCommand struct {
ServiceName string
Username string
Password string
DefaultsFile string
AgentPassword string
Environment string
Cluster string
Expand Down Expand Up @@ -125,9 +126,17 @@ func (cmd *addMySQLCommand) GetAddress() string {
}

func (cmd *addMySQLCommand) GetDefaultAddress() string {
if cmd.DefaultsFile != "" {
// address might be specified in defaults file
return ""
}
return "127.0.0.1:3306"
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
}

func (cmd *addMySQLCommand) GetDefaultUsername() string {
return "root"
}

func (cmd *addMySQLCommand) GetSocket() string {
return cmd.Socket
}
Expand Down Expand Up @@ -179,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 {
Expand All @@ -199,8 +210,9 @@ 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,
CustomLabels: customLabels,

Expand Down Expand Up @@ -251,8 +263,9 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

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

And for username let's use the same logic as for default address.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

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)

querySources := []string{mysqlQuerySourceSlowLog, mysqlQuerySourcePerfSchema, mysqlQuerySourceNone} // TODO add "auto", make it default
Expand Down Expand Up @@ -284,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()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down