16636: Address review comments
[arvados.git] / lib / dispatchcloud / worker / pool.go
index 6ca15de4939ce060edbb30775badbbd91e368345..086887cb44176f05c9446341a68d7176dd5ed7aa 100644 (file)
@@ -371,19 +371,19 @@ func (wp *Pool) SetIdleBehavior(id cloud.InstanceID, idleBehavior IdleBehavior)
 
 // Successful connection to the SSH daemon, update the mTimeToSSH metric
 func (wp *Pool) reportSSHConnected(inst cloud.Instance) {
+       wp.mtx.Lock()
+       defer wp.mtx.Unlock()
        wkr := wp.workers[inst.ID()]
-       wkr.mtx.Lock()
-       defer wkr.mtx.Unlock()
        if wkr.state != StateBooting || !wkr.firstSSHConnection.IsZero() {
                // the node is not in booting state (can happen if a-d-c is restarted) OR
                // this is not the first SSH connection
                return
        }
 
+       wkr.firstSSHConnection = time.Now()
        if wp.mTimeToSSH != nil {
-               wp.mTimeToSSH.Observe(time.Since(wkr.appeared).Seconds())
+               wp.mTimeToSSH.Observe(wkr.firstSSHConnection.Sub(wkr.appeared).Seconds())
        }
-       wkr.firstSSHConnection = time.Now()
 }
 
 // Add or update worker attached to the given instance.