Skip to content

Commit

Permalink
Do not show GTID in trace queries when the option is ON (#150)
Browse files Browse the repository at this point in the history
* Show only GTID diff in trace queries

* Show only GTID diff in trace queries

* Refactor the code

* Add message for ignored queries and fix full gtid at healthcheck

* Add quotes
  • Loading branch information
noname0443 authored Dec 18, 2024
1 parent 4486c9f commit c91061f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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", "''"),
}

//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

0 comments on commit c91061f

Please sign in to comment.