Skip to content

Commit

Permalink
Fix adding percona_ps with async replication and percona_pxc to…
Browse files Browse the repository at this point in the history
… PMM
  • Loading branch information
pooknull committed Feb 8, 2023
1 parent ce9d651 commit 86be998
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
5 changes: 3 additions & 2 deletions internal/resource/ps/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"terraform-percona/internal/db"
)

func Restart() string {
Expand Down Expand Up @@ -115,6 +116,6 @@ func InstallPMMClient(addr string) string {
sudo pmm-admin config --server-insecure-tls --server-url="%s"`, addr)
}

func AddServiceToPMM(username, password string, port int) string {
return fmt.Sprintf(`pmm-admin add mysql --query-source=slowlog --username="%s" --password="%s" --port=%d`, username, password, port)
func AddServiceToPMM(password string, port int) string {
return fmt.Sprintf(`pmm-admin add mysql --query-source=slowlog --username="%s" --password="%s" --port=%d`, db.UserPMM, password, port)
}
4 changes: 2 additions & 2 deletions internal/resource/ps/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (m *manager) instanceConfig(ctx context.Context, instance cloud.Instance, i
"enforce-gtid-consistency": "ON",
}
if serverID == 1 {
cfg["bind-address"] = instance.PrivateIpAddress
cfg["bind-address"] = strings.Join([]string{instance.PrivateIpAddress, "localhost"}, ",")
}
return cfg
case replicationTypeGR:
Expand Down Expand Up @@ -390,7 +390,7 @@ func (m *manager) setupInstances(ctx context.Context, instances []cloud.Instance
}
for _, instance := range instances {
if m.pmmAddress != "" {
_, err := m.runCommand(ctx, instance, cmd.AddServiceToPMM("pmm", m.pmmPassword, m.port))
_, err := m.runCommand(ctx, instance, cmd.AddServiceToPMM(m.pmmPassword, m.port))
if err != nil {
return errors.Wrap(err, "add service to pmm")
}
Expand Down
9 changes: 7 additions & 2 deletions internal/resource/pxc/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"terraform-percona/internal/db"
)

func RetrieveVersions() string {
Expand Down Expand Up @@ -43,6 +44,10 @@ func Start(bootstrap bool) string {
return "sudo systemctl start mysql"
}

func FixRootUser(rootPassword string) string {
return fmt.Sprintf(`mysql -uroot -p%s -e "RENAME USER 'root'@'localhost' TO 'root'@'%%';FLUSH PRIVILEGES;"`, rootPassword)
}

func Stop(bootstrap bool) string {
if bootstrap {
return "sudo systemctl stop mysql@bootstrap.service"
Expand All @@ -59,6 +64,6 @@ func InstallPMMClient(addr string) string {
sudo pmm-admin config --server-insecure-tls --server-url="%s"`, addr)
}

func AddServiceToPMM(username, password string, port int) string {
return fmt.Sprintf(`pmm-admin add mysql --query-source=slowlog --username="%s" --password="%s" --port=%d`, username, password, port)
func AddServiceToPMM(password string, port int) string {
return fmt.Sprintf(`pmm-admin add mysql --query-source=slowlog --username="%s" --password="%s" --port=%d`, db.UserPMM, password, port)
}
12 changes: 11 additions & 1 deletion internal/resource/pxc/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (m *manager) Create(ctx context.Context) ([]cloud.Instance, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to edit default cfg for pmm")
}
_, err = m.runCommand(ctx, instance, cmd.AddServiceToPMM("pmm", m.pmmPassword, m.mysqlPort))
_, err = m.runCommand(ctx, instance, cmd.AddServiceToPMM(m.pmmPassword, m.mysqlPort))
if err != nil {
return nil, errors.Wrap(err, "add service to pmm")
}
Expand Down Expand Up @@ -173,6 +173,16 @@ func (m *manager) installPXC(ctx context.Context, instance cloud.Instance, clust
if err != nil {
return errors.Wrap(err, "failed to run pxc install cmd")
}
if _, err = m.cloud.RunCommand(ctx, m.resourceID, instance, cmd.Start(false)); err != nil {
return errors.Wrap(err, "pxc start")
}
_, err = m.cloud.RunCommand(ctx, m.resourceID, instance, cmd.FixRootUser(m.password))
if err != nil {
return errors.Wrap(err, "pxc fix root user")
}
if _, err = m.cloud.RunCommand(ctx, m.resourceID, instance, cmd.Stop(false)); err != nil {
return errors.Wrap(err, "pxc stop")
}
err = m.editDefaultCfg(ctx, instance, "mysqld", map[string]string{
"port": strconv.Itoa(m.mysqlPort),
"wsrep_cluster_address": "gcomm://" + strings.Join(clusterHosts, ","),
Expand Down

0 comments on commit 86be998

Please sign in to comment.