Skip to content

Fix effective_config merge bug for OpAMP collectors#6988

Open
ycombinator wants to merge 3 commits intoelastic:mainfrom
ycombinator:fix/6877-effective-config-merge
Open

Fix effective_config merge bug for OpAMP collectors#6988
ycombinator wants to merge 3 commits intoelastic:mainfrom
ycombinator:fix/6877-effective-config-merge

Conversation

@ycombinator
Copy link
Copy Markdown
Contributor

@ycombinator ycombinator commented May 8, 2026

What is the problem this PR solves?

When an OpAMP collector removes a pipeline from its configuration, the removed pipeline still appears in the effective_config field of the agent document in Elasticsearch. This happens because fleet-server uses Elasticsearch's partial document update API ({"doc": {...}}), which recursively merges objects rather than replacing them. So keys present in the old effective_config but absent in the new one are preserved.

For example, if the stored config has pipelines {traces, metrics} and the collector reports only {traces}, the merge would keep metrics when it should be removed.

How does this PR solve the problem?

When the checkin includes effective_config, the update now uses a new Painless script (checkinWithEffectiveConfig.painless) that follows the same pattern as deleteAuditFieldsOnCheckin.painless, directly assigning fields on ctx._source to fully replace effective_config instead of merging it. This is a new branch in flush() alongside the existing script and doc-merge paths.

How to test this PR locally

mage test:integration

Design Checklist

  • I have ensured my design is stateless and will work when multiple fleet-server instances are behind a load balancer.
  • I have or intend to scale test my changes, ensuring it will work reliably with 100K+ agents connected.
  • I have included fail safe mechanisms to limit the load on fleet-server: rate limiting, circuit breakers, caching, load shedding, etc.

Checklist

  • 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

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 8, 2026

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

  • backport-./d./d is the label to automatically backport 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.

ycombinator and others added 2 commits May 8, 2026 10:36
The Elasticsearch partial update API recursively merges objects,
so when a collector removes a pipeline from its config, the old
pipeline key persists in the stored effective_config. This test
creates a document with two pipelines, updates it with one, and
asserts the removed pipeline is gone.

Relates elastic#6877

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ycombinator ycombinator force-pushed the fix/6877-effective-config-merge branch from d89970c to 008a0ab Compare May 8, 2026 17:38
@ycombinator ycombinator added bug Something isn't working 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 May 8, 2026
@ycombinator ycombinator force-pushed the fix/6877-effective-config-merge branch from c1c6a75 to 9c26062 Compare May 8, 2026 17:49
Use a Painless script to update the agent document when
effective_config is present, replacing the {"doc": ...} partial
update that recursively merges nested objects. This ensures that
keys removed from the collector's config (e.g. deleted pipelines)
are no longer preserved in Elasticsearch.

Closes elastic#6877

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ycombinator ycombinator force-pushed the fix/6877-effective-config-merge branch from 9c26062 to 11e707d Compare May 8, 2026 17:51
@ycombinator ycombinator marked this pull request as ready for review May 8, 2026 17:52
@ycombinator ycombinator requested a review from a team as a code owner May 8, 2026 17:52
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 bug Something isn't working 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.

[OpApmp] When deleting a pipeline from my collector it's not deleted from effective_config

1 participant