From 7c5a5782bc907aed3387e3ad71ca896d8cdd9e5a Mon Sep 17 00:00:00 2001 From: James Rasell Date: Thu, 10 Jul 2025 09:07:32 +0200 Subject: [PATCH] client: Use single time variable when handling heartbeat response. (#26238) When the client handles an update status response from the server, it modifies its heartbeat stop tracker with a time set once the RPC call returns. It optionally also emits a log message, if the client suspects it has missed a heartbeat. These times were originally tracked by two different calls to the time function which were executed 2 microseconds apart. There is no reason we cannot use a single time variable for both uses which saves us one whole call to time.Now. --- client/client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/client.go b/client/client.go index 12799161f..0102b1c40 100644 --- a/client/client.go +++ b/client/client.go @@ -2145,7 +2145,7 @@ func (c *Client) updateNodeStatus() error { c.triggerDiscovery() return fmt.Errorf("failed to update status: %v", err) } - end := time.Now() + endTime := time.Now() if len(resp.EvalIDs) != 0 { c.logger.Debug("evaluations triggered by node update", "num_evals", len(resp.EvalIDs)) @@ -2156,7 +2156,7 @@ func (c *Client) updateNodeStatus() error { last := c.lastHeartbeat() oldTTL := c.heartbeatTTL haveHeartbeated := c.haveHeartbeated - c.heartbeatStop.setLastOk(time.Now()) + c.heartbeatStop.setLastOk(endTime) c.heartbeatTTL = resp.HeartbeatTTL c.haveHeartbeated = true c.heartbeatLock.Unlock() @@ -2168,7 +2168,7 @@ func (c *Client) updateNodeStatus() error { // We have potentially missed our TTL log how delayed we were if haveHeartbeated { c.logger.Warn("missed heartbeat", - "req_latency", end.Sub(start), "heartbeat_ttl", oldTTL, "since_last_heartbeat", time.Since(last)) + "req_latency", endTime.Sub(start), "heartbeat_ttl", oldTTL, "since_last_heartbeat", time.Since(last)) } }