Skip to content
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

[Fleet] Surface conditions making the agent "not upgradeable" on "error upgrading agent" message #171840

Closed
criamico opened this issue Nov 23, 2023 · 2 comments · Fixed by #173253
Assignees
Labels
enhancement New value added to drive a business result Team:Fleet Team label for Observability Data Collection Fleet team

Comments

@criamico
Copy link
Contributor

criamico commented Nov 23, 2023

When upgrading an agent, we read the local_metadata.elastic.agent.upgradeable state from the elastic agent data, but we also do additional checks to mark the agent as upgradeable:

export function isAgentUpgradeable(
agent: Agent,
latestAgentVersion: string,
versionToUpgrade?: string
) {
let agentVersion: string;
if (typeof agent?.local_metadata?.elastic?.agent?.version === 'string') {
agentVersion = agent.local_metadata.elastic.agent.version;
} else {
return false;
}
if (agent.unenrollment_started_at || agent.unenrolled_at) {
return false;
}
if (!agent.local_metadata.elastic.agent.upgradeable) {
return false;
}
if (isAgentUpgrading(agent)) {
return false;
}
if (getRecentUpgradeInfoForAgent(agent).hasBeenUpgradedRecently) {
return false;
}
if (versionToUpgrade !== undefined) {
return isNotDowngrade(agentVersion, versionToUpgrade);
}
return isAgentVersionLessThanLatest(agentVersion, latestAgentVersion);
}

In some cases this can result in this error message, that gives no explanations about why the agent cannot be upgraded:

image (14)

Add additional information to the error message explaining why the agent is not upgradeable. We can easily get this info from is_agent_upgradeable itself.

Example

One example is the following agent, that has "upgradeable": true, from the agent itself but "upgrade_started_at": "2023-09-12T21:01:57.796Z" and "upgraded_at": null that mark the agent as already upgrading and so don't allow starting another upgrade.

{
  "item": {
    "id": "078b8cfa-fd39-461d-85a7-cee57d841204",
    "type": "PERMANENT",
    "active": true,
    "enrolled_at": "2023-03-03T11:02:58Z",
    "upgraded_at": null,
    "upgrade_started_at": "2023-09-12T21:01:57.796Z",
    "policy_id": "019cf5a",
    "last_checkin": "2023-11-22T20:29:12Z",
    "last_checkin_status": "online",
    "last_checkin_message": "Running",
    "policy_revision": 279,
    "agent": {
      "id": "078b",
      "version": "8.6.2"
    },
    "local_metadata": {
      "elastic": {
        "agent": {
          "build.original": "8.6.2 (build: 913c02bea9b13dec4d5c5f3057b5b397344e3298 at 2023-02-13 16:51:46 +0000 UTC)",
          "id": "078b8cfa-fd39-461d-85a7-cee57d841204",
          "log_level": "info",
          "snapshot": false,
          "upgradeable": true,
          "version": "8.6.2"
        }
      },
    "status": "offline"
  }

In this case the error message should say something like

agent N.. is not upgradeable: an upgrade attempt started at "2023-09-12T21:01:57.796Z" and was not completed

@criamico criamico added enhancement New value added to drive a business result Team:Fleet Team label for Observability Data Collection Fleet team labels Nov 23, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@kpollich
Copy link
Member

Related: #173281

criamico added a commit that referenced this issue Dec 19, 2023
)

Closes #171840
Also implements the UI part of
#173281

## Summary
When trying to upgrade a single agent that is not upgradeable, the error
message doesn't specify _why_ the agent cannot be upgraded. This PR is
introducing:
- More granular error messages in the endpoint `POST
agent/{agent_id}/upgrade`. The messages are now different depending on
which conditions are met. For the case when the agent is reported not
upgradeable from elastic agent, there is now an error message the states
it explicitly.
- When clicking on the `upgrade 1 agent` from the bulk actions, if the
agent is not upgradeable the submit button is now greyed out and a
message explaining the reason is shown:
- 
![Screenshot 2023-12-18 at 14 41
48](https://github.com/elastic/kibana/assets/16084106/8e0a03b4-c8fc-4a2e-aea6-77c7cc1acdf3)

The same warning appears when clicking on other upgrade actions in the
bulk action menu, but only for a single agent. Multiple upgrades have
not been changed.

- In the agents list, reuse the existing tooltip besides the version to
show the same messages when the agent is not upgradeable:
![Screenshot 2023-12-18 at 14 40
32](https://github.com/elastic/kibana/assets/16084106/ada30bc0-8c58-40d9-b7cf-c5c7a81a75f7)




### Checklist
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Team:Fleet Team label for Observability Data Collection Fleet team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants