-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log warning on same version upgrade to prevent failed status #6273
Changes from 7 commits
29ea961
96deaee
299ab0b
1abfd1f
6cac6df
ea65977
5688de5
1ea127e
72a5106
14e7875
4ba234c
b467845
29ba576
167701b
eff680d
bef8ff6
0232a31
aeb6ee0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Kind can be one of: | ||
# - breaking-change: a change to previously-documented behavior | ||
# - deprecation: functionality that is being removed in a later release | ||
# - bug-fix: fixes a problem in a previous version | ||
# - enhancement: extends functionality but does not break or fix existing behavior | ||
# - feature: new functionality | ||
# - known-issue: problems that we are aware of in a given version | ||
# - security: impacts on the security of a product or a user’s deployment. | ||
# - upgrade: important information for someone upgrading from a prior version | ||
# - other: does not fit into any of the other categories | ||
kind: bug-fix | ||
|
||
# Change summary; a 80ish characters long description of the change. | ||
summary: Log warning on same version upgrade attempts | ||
|
||
# Long description; in case the summary is not enough to describe the change | ||
# this field accommodate a description without length limits. | ||
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. | ||
description: | | ||
Log a warning instead of reporting an error whan a same-version upgrade is | ||
attempted. This prevents the agent from reporting a "failed" status. | ||
|
||
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. | ||
component: elastic-agent | ||
|
||
# PR URL; optional; the PR number that added the changeset. | ||
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. | ||
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. | ||
# Please provide it if you are adding a fragment for a different PR. | ||
#pr: https://github.com/owner/repo/1234 | ||
|
||
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). | ||
# If not present is automatically filled by the tooling with the issue linked to the PR number. | ||
issue: https://github.com/elastic/elastic-agent/issues/6186 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ var agentArtifact = artifact.Artifact{ | |
} | ||
|
||
var ErrWatcherNotStarted = errors.New("watcher did not start in time") | ||
var ErrUpgradeSameVersion = errors.New("upgrade did not occur because it is the same version") | ||
|
||
// Upgrader performs an upgrade | ||
type Upgrader struct { | ||
|
@@ -162,6 +163,19 @@ func (av agentVersion) String() string { | |
func (u *Upgrader) Upgrade(ctx context.Context, version string, sourceURI string, action *fleetapi.ActionUpgrade, det *details.Details, skipVerifyOverride bool, skipDefaultPgp bool, pgpBytes ...string) (_ reexec.ShutdownCallbackFn, err error) { | ||
u.log.Infow("Upgrading agent", "version", version, "source_uri", sourceURI) | ||
|
||
currentVersion := agentVersion{ | ||
version: release.Version(), | ||
snapshot: release.Snapshot(), | ||
hash: release.Commit(), | ||
} | ||
|
||
// check version before download | ||
same, _ := isSameVersion(u.log, currentVersion, packageMetadata{}, version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check will not work for snapshot upgrades. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but it should work for non-snapshot attempts, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pchila so in this case this will fail because hash is unpopulated right? but then later it is extracted and checked again on line 224. so we lose a bit of time but will not perform upgrade There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we are relying on the fact that the current version has a not empty hash compared to the zero value in I guess we will never get true from here... Did you test this ? Is there a case where this returns true ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're correct, I forgot that comparing currentVersion vs version would also compare the hashes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a new func that does this comparison correctly. |
||
if same { | ||
u.log.Warnf("Upgrade action skipped because agent is already at version %s", currentVersion) | ||
return nil, ErrUpgradeSameVersion | ||
} | ||
|
||
// Inform the Upgrade Marker Watcher that we've started upgrading. Note that this | ||
// is only possible to do in-memory since, today, the process that's initiating | ||
// the upgrade is the same as the Agent process in which the Upgrade Marker Watcher is | ||
|
@@ -206,15 +220,11 @@ func (u *Upgrader) Upgrade(ctx context.Context, version string, sourceURI string | |
return nil, fmt.Errorf("reading metadata for elastic agent version %s package %q: %w", version, archivePath, err) | ||
} | ||
|
||
currentVersion := agentVersion{ | ||
version: release.Version(), | ||
snapshot: release.Snapshot(), | ||
hash: release.Commit(), | ||
} | ||
|
||
// Recheck version here in case of a snapshot->snapshot upgrade on the same version. | ||
same, newVersion := isSameVersion(u.log, currentVersion, metadata, version) | ||
if same { | ||
return nil, fmt.Errorf("agent version is already %s", currentVersion) | ||
u.log.Warnf("Upgrade action skipped because agent is already at version %s", currentVersion) | ||
return nil, ErrUpgradeSameVersion | ||
michel-laterman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
u.log.Infow("Unpacking agent package", "version", newVersion) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to consider this an error, that is what lead to the bug this is fixing in the first place. It needs to be like an idempotent API call. It returns success if the action has already completed successfully once.