From 194abb6f3003e1476ce446ea0d1632abd38855fd Mon Sep 17 00:00:00 2001 From: UMEZAWA Takeshi Date: Tue, 1 Aug 2023 15:11:49 +0900 Subject: [PATCH] output replication lag metrics even if delay check is skipped Signed-off-by: UMEZAWA Takeshi --- server/mysqld_health.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/server/mysqld_health.go b/server/mysqld_health.go index 29caaaf..64e054e 100644 --- a/server/mysqld_health.go +++ b/server/mysqld_health.go @@ -76,12 +76,6 @@ func (a *Agent) MySQLDReady(w http.ResponseWriter, r *http.Request) { return } - // Check the delay isn't over the threshold - if a.maxDelayThreshold == 0 { - // Skip delay check - return - } - queued, applied, uptime, err := a.GetTransactionTimestamps(r.Context()) if err != nil { a.logger.Error(err, "failed to get replication lag") @@ -94,6 +88,20 @@ func (a *Agent) MySQLDReady(w http.ResponseWriter, r *http.Request) { // "0000-00-00 00:00:00.000000", the zero value of transaction timestamps (type TIMESTAMP(6) column), // is converted to "0001-01-01 00:00:00 +0000", the zero value of time.Time. // So, this IsZero() works as expected. + if !queued.IsZero() { + lag = queued.Sub(applied) + a.configureReplicationMetrics(true) + metrics.ReplicationDelay.Set(lag.Seconds()) + } else { + a.configureReplicationMetrics(false) + } + + // Check the delay isn't over the threshold + if a.maxDelayThreshold == 0 { + // Skip delay check + return + } + if queued.IsZero() && uptime < a.transactionQueueingWait { a.logger.Info("the instance does not seem to receive transactions yet", "uptime", uptime) msg := fmt.Sprintf("the instance does not seem to receive transactions yet: uptime=%v", uptime) @@ -101,12 +109,6 @@ func (a *Agent) MySQLDReady(w http.ResponseWriter, r *http.Request) { return } - if !queued.IsZero() { - lag = queued.Sub(applied) - } - - a.configureReplicationMetrics(true) - metrics.ReplicationDelay.Set(lag.Seconds()) if lag >= a.maxDelayThreshold { a.logger.Info("the instance delays from the primary", "maxDelayThreshold", a.maxDelayThreshold.Seconds(),