diff --git a/providers/proxysql/config.go b/providers/proxysql/config.go index 277a10e..6e70d23 100644 --- a/providers/proxysql/config.go +++ b/providers/proxysql/config.go @@ -82,13 +82,35 @@ func GenerateConfig(cfg ProxySQLConfig) string { b.WriteString(")\n\n") } - b.WriteString(fmt.Sprintf("%s=\n(\n", usersKey)) - b.WriteString(" {\n") - b.WriteString(fmt.Sprintf(" username=\"%s\"\n", cfg.MonitorUser)) - b.WriteString(fmt.Sprintf(" password=\"%s\"\n", cfg.MonitorPass)) - b.WriteString(" default_hostgroup=0\n") - b.WriteString(" }\n") - b.WriteString(")\n") + if isPgsql { + // PostgreSQL: single user entry (no R/W split) + b.WriteString(fmt.Sprintf("%s=\n(\n", usersKey)) + b.WriteString(" {\n") + b.WriteString(fmt.Sprintf(" username=\"%s\"\n", cfg.MonitorUser)) + b.WriteString(fmt.Sprintf(" password=\"%s\"\n", cfg.MonitorPass)) + b.WriteString(" default_hostgroup=0\n") + b.WriteString(" }\n") + b.WriteString(")\n") + } else { + // MySQL: three users — general purpose, dedicated writer, dedicated reader + b.WriteString(fmt.Sprintf("%s=\n(\n", usersKey)) + b.WriteString(" {\n") + b.WriteString(" username=\"msandbox\"\n") + b.WriteString(" password=\"msandbox\"\n") + b.WriteString(" default_hostgroup=0\n") + b.WriteString(" },\n") + b.WriteString(" {\n") + b.WriteString(" username=\"msandbox_rw\"\n") + b.WriteString(" password=\"msandbox\"\n") + b.WriteString(" default_hostgroup=0\n") + b.WriteString(" },\n") + b.WriteString(" {\n") + b.WriteString(" username=\"msandbox_ro\"\n") + b.WriteString(" password=\"msandbox\"\n") + b.WriteString(" default_hostgroup=1\n") + b.WriteString(" }\n") + b.WriteString(")\n") + } // For Group Replication / InnoDB Cluster topologies, configure ProxySQL // to monitor GR status and automatically reroute on failover. diff --git a/providers/proxysql/config_test.go b/providers/proxysql/config_test.go index 951614c..a7959a4 100644 --- a/providers/proxysql/config_test.go +++ b/providers/proxysql/config_test.go @@ -10,13 +10,13 @@ func TestGenerateConfigBasic(t *testing.T) { AdminHost: "127.0.0.1", AdminPort: 6032, AdminUser: "admin", AdminPassword: "admin", MySQLPort: 6033, DataDir: "/tmp/test", - MonitorUser: "msandbox", MonitorPass: "msandbox", + MonitorUser: "rsandbox", MonitorPass: "rsandbox", } result := GenerateConfig(cfg) checks := []string{ `admin_credentials="admin:admin"`, `interfaces="127.0.0.1:6033"`, - `monitor_username="msandbox"`, + `monitor_username="rsandbox"`, `mysql_ifaces="127.0.0.1:6032"`, } for _, check := range checks { @@ -31,7 +31,7 @@ func TestGenerateConfigWithBackends(t *testing.T) { AdminHost: "127.0.0.1", AdminPort: 6032, AdminUser: "admin", AdminPassword: "admin", MySQLPort: 6033, DataDir: "/tmp/test", - MonitorUser: "msandbox", MonitorPass: "msandbox", + MonitorUser: "rsandbox", MonitorPass: "rsandbox", Backends: []BackendServer{ {Host: "127.0.0.1", Port: 3306, Hostgroup: 0, MaxConns: 100}, {Host: "127.0.0.1", Port: 3307, Hostgroup: 1, MaxConns: 100}, @@ -57,8 +57,8 @@ func TestGenerateConfigMySQL(t *testing.T) { AdminPassword: "admin", MySQLPort: 6033, DataDir: "/tmp/proxysql/data", - MonitorUser: "msandbox", - MonitorPass: "msandbox", + MonitorUser: "rsandbox", + MonitorPass: "rsandbox", Backends: []BackendServer{ {Host: "127.0.0.1", Port: 3306, Hostgroup: 0, MaxConns: 200}, }, @@ -73,6 +73,20 @@ func TestGenerateConfigMySQL(t *testing.T) { if !strings.Contains(config, "mysql_users") { t.Error("expected mysql_users block") } + // Monitor user should be rsandbox (not in mysql_users, only in mysql_variables) + if !strings.Contains(config, `monitor_username="rsandbox"`) { + t.Error("expected monitor_username=rsandbox") + } + // Three proxy users for R/W split + if !strings.Contains(config, `username="msandbox"`) { + t.Error("expected msandbox user in mysql_users") + } + if !strings.Contains(config, `username="msandbox_rw"`) { + t.Error("expected msandbox_rw user in mysql_users") + } + if !strings.Contains(config, `username="msandbox_ro"`) { + t.Error("expected msandbox_ro user in mysql_users") + } } func TestGenerateConfigPostgreSQL(t *testing.T) { @@ -114,7 +128,7 @@ func TestGenerateConfigGRHostgroups(t *testing.T) { AdminHost: "127.0.0.1", AdminPort: 6032, AdminUser: "admin", AdminPassword: "admin", MySQLPort: 6033, DataDir: "/tmp/test", - MonitorUser: "msandbox", MonitorPass: "msandbox", + MonitorUser: "rsandbox", MonitorPass: "rsandbox", Topology: "innodb-cluster", Backends: []BackendServer{ {Host: "127.0.0.1", Port: 3306, Hostgroup: 0, MaxConns: 200}, @@ -141,7 +155,7 @@ func TestGenerateConfigNoGRHostgroupsForReplication(t *testing.T) { AdminHost: "127.0.0.1", AdminPort: 6032, AdminUser: "admin", AdminPassword: "admin", MySQLPort: 6033, DataDir: "/tmp/test", - MonitorUser: "msandbox", MonitorPass: "msandbox", + MonitorUser: "rsandbox", MonitorPass: "rsandbox", Topology: "replication", Backends: []BackendServer{ {Host: "127.0.0.1", Port: 3306, Hostgroup: 0, MaxConns: 200}, @@ -158,7 +172,7 @@ func TestGenerateConfigGRHostgroupsForGroup(t *testing.T) { AdminHost: "127.0.0.1", AdminPort: 6032, AdminUser: "admin", AdminPassword: "admin", MySQLPort: 6033, DataDir: "/tmp/test", - MonitorUser: "msandbox", MonitorPass: "msandbox", + MonitorUser: "rsandbox", MonitorPass: "rsandbox", Topology: "group", Backends: []BackendServer{ {Host: "127.0.0.1", Port: 3306, Hostgroup: 0, MaxConns: 200}, diff --git a/providers/proxysql/proxysql.go b/providers/proxysql/proxysql.go index 91aa253..3a89b5f 100644 --- a/providers/proxysql/proxysql.go +++ b/providers/proxysql/proxysql.go @@ -67,11 +67,11 @@ func (p *ProxySQLProvider) CreateSandbox(config providers.SandboxConfig) (*provi monitorUser := config.Options["monitor_user"] if monitorUser == "" { - monitorUser = "msandbox" + monitorUser = "rsandbox" } monitorPass := config.Options["monitor_password"] if monitorPass == "" { - monitorPass = "msandbox" + monitorPass = "rsandbox" } host := config.Host @@ -117,8 +117,9 @@ func (p *ProxySQLProvider) CreateSandbox(config providers.SandboxConfig) (*provi scripts["use_proxy"] = fmt.Sprintf("#!/bin/bash\npsql -h %s -p %d -U %s \"$@\"\n", host, mysqlPort, monitorUser) } else { - scripts["use_proxy"] = fmt.Sprintf("#!/bin/bash\nmysql -h %s -P %d -u %s -p%s --prompt 'ProxySQL> ' \"$@\"\n", - host, mysqlPort, monitorUser, monitorPass) + // use_proxy connects as msandbox (app user), not the monitor user (rsandbox) + scripts["use_proxy"] = fmt.Sprintf("#!/bin/bash\nmysql -h %s -P %d -u msandbox -pmsandbox --prompt 'ProxySQL> ' \"$@\"\n", + host, mysqlPort) } for name, content := range scripts { diff --git a/sandbox/proxysql_topology.go b/sandbox/proxysql_topology.go index 1bb9816..62b0099 100644 --- a/sandbox/proxysql_topology.go +++ b/sandbox/proxysql_topology.go @@ -84,8 +84,8 @@ func DeployProxySQLForTopology(sandboxDir string, masterPort int, slavePorts []i DbUser: "admin", DbPassword: "admin", Options: map[string]string{ - "monitor_user": "msandbox", - "monitor_password": "msandbox", + "monitor_user": "rsandbox", + "monitor_password": "rsandbox", "backends": strings.Join(backendParts, ","), "backend_provider": backendProvider, "topology": topologyName(topology), diff --git a/test/proxysql-integration-tests.sh b/test/proxysql-integration-tests.sh index e2f00ce..c9416dc 100755 --- a/test/proxysql-integration-tests.sh +++ b/test/proxysql-integration-tests.sh @@ -369,10 +369,22 @@ section "Configuration correctness" dbdeployer deploy single $MYSQL_VERSION_1 --sandbox-binary=$SANDBOX_BINARY --with-proxysql > /dev/null 2>&1 SANDBOX_DIR=~/sandboxes/msb_$(echo $MYSQL_VERSION_1 | tr '.' '_') -if grep -q "msandbox" ${SANDBOX_DIR}/proxysql/proxysql.cnf 2>/dev/null; then - pass "config contains monitor_username=msandbox" +if grep -q 'monitor_username="rsandbox"' ${SANDBOX_DIR}/proxysql/proxysql.cnf 2>/dev/null; then + pass "config contains monitor_username=rsandbox" else - fail "monitor username in config" "not found" + fail "monitor username in config" "rsandbox not found" +fi + +if grep -q 'username="msandbox_rw"' ${SANDBOX_DIR}/proxysql/proxysql.cnf 2>/dev/null; then + pass "config contains msandbox_rw proxy user" +else + fail "msandbox_rw proxy user in config" "not found" +fi + +if grep -q 'username="msandbox_ro"' ${SANDBOX_DIR}/proxysql/proxysql.cnf 2>/dev/null; then + pass "config contains msandbox_ro proxy user" +else + fail "msandbox_ro proxy user in config" "not found" fi if grep -q 'admin_credentials="admin:admin"' ${SANDBOX_DIR}/proxysql/proxysql.cnf 2>/dev/null; then