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

output replication lag metrics even if delay check is skipped #85

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Changes from all 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
26 changes: 14 additions & 12 deletions server/mysqld_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -94,19 +88,27 @@ 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)
http.Error(w, msg, http.StatusServiceUnavailable)
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(),
Expand Down