From 130242600566e31919764be46c466e7e97343f07 Mon Sep 17 00:00:00 2001 From: Vishnu Karthik Ravindran Date: Fri, 16 Aug 2024 15:33:07 -0400 Subject: [PATCH] Gather metrics when version check fails for Windows cr: https://code.amazon.com/reviews/CR-143607507 --- agent/update/processor/processor.go | 9 +++------ agent/update/processor/processor_test.go | 6 ++++++ agent/update/processor/progress.go | 4 ++-- agent/update/processor/progress_test.go | 1 + agent/updateutil/updateconstants/constants.go | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/agent/update/processor/processor.go b/agent/update/processor/processor.go index 1edb75334..95940d0ff 100644 --- a/agent/update/processor/processor.go +++ b/agent/update/processor/processor.go @@ -571,14 +571,11 @@ func verifyInstallation(mgr *updateManager, log log.T, updateDetail *UpdateDetai } if !isRollback { + // reset the sub status as it is used in the succeeded function now + mgr.subStatus = "" // initiate rollback when agent installation is not complete if versionInstalledErrCode := mgr.util.VerifyInstalledVersion(log, version); versionInstalledErrCode != "" { - message := updateutil.BuildMessage(nil, - "failed to identify installed target agent version: %v", - updateDetail.TargetVersion) - updateDetail.AppendError(log, message) - // we will receive 2 kind of error code - ErrorInstTargetVersionNotFoundViaReg and ErrorInstTargetVersionNotFoundViaWMIC - return mgr.failed(updateDetail, log, versionInstalledErrCode, message, false) + mgr.subStatus = string(versionInstalledErrCode) } log.Infof("%v is running", updateDetail.PackageName) return mgr.succeeded(updateDetail, log) diff --git a/agent/update/processor/processor_test.go b/agent/update/processor/processor_test.go index 3556c3d94..54584bee3 100644 --- a/agent/update/processor/processor_test.go +++ b/agent/update/processor/processor_test.go @@ -1635,6 +1635,8 @@ func TestVerifyInstallation_VersionCheck_Success(t *testing.T) { assert.NoError(t, err) assert.False(t, isRollbackCalled) assert.Equal(t, updateDetail.State, Completed) + assert.Equal(t, updateDetail.Result, contracts.ResultStatusSuccess) + assert.Equal(t, updater.mgr.subStatus, "") } func TestVerifyInstallation_VersionCheck_Failed_WMIC(t *testing.T) { @@ -1657,6 +1659,8 @@ func TestVerifyInstallation_VersionCheck_Failed_WMIC(t *testing.T) { assert.NoError(t, err) assert.False(t, isRollbackCalled) assert.Equal(t, updateDetail.State, Completed) + assert.Equal(t, updateDetail.Result, contracts.ResultStatusSuccess) + assert.Equal(t, updater.mgr.subStatus, string(updateconstants.ErrorInstTargetVersionNotFoundViaWMIC)) } func TestVerifyInstallation_VersionCheck_Failed_Reg(t *testing.T) { @@ -1679,6 +1683,8 @@ func TestVerifyInstallation_VersionCheck_Failed_Reg(t *testing.T) { assert.NoError(t, err) assert.False(t, isRollbackCalled) assert.Equal(t, updateDetail.State, Completed) + assert.Equal(t, updateDetail.Result, contracts.ResultStatusSuccess) + assert.Equal(t, updater.mgr.subStatus, string(updateconstants.ErrorInstTargetVersionNotFoundViaReg)) } func TestVerifyInstallationCannotStartAgent(t *testing.T) { diff --git a/agent/update/processor/progress.go b/agent/update/processor/progress.go index ddfef83bc..d78fc650b 100644 --- a/agent/update/processor/progress.go +++ b/agent/update/processor/progress.go @@ -96,8 +96,8 @@ func (u *updateManager) succeeded(updateDetail *UpdateDetail, log logPkg.T) (err log.WriteEvent( logger.AgentUpdateResultMessage, updateDetail.SourceVersion, - PrepareHealthStatus(updateDetail, "", updateDetail.TargetVersion)) - return u.finalize(u, updateDetail, "") + PrepareHealthStatus(updateDetail, u.subStatus, updateDetail.TargetVersion)) + return u.finalize(u, updateDetail, u.subStatus) } // failed sets update to failed with error messages diff --git a/agent/update/processor/progress_test.go b/agent/update/processor/progress_test.go index 16f972d3e..7fffaa6bc 100644 --- a/agent/update/processor/progress_test.go +++ b/agent/update/processor/progress_test.go @@ -13,6 +13,7 @@ // Package processor contains the methods for update ssm agent. // It also provides methods for sendReply and updateInstanceInfo + //go:build e2e // +build e2e diff --git a/agent/updateutil/updateconstants/constants.go b/agent/updateutil/updateconstants/constants.go index 291abf5e6..0b84b3c1f 100644 --- a/agent/updateutil/updateconstants/constants.go +++ b/agent/updateutil/updateconstants/constants.go @@ -281,10 +281,10 @@ const ( ErrorCannotStartService ErrorCode = "ErrorCannotStartService" // ErrorInstTargetVersionNotFoundViaReg represents that the target agent version could not be found using Registry - ErrorInstTargetVersionNotFoundViaReg ErrorCode = "ErrorInstTargetVersionNotFoundViaReg" + ErrorInstTargetVersionNotFoundViaReg ErrorCode = "InstTgtVerNotFoundViaReg" // ErrorInstTargetVersionNotFoundViaWMIC represents that the target agent version could not be found using WMIC - ErrorInstTargetVersionNotFoundViaWMIC ErrorCode = "ErrorInstTargetVersionNotFoundViaWMIC" + ErrorInstTargetVersionNotFoundViaWMIC ErrorCode = "InstTgtVerNotFoundViaWMIC" // ErrorCannotStopService represents Cannot stop Ec2Config service ErrorCannotStopService ErrorCode = "ErrorCannotStopService"