[Fleet] Write policy_base_id field at agent enrollment#7422
[Fleet] Write policy_base_id field at agent enrollment#7422juliaElastic wants to merge 10 commits into
Conversation
|
This pull request does not have a backport label. Could you fix it @juliaElastic? 🙏
|
This comment has been minimized.
This comment has been minimized.
|
This pull request is now in conflicts. Could you fix it @juliaElastic? 🙏 |
This comment has been minimized.
This comment has been minimized.
TL;DRThe Remediation
Investigation detailsRoot Cause
Evidence
VerificationThe supplied Buildkite log was inspected locally. The PR checkout was not available in the workspace, so no PR-specific rerun was performed. What is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces a denormalized policy_base_id field on agent documents to enable efficient term/terms queries for “base policy ID” lookups when policy_id may include a #major.minor version suffix.
Changes:
- Adds
policy_base_idto the Agent schema/model and corresponding DL constant. - Populates
PolicyBaseIDduring agent creation in the enrollment handler via apolicyBaseID()helper. - Adds a unit test for the
policyBaseID()helper and a changelog fragment.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| model/schema.json | Adds policy_base_id to the agent schema definition. |
| internal/pkg/model/schema.go | Regenerates model output to include Agent.PolicyBaseID. |
| internal/pkg/dl/constants.go | Adds FieldPolicyBaseID constant for ES field naming. |
| internal/pkg/api/handleEnroll.go | Writes PolicyBaseID on agent creation and adds policyBaseID() helper. |
| internal/pkg/api/handleEnroll_test.go | Adds unit coverage for policyBaseID() helper behavior. |
| changelog/fragments/1784718180-write-policy-base-id-on-enrollment.yaml | Records the feature in the changelog. |
Files not reviewed (1)
- internal/pkg/model/schema.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Adds a denormalized
policy_base_idfield written at agent enrollment to enable cheapterm/termsqueries in place of expensive prefix/wildcard queries.Background
Fleet supports version-specific agent policies where
policy_idgets a#major.minorsuffix (e.g.my-policy#9.2). Querying agents by policy currently requires:{ "bool": { "should": [{ "term": { "policy_id": "my-policy" } }, { "prefix": { "policy_id": "my-policy#" } }] } }The
policy_base_idfield stores the canonical base ID (suffix stripped), enabling a singleterm: { policy_base_id: "my-policy" }query instead.Changes
internal/pkg/dl/constants.go: AddFieldPolicyBaseID = "policy_base_id"constantinternal/pkg/model/schema.go: AddPolicyBaseID string json:"policy_base_id,omitempty"field to theAgentmodelinternal/pkg/api/handleEnroll.go: SetPolicyBaseID: policyBaseID(policyID)in the agent struct at enrollment; addpolicyBaseIDhelper that strips the#versionsuffixNotes
agent_policy_idvia partial update — no change needed there;policy_base_idtrackspolicy_id, notagent_policy_idupdate_by_queryduring Fleet setup (companion PR: [Fleet] Add policy_base_id field to eliminate prefix/wildcard agent policy queries (B2) kibana#279716)Part of elastic/ingest-dev#8624 (Workstream B2).