-
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
Create installation marker on upgrade from versions < 8.8.0 #2655
Create installation marker on upgrade from versions < 8.8.0 #2655
Conversation
This pull request does not have a backport label. Could you fix it @ycombinator? 🙏
NOTE: |
🌐 Coverage report
|
internal/pkg/agent/cmd/run.go
Outdated
// https://github.com/elastic/elastic-agent/issues/2645). | ||
|
||
installMarkerVersion := semver.MustParse("8.8.0") | ||
prevVersion, err := semver.NewVersion(upgradeMarker.PrevVersion) |
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.
Probably worth checking to see if this PrevVersion
field always exists in every version of the upgrade marker file that can be created. The 7.17.0 release is a good place to start checking.
Does 8.8.0 always create the installation marker? If it does then the absence of the installation marker implies that this is an agent version prior to 8.8.0 installed in the default location since that was the only option. Is that possibly safer since it doesn't depend on the format of the upgrade marker file?
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 have no issue with approach as long as we can prove it will always work.
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.
Does 8.8.0 always create the installation marker? If it does then the absence of the installation marker implies that this is an agent version prior to 8.8.0 installed in the default location since that was the only option. Is that possibly safer since it doesn't depend on the format of the upgrade marker file?
Yes, we always create the installation marker in 8.8.0 when Agent is installed using elastic-agent install
. That said, I also like the idea of not depending on the format of the upgrade marker file to determine the pre-upgrade version.
I do think we need to check for the existence of the upgrade marker file, though, to know that we're in the midst of an upgrade. Otherwise, we'll end up creating the installation marker even if a user simply ran elastic-agent run
or more likely, in the Docker use case (probably harmless).
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.
Yes, checking for the existence of the file should be fine. Looking inside it is more likely to have unexpected results. I'm not sure what guarantees we have about its format so that likely means we have none.
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.
The format is guaranteed by the mapping of the UpdateMarker
struct
It's not a file that a user is supposed to touch...
OTOH I don't know if we ever formalized such format anywhere and if we want to keep it forward/backward compatible by putting in place some rules about what is required/optional
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.
Looks good.
// If the installation marker file is present, we're all set. | ||
if info.RunningInstalled() { | ||
return nil | ||
} |
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 think adding a comment saying that only installed Elastic Agent's can be self-upgraded so if this returns true then we know that the marker is present as info.RunningInstalled()
checks for the marker to be present.
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.
Done in 4a420fa.
// Otherwise, we're being upgraded from a version of an installed Agent | ||
// that didn't use an installation marker file (that is, before v8.8.0). | ||
// So create the file now. | ||
if err := info.CreateInstallMarker(paths.Top()); err != nil { |
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.
This has a bit of overlap with the upgrade migrations I am trying to implement in #2597: I can see creating the install marker as part of an upgrade migration then the PrevVersion (yes I have to rely on the update marker to know which version we are coming from) is < 8.8.0
It's not something to do now but we could think of moving this part into its own migration when available
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.
Yes! While writing this I was thinking how it parallels DB migrations so, indeed, there's some overlap here. ++ to incorporating this and #2597 into a more structured migrations process if that makes sense.
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.
LGTM
* Create installation marker on upgrade from versions < 8.8.0 * Removing debugging lines * Mention re-exec for additional clarity * Adding changelog entry * Removing scratch statement * Re-ordering imports * Error check * Do not depend on parsing pre-upgrade version from upgrade marker file * Clarify comment about only installed Agent being eligible for self-upgrade (cherry picked from commit 9df6514)
…2668) * Create installation marker on upgrade from versions < 8.8.0 * Removing debugging lines * Mention re-exec for additional clarity * Adding changelog entry * Removing scratch statement * Re-ordering imports * Error check * Do not depend on parsing pre-upgrade version from upgrade marker file * Clarify comment about only installed Agent being eligible for self-upgrade (cherry picked from commit 9df6514) Co-authored-by: Shaunak Kashyap <[email protected]>
What does this PR do?
This PR checks if Agent is being run as part of an ongoing upgrade (i.e. being re-exec'd) and, if so, creates the installation marker file if the previous version of the Agent (the one being upgraded from) was one before the installation marker file was introduced.
Why is it important?
In v8.8.0, we introduced an installation marker file to indicate that an Agent was running as installed (this was necessary to implement the custom installation
--base-path
feature). When an installed Agent that's older than v8.8.0 is upgraded, this installation marker file is not present. In such cases, we need to create it manually post-upgrade. Otherwise, the upgrade will be unsuccessful.Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration filesI have added tests that prove my fix is effective or that my feature works./changelog/fragments
using the changelog toolI have added an integration test or an E2E testwill be covered as part of Port over Agent Upgrade test #2618How to test this PR locally
Install a version of Elastic Agent older than
8.8.0
.Build Agent with this PR (should result in an Agent with version
8.9.0-SNAPSHOT
).Upgrade to the Agent built with this PR.
Wait until the upgrade watcher has finished running. This should be 10 minutes. Waiting ensures that the Agent is either successfully completed the upgrade or has been rolled back. You can also keep checking the process list and wait until there is no
elastic-agent watch
process present.Check that the new version of Agent is running.
Check that the running Agent is healthy.
Related issues
Use cases
Screenshots
Logs
Questions to ask yourself