From 36e3b4021e376e74806df16816bd3f207ff37ecb Mon Sep 17 00:00:00 2001 From: Ward Vandewege Date: Thu, 3 Sep 2020 17:19:29 -0400 Subject: [PATCH] 16636: Address review comments Arvados-DCO-1.1-Signed-off-by: Ward Vandewege --- lib/cloud/cloudtest/tester.go | 6 +++--- lib/dispatchcloud/worker/pool.go | 8 ++++---- lib/dispatchcloud/worker/verify.go | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/cloud/cloudtest/tester.go b/lib/cloud/cloudtest/tester.go index 6093834179..5288b5c76c 100644 --- a/lib/cloud/cloudtest/tester.go +++ b/lib/cloud/cloudtest/tester.go @@ -127,7 +127,7 @@ func (t *tester) Run() bool { defer t.destroyTestInstance() bootDeadline := time.Now().Add(t.TimeoutBooting) - initCommand := worker.TagVerifier{nil, t.secret}.InitCommand() + initCommand := worker.TagVerifier{Instance: nil, Secret: t.secret, ReportVerified: nil}.InitCommand() t.Logger.WithFields(logrus.Fields{ "InstanceType": t.InstanceType.Name, @@ -160,7 +160,7 @@ func (t *tester) Run() bool { // Create() succeeded. Make sure the new instance // appears right away in the Instances() list. lgrC.WithField("Instance", inst.ID()).Info("created instance") - t.testInstance = &worker.TagVerifier{inst, t.secret} + t.testInstance = &worker.TagVerifier{Instance: inst, Secret: t.secret, ReportVerified: nil} t.showLoginInfo() err = t.refreshTestInstance() if err == errTestInstanceNotFound { @@ -236,7 +236,7 @@ func (t *tester) refreshTestInstance() error { "Instance": i.ID(), "Address": i.Address(), }).Info("found our instance in returned list") - t.testInstance = &worker.TagVerifier{i, t.secret} + t.testInstance = &worker.TagVerifier{Instance: i, Secret: t.secret, ReportVerified: nil} if !t.showedLoginInfo { t.showLoginInfo() } diff --git a/lib/dispatchcloud/worker/pool.go b/lib/dispatchcloud/worker/pool.go index 6ca15de493..086887cb44 100644 --- a/lib/dispatchcloud/worker/pool.go +++ b/lib/dispatchcloud/worker/pool.go @@ -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. diff --git a/lib/dispatchcloud/worker/verify.go b/lib/dispatchcloud/worker/verify.go index 4e6ee86c6b..559bb28973 100644 --- a/lib/dispatchcloud/worker/verify.go +++ b/lib/dispatchcloud/worker/verify.go @@ -32,7 +32,9 @@ func (tv TagVerifier) InitCommand() cloud.InitCommand { } func (tv TagVerifier) VerifyHostKey(pubKey ssh.PublicKey, client *ssh.Client) error { - tv.ReportVerified(tv.Instance) + if tv.ReportVerified != nil { + tv.ReportVerified(tv.Instance) + } if err := tv.Instance.VerifyHostKey(pubKey, client); err != cloud.ErrNotImplemented || tv.Secret == "" { // If the wrapped instance indicates it has a way to // verify the key, return that decision. -- 2.30.2