Skip to content
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

Do not show GTID in trace queries when the option is ON #150

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2068,6 +2068,7 @@ func (app *App) getNodeState(host string) *NodeState {
node = app.cluster.Get(host)
}
nodeState := new(NodeState)
nodeState.ShowOnlyGTIDDiff = app.config.ShowOnlyGTIDDiff
err := func() error {
nodeState.CheckAt = time.Now()
nodeState.CheckBy = app.config.Hostname
Expand Down
20 changes: 20 additions & 0 deletions internal/mysql/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,32 @@ func (n *Node) getQuery(name string) string {

func (n *Node) traceQuery(query string, arg interface{}, result interface{}, err error) {
query = queryOnliner.ReplaceAllString(query, " ")
if n.config.ShowOnlyGTIDDiff && IsGtidQuery(query) {
n.logger.Debug("<gtid query was ignored>")
return
}
msg := fmt.Sprintf("node %s running query '%s' with args %#v, result: %#v, error: %v", n.host, query, arg, result, err)
msg = strings.ReplaceAll(msg, n.config.MySQL.Password, "********")
msg = strings.ReplaceAll(msg, n.config.MySQL.ReplicationPassword, "********")
n.logger.Debug(msg)
}

func IsGtidQuery(query string) bool {
for _, gtidQuery := range GtidQueries {
if strings.HasPrefix(query, gtidQuery) {
return true
}
}

return false
}

var GtidQueries = []string{
DefaultQueries[queryGTIDExecuted],
strings.ReplaceAll(DefaultQueries[querySlaveStatus], ":channel", "''"),
strings.ReplaceAll(DefaultQueries[queryReplicaStatus], ":channel", ""),
noname0443 marked this conversation as resolved.
Show resolved Hide resolved
}

//nolint:unparam
func (n *Node) queryRow(queryName string, arg interface{}, result interface{}) error {
return n.queryRowWithTimeout(queryName, arg, result, n.config.DBTimeout)
Expand Down
2 changes: 1 addition & 1 deletion internal/mysql/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var DefaultQueries = map[string]string{
querySlaveStatus: `SHOW SLAVE STATUS FOR CHANNEL :channel`,
queryReplicaStatus: `SHOW REPLICA STATUS FOR CHANNEL :channel`,
queryGetVersion: `SELECT sys.version_major() AS MajorVersion, sys.version_minor() AS MinorVersion, sys.version_patch() AS PatchVersion`,
queryGTIDExecuted: `SELECT @@GLOBAL.gtid_executed as Executed_Gtid_Set`,
queryGTIDExecuted: `SELECT @@GLOBAL.gtid_executed as Executed_Gtid_Set`,
queryGetUUID: `SELECT @@server_uuid as server_uuid`,
queryShowBinaryLogs: `SHOW BINARY LOGS`,
querySlaveHosts: `SHOW SLAVE HOSTS`,
Expand Down
Loading