feat: add opt-in dynamic ILM resolution for sprintf-based alias and policy#1254
Open
jithsungh wants to merge 2 commits into
Open
feat: add opt-in dynamic ILM resolution for sprintf-based alias and policy#1254jithsungh wants to merge 2 commits into
jithsungh wants to merge 2 commits into
Conversation
…and policy Enable dynamic ILM behavior when `ilm_rollover_alias` or `ilm_policy` contains sprintf placeholders. In this mode: - rollover alias and policy are resolved per event - resolved values are validated (non-empty, no unresolved placeholders) - policy and alias must already exist in Elasticsearch - validation is cached per resolved alias/policy combination Behavior: - skips ILM bootstrap during startup in dynamic mode - uses resolved rollover alias as target index Backward compatibility: - no change to existing behavior - dynamic mode is activated only when sprintf patterns are used Notes: - does not auto-create ILM policies or templates - enforces strict pre-provisioned ILM setup
|
💚 CLA has been signed |
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in “dynamic ILM” mode for the Elasticsearch output plugin that resolves ilm_rollover_alias and ilm_policy per-event when either setting contains sprintf patterns, and skips startup ILM bootstrap in that mode.
Changes:
- Skip
setup_ilmbootstrap when ILM settings contain sprintf patterns, and add per-event alias/policy resolution + existence validation with caching. - Route event
_indexto the dynamically-resolved rollover alias when dynamic ILM mode is active. - Add unit tests for dynamic resolution, caching behavior, and failure scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lib/logstash/outputs/elasticsearch/ilm.rb |
Introduces dynamic ILM detection, per-event resolution/validation, and skips startup ILM bootstrap in dynamic mode. |
lib/logstash/outputs/elasticsearch.rb |
Hooks dynamic ILM validation into per-event mapping and uses resolved rollover alias as the target index. |
spec/unit/outputs/elasticsearch_spec.rb |
Adds unit tests covering the new dynamic ILM behavior and startup bootstrap bypass. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces opt-in dynamic ILM resolution when
ilm_rollover_aliasorilm_policycontains sprintf patterns.In this mode, alias and policy are resolved per event instead of at startup.
Motivation
In multi-service environments, users often need ILM configurations (alias + policy) to vary per event (e.g. based on service or container name).
Currently, this requires:
This change allows ILM resolution to be driven directly from event fields.
Behavior
Activated only when sprintf is used in:
ilm_rollover_aliasilm_policyPer-event:
Startup ILM bootstrap is skipped in dynamic mode
Constraints (Intentional)
No automatic creation of:
All ILM resources must be pre-created
Missing resources result in
EventMappingErrorBackward Compatibility
Performance Considerations
Testing
Added unit tests covering:
Additional Context
This approach has been used in production environments with strict pre-provisioned ILM setups to support multi-service indexing patterns.
Faced the linear search bottleneck at logstash_output_elasticsearch config containing hundreds of if-else blocks each for one microservice manually routing event to their alias and policies.
visit additional documentation
If there is interest, additional features (e.g. controlled auto-provisioning) can be proposed separately.