Skip to content

Conversation

pchila
Copy link
Member

@pchila pchila commented Jun 9, 2025

What does this PR do?

A new reason string field has been added in UpgradeDetails struct. Such field should contain a human-readable description of the cause of the last state transition.
In the specific case this is used to distinguish how elastic-agent got to the UPG_ROLLBACK state: the only possible reason at the moment is an automatic rollback initiated by the elastic-agent watcher, but this could be used for any state transition

Why is it important?

This PR will allow to to distinguish if the cause of an UPG_ROLLBACK status is:

Checklist

  • I have read and understood the pull request guidelines of this project.
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

Disruptive User Impact

How to test this PR locally

  1. Upgrade an agent built from this PR to:
  • either a lower version agent (9.0.2 for example)
  • the same commit repackaged as an IAR, for example
    AGENT_PACKAGE_VERSION="9.1.0+build20250626000000" BEAT_VERSION="9.1.0-SNAPSHOT" EXTERNAL=true PACKAGES=tar.gz  PLATFORMS="linux/amd64" mage clean package
  1. Kill/restart the updated agent 3 times during the grace period

  2. Check that the agent rolls back to the starting version

  3. Verify that now a new reason field is present in upgrade details metadata:

    • with an elastic-agent status command
    root@elastic-agent-dev:~# elastic-agent status
    ┌─ fleet
    │  └─ status: (STARTING)
    ├─ elastic-agent
    │  └─ status: (HEALTHY) Running
    └─ upgrade_details
       ├─ target_version: 9.1.0
       ├─ state: UPG_ROLLBACK
       ├─ action_id: 82b460db-898c-453f-9372-303042605841
       └─ metadata
          └─ reason: automatic rollback
    • with a call to fleet API GET kbn:/api/fleet/agents/7a0ac237-9e82-49ac-bb0d-a2a9edac0ead if it's a managed agent:
    {
    "item": {
        "id": "7a0ac237-9e82-49ac-bb0d-a2a9edac0ead",
        "type": "PERMANENT",
        "active": true,
        "enrolled_at": "2025-06-26T11:35:58Z",
        "upgraded_at": "2025-06-26T11:39:05Z",
        "upgrade_started_at": null,
        "upgrade_details": {
          "metadata": {
            "retry_until": "2025-06-26T13:36:10.184616451Z",
            "reason": "automatic rollback"
          },
          "action_id": "82b460db-898c-453f-9372-303042605841",
          "state": "UPG_ROLLBACK",
          "target_version": "9.1.0"
        },

Related issues

Questions to ask yourself

  • How are we going to support this in production?
  • How are we going to measure its adoption?
  • How are we going to debug this?
  • What are the metrics I should take care of?
  • ...

@pchila pchila self-assigned this Jun 9, 2025
@pchila pchila added enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team labels Jun 9, 2025
Copy link
Contributor

mergify bot commented Jun 9, 2025

This pull request does not have a backport label. Could you fix it @pchila? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label that automatically backports to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

Copy link
Contributor

mergify bot commented Jun 13, 2025

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b add-rollback-reason upstream/add-rollback-reason
git merge upstream/main
git push upstream add-rollback-reason

@pchila pchila force-pushed the add-rollback-reason branch from 5e3129c to 2121c28 Compare June 16, 2025 08:05
@pchila pchila force-pushed the add-rollback-reason branch from 6531e40 to 394dcc6 Compare June 24, 2025 07:01
Copy link
Contributor

mergify bot commented Jun 24, 2025

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b add-rollback-reason upstream/add-rollback-reason
git merge upstream/main
git push upstream add-rollback-reason

@pchila pchila force-pushed the add-rollback-reason branch 2 times, most recently from 91ba418 to 83c694e Compare June 25, 2025 18:34
@pchila pchila force-pushed the add-rollback-reason branch from 23c0f74 to ad6365a Compare June 26, 2025 05:57
@pchila
Copy link
Member Author

pchila commented Jun 26, 2025

Not sure why lint is still failing since the replace directive in go.mod pointing to my fork of elastic-agent-libs has been removed (I merged my changes there and created a new release) 🤔

Edit:
@v1v @dliappis @pkoutsovasilis it seems that the linting action is working on a commit that contains obsolete code. Could you take a look please ?

@pchila pchila marked this pull request as ready for review June 26, 2025 14:20
@pchila pchila requested a review from a team as a code owner June 26, 2025 14:20
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@pchila pchila changed the title Add rollback reason to upgrade details and preserve upgrade marker when rolling back Preserve upgrade marker when rolling back and add rollback reason to upgrade details Jun 27, 2025
Copy link

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @pchila

Copy link
Contributor

@pkoutsovasilis pkoutsovasilis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for all the testing, this was helpful to me

pchila added a commit to pchila/elastic-agent that referenced this pull request Jun 27, 2025
Modifications introduced with elastic#8407
should have fixed the timing issue that made TestStandaloneUpgradeRollbackOnRestarts
flaky on windows
@pchila pchila merged commit 2f55098 into elastic:main Jun 27, 2025
19 checks passed
pchila added a commit to pchila/elastic-agent that referenced this pull request Jun 27, 2025
Modifications introduced with elastic#8407
should have fixed the timing issue that made TestStandaloneUpgradeRollbackOnRestarts
flaky on windows
pchila added a commit to pchila/elastic-agent that referenced this pull request Jun 30, 2025
Modifications introduced with elastic#8407
should have fixed the timing issue that made TestStandaloneUpgradeRollbackOnRestarts
flaky on windows
pchila added a commit to pchila/elastic-agent that referenced this pull request Jul 1, 2025
Modifications introduced with elastic#8407
should have fixed the timing issue that made TestStandaloneUpgradeRollbackOnRestarts
flaky on windows
pchila added a commit that referenced this pull request Jul 3, 2025
Modifications introduced with #8407
should have fixed the timing issue that made TestStandaloneUpgradeRollbackOnRestarts
flaky on windows
@pchila pchila mentioned this pull request Jul 30, 2025
2 tasks
pchila added a commit to pchila/elasticsearch that referenced this pull request Sep 15, 2025
Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407
pchila added a commit to elastic/elasticsearch that referenced this pull request Sep 15, 2025
* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION
ebeahan pushed a commit to ebeahan/elasticsearch that referenced this pull request Sep 15, 2025
…34711)

* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION

(cherry picked from commit 67676ae)

# Conflicts:
#	x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java
ebeahan pushed a commit to ebeahan/elasticsearch that referenced this pull request Sep 15, 2025
…34711)

* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION

(cherry picked from commit 67676ae)

# Conflicts:
#	x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java
ebeahan pushed a commit to ebeahan/elasticsearch that referenced this pull request Sep 15, 2025
…34711)

* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION

(cherry picked from commit 67676ae)

# Conflicts:
#	x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java
elasticsearchmachine pushed a commit to elastic/elasticsearch that referenced this pull request Sep 15, 2025
…134752)

* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION

(cherry picked from commit 67676ae)

# Conflicts:
#	x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java

Co-authored-by: Paolo Chilà <[email protected]>
elasticsearchmachine pushed a commit to elastic/elasticsearch that referenced this pull request Sep 15, 2025
…134749)

* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION

(cherry picked from commit 67676ae)

# Conflicts:
#	x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java

Co-authored-by: Paolo Chilà <[email protected]>
elasticsearchmachine pushed a commit to elastic/elasticsearch that referenced this pull request Sep 15, 2025
…134750)

* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION

(cherry picked from commit 67676ae)

# Conflicts:
#	x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java

Co-authored-by: Paolo Chilà <[email protected]>
elasticsearchmachine pushed a commit to elastic/elasticsearch that referenced this pull request Sep 15, 2025
…134751)

* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION

(cherry picked from commit 67676ae)

# Conflicts:
#	x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java

Co-authored-by: Paolo Chilà <[email protected]>
mridula-s109 pushed a commit to mridula-s109/elasticsearch that referenced this pull request Sep 17, 2025
…34711)

* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION
gmjehovich pushed a commit to gmjehovich/elasticsearch that referenced this pull request Sep 18, 2025
…34711)

* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION
sarog pushed a commit to portsbuild/elasticsearch that referenced this pull request Sep 19, 2025
…34711) (elastic#134751)

* Add Reason field to elastic-agent upgrade details metadata

Add "reason" text field to map a new upgrade details field introduced in
PR elastic/elastic-agent#8407

* Update docs/changelog/134711.yaml

* Bump FLEET_AGENTS_MAPPINGS_VERSION

(cherry picked from commit 67676ae)

# Conflicts:
#	x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java

Co-authored-by: Paolo Chilà <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-skip enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add reason in UPG_ROLLBACK upgrade details metadata

3 participants