Skip to content

Commit

Permalink
Gather metrics when version check fails for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuKarthikRavindran authored and Chnwanze committed Aug 21, 2024
1 parent d077595 commit 1302426
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
9 changes: 3 additions & 6 deletions agent/update/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions agent/update/processor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions agent/update/processor/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions agent/update/processor/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions agent/updateutil/updateconstants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 1302426

Please sign in to comment.