From c91061f2e35193a3ef533367362d657259f9910b Mon Sep 17 00:00:00 2001 From: noname0443 Date: Wed, 18 Dec 2024 17:06:30 +0300 Subject: [PATCH] Do not show GTID in trace queries when the option is ON (#150) * 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 --- internal/app/app.go | 1 + internal/mysql/node.go | 20 ++++++++++++++++++++ internal/mysql/queries.go | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/app/app.go b/internal/app/app.go index 92435978..82771b62 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -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 diff --git a/internal/mysql/node.go b/internal/mysql/node.go index 29149ca0..7a0a3c5e 100644 --- a/internal/mysql/node.go +++ b/internal/mysql/node.go @@ -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("") + 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) diff --git a/internal/mysql/queries.go b/internal/mysql/queries.go index d2f3cafc..0fe31db4 100644 --- a/internal/mysql/queries.go +++ b/internal/mysql/queries.go @@ -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`,