Skip to content

Conversation

@blakerouse
Copy link
Contributor

@blakerouse blakerouse commented Nov 6, 2025

What is the problem this PR solves?

Handles a possible error in loading the model.Agent where the components field might be invalid JSON or a string (due to another bug). This changes the code to be more defensive, also should do less on parsing the components model when that is not needed.

How does this PR solve the problem?

Changes the components field to be a json.RawMessage that does two things. One it stops it from being parsed when the model.Agent is loaded from elasticsearch, which happens often and will reduce the time it takes to parse this field. Two, it stops that field from erroring to be unmarshalled when it is an invalid format.

How to test this PR locally

mage unitTest does a great job of covering it.

Checklist

  • 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

Related issues

@blakerouse blakerouse self-assigned this Nov 6, 2025
@blakerouse blakerouse requested a review from a team as a code owner November 6, 2025 16:44
@blakerouse blakerouse added Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-active-all Automated backport with mergify to all the active branches labels Nov 6, 2025
@prodsecmachine
Copy link

prodsecmachine commented Nov 6, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@blakerouse blakerouse merged commit f9dbe41 into elastic:main Nov 6, 2025
11 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

@Mergifyio backport 8.19 9.1 9.2

@mergify
Copy link
Contributor

mergify bot commented Nov 6, 2025

backport 8.19 9.1 9.2

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Nov 6, 2025
* Handle malformatted JSON in .fleet-agents components field.

* Add changelog.

* Add logs and update test to use require.

(cherry picked from commit f9dbe41)

# Conflicts:
#	internal/pkg/api/handleCheckin.go
mergify bot pushed a commit that referenced this pull request Nov 6, 2025
* Handle malformatted JSON in .fleet-agents components field.

* Add changelog.

* Add logs and update test to use require.

(cherry picked from commit f9dbe41)

# Conflicts:
#	internal/pkg/api/handleCheckin.go
mergify bot pushed a commit that referenced this pull request Nov 6, 2025
* Handle malformatted JSON in .fleet-agents components field.

* Add changelog.

* Add logs and update test to use require.

(cherry picked from commit f9dbe41)
blakerouse added a commit that referenced this pull request Nov 6, 2025
#5864)

* Handle malformatted JSON in .fleet-agents components field.

* Add changelog.

* Add logs and update test to use require.

(cherry picked from commit f9dbe41)

Co-authored-by: Blake Rouse <[email protected]>
michalpristas pushed a commit that referenced this pull request Nov 7, 2025
michalpristas pushed a commit that referenced this pull request Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-active-all Automated backport with mergify to all the active branches Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

3 participants