[Fleet] Add namespace level customization for packages#262568
Conversation
83dbcb0 to
5047d41
Compare
5047d41 to
a8be4ae
Compare
|
Pinging @elastic/fleet (Team:Fleet) |
Catch flakiness early (recommended)Recommended before merge: run the flaky test runner against this PR to catch flakiness early. Trigger a run with the Flaky Test Runner UI or post this comment on the PR: This check is experimental. Share your feedback in the #appex-qa channel. Posted via Macroscope — Flaky Test Runner nudge |
|
/flaky ftrConfig:x-pack/platform/test/fleet_api_integration/config.space_awareness.ts:30 |
Flaky Test Runner✅ Build triggered - kibana-flaky-test-suite-runner#11659
|
ApprovabilityVerdict: Needs human review This PR introduces a new feature for namespace-level package customization, including new API endpoints, background tasks, and schema changes. Multiple unresolved review comments raise concerns about data integrity, performance, and error handling. The changes affect code owned by @elastic/fleet and require review by designated owners. You can customize Macroscope's approvability policy. Learn more. |
Flaky Test Runner Stats🎉 All tests passed! - kibana-flaky-test-suite-runner#11659[✅] x-pack/platform/test/fleet_api_integration/config.space_awareness.ts: 30/30 tests passed. |
|
@elasticmachine merge upstream |
|
Hi @lucabelluccini Thanks a lot for your input, it will be super helpful for scoping followup work.
Your interpretation is correct:
Very good point. I can see three scenarios: 1. User cloned the base index template (what is described in https://www.elastic.co/docs/reference/fleet/data-streams-scenario3): this would likely imply two index templates with overlapping index patterns and the same priority, e.g.:
In that case, ES should reject creating the second index template, so the actual outcome would be that the user's cloned index template stays and Fleet's attempt at creating the managed one fails. In the case that they set a different priority, both templates will coexist and the higher-priority one wins for matching data streams. 2. User only created 3. User edited the original Fleet-managed index template directly: those customizations would get overridden if they enable namespace customization. In any case, it is clear that we need solid documentation to help them with the migration. What we could do to help:
I would be happy to add the first addition to this PR if it seems useful, as it should be fairly small. I think the second one, if applicable, needs to be fleshed out and be its own followup.
Fair point, it would be great if namespace-level customization could eventually fill that gap. This is broader than Fleet, since APM's templates are no longer installed by EPM. We'd probably need either the stack-managed template owners to extend their |
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Page load bundle
History
|
|
@elasticmachine merge upstream |
vishaangelova
left a comment
There was a problem hiding this comment.
A couple of small suggestions, otherwise LGTM!
Co-authored-by: Visha Angelova <91186315+vishaangelova@users.noreply.github.com>
Co-authored-by: Visha Angelova <91186315+vishaangelova@users.noreply.github.com>
|
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Public APIs missing comments
Page load bundle
History
|
Summary
Closes #245181
Fleet currently supports user customization at the type level (e.g.
logs@custom) and data-stream level (e.g.logs-system.application@custom), but not at the namespace level. Users managing multiple integrations under a shared namespace must configure each data stream individually.This PR implements namespace level customization by adding opt-in per-namespace index templates.
This is an API-only solution for now. #264065 will implement UI changes.
Solution rationale
Fleet currently creates one base index template per data stream pattern defined by the integration, e.g.
logs-system.application-*. This index templates applies to all matching data streams regardless of namespace, e.g.logs-system.application-productionandlogs-system.application-staging). This means that namespace-specific component templates (e.g.production@customandstaging@custom) cannot belong to that index template, otherwise they would compete with each other and affect all data streams, not just the relevant namespace.In this change, Fleet creates a dedicated index template per data stream with a more specific index pattern and higher priority than the base template. This namespace template is a clone of the base template with
{namespace}@customadded tocomposed_of. The base template is never modified.Example:
Component templates in
logs-system.application:Component templates in
logs-system.application@namespace.production:Opt-in mechanism
Creating namespace templates for every namespace by default could potentially cause many templates to be created unnecessarily. To mitigate this, namespace level customization is opt-in and managed in the package installation:
Namespaces can be opted in by updating the package installation:
Or using the new bulk API:
Space awareness
Installation saved objects are shared across spaces, meaning the list of opted in namespaces for an installed package is cluster wide: any Kibana space that can see an integration sees the same opt-in list. Index templates and component templates are also cluster wide.
The present implementation attempts to mitigate the write-side of this using the
allowed_namespace_prefixesper-space restriction mechanism in Fleet settings (which is already used to gate which namespaces a user can choose for agent/package policies in a given space).When the user attempts to modify the list of opted in namespaces, it will be validated against allowed namespace prefixes if any (if none are set, there's no validation). For example, if
prodnamespace is allowed in space A, then from that spaceprod_euandprod_uswould be allowed, but notqa.Performance and scaling
Namespace template creation and deletion is handled by an asynchronous task. This addresses risks of latency/timeouts and provides a built-in retry mechanism.
Testing
Per-package opt-in creates namespace templates (existing policies)
Install the System integration with a package policy using namespace
production.Verify no namespace template exists yet:
should return 404.
production:In particular, check:
index_patternsis["logs-system.application-production*"]priorityis 250composed_ofincludesproduction@customNamespace template shows in Assets tab
In Kibana UI → Integrations → System → Assets tab, confirm
logs-system.application@namespace.production(and any other per-dataset variants) appear alongside other Fleet-managed assets.Namespace component templates are applied to their specific data streams only
production@customcomponent template, e.g.:This should create the data stream and its first backing index automatically, using the
logs-system.application@namespace.productionindex template (priority 250) rather than the baselogs-system.application template(priority 200).3. Verify the
productionnamespace data stream hasnumber_of_replicas: 2:number_of_replicas: 2, confirming namespace isolation.Opt-out deletes index templates but keeps component templates
production:production@customcomponent template still exists.Uninstall cleans up namespace templates
productionback in, namespace index template should exist.Bulk endpoint
productionandstagingnamespaces for both:enableanddisable.enableanddisable:Space awareness
Should result in:
prod_eu), it should work.stagingand try to opt outprod_eu(pass an empty array): it should reject withCannot change namespace customization for: prod_eu. Allowed prefixes in this space: staging.Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesbackport:*labels.Identify risks
Risk of eventual consistency gap if package installation SO is saved (synchronous) but the async task fails to create/delete index templates.
Release note
Add opt-in namespace level customization to integrations.