-
Notifications
You must be signed in to change notification settings - Fork 306
Index Lifecycle Management Support #805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e88262c
Firat pass
robbavey c090462
Reworked tests a bit
robbavey c086649
WIP
robbavey 7ccfc57
Make definition more strict and throw for inconsistencies
robbavey f945a13
Add further tests
robbavey 37b1db0
Update _ilm endpoint to be _ilm/policy
robbavey 9ef1c32
Use _xpack endpoint to verify ilm enablement status on Elasticsearch
robbavey 2b9496b
Update travis.yml to include more integration tests
robbavey 2aff4ac
Add missing test templates
robbavey 3b05443
Integration test improvements
robbavey 65f8ffc
Allow date math in pattern
robbavey 21253a3
Improve logging and error handling
robbavey 720db55
Rename write alias to rollover alias for consistency with beats
robbavey 5531cb6
Replace use of 'template' with 'index_patterns' when amending templates
robbavey f0d79e0
General tidy up
robbavey 6e19287
Move ILM functions out of common.rb
robbavey affba99
Cleanup template naming
robbavey a1b4e23
Fix ILM specs against ES 7
robbavey 38a353f
Remove redundant line`
robbavey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
14 changes: 14 additions & 0 deletions
14
lib/logstash/outputs/elasticsearch/default-ilm-policy.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"policy" : { | ||
"phases": { | ||
"hot" : { | ||
"actions" : { | ||
"rollover" : { | ||
"max_size" : "50gb", | ||
"max_age":"30d" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
module LogStash; module Outputs; class ElasticSearch | ||
module Ilm | ||
|
||
ILM_POLICY_PATH = "default-ilm-policy.json" | ||
|
||
def setup_ilm | ||
return unless ilm_enabled? | ||
@logger.info("Using Index lifecycle management - this feature is currently in beta.") | ||
@logger.warn "Overwriting supplied index name with rollover alias #{@ilm_rollover_alias}" if @index != LogStash::Outputs::ElasticSearch::CommonConfigs::DEFAULT_INDEX_NAME | ||
@index = ilm_rollover_alias | ||
|
||
maybe_create_rollover_alias | ||
maybe_create_ilm_policy | ||
end | ||
|
||
def ilm_enabled? | ||
@ilm_enabled | ||
end | ||
|
||
def verify_ilm_readiness | ||
return unless ilm_enabled? | ||
|
||
# Check the Elasticsearch instance for ILM readiness - this means that the version has to be a non-OSS release, with ILM feature | ||
# available and enabled. | ||
begin | ||
xpack = client.get_xpack_info | ||
features = xpack["features"] | ||
ilm = features.nil? ? nil : features["ilm"] | ||
raise LogStash::ConfigurationError, "Index Lifecycle management is enabled in logstash, but not installed on your Elasticsearch cluster" if features.nil? || ilm.nil? | ||
raise LogStash::ConfigurationError, "Index Lifecycle management is enabled in logstash, but not available in your Elasticsearch cluster" unless ilm['available'] | ||
raise LogStash::ConfigurationError, "Index Lifecycle management is enabled in logstash, but not enabled in your Elasticsearch cluster" unless ilm['enabled'] | ||
|
||
unless ilm_policy_default? || client.ilm_policy_exists?(ilm_policy) | ||
raise LogStash::ConfigurationError, "The specified ILM policy #{ilm_policy} does not exist on your Elasticsearch instance" | ||
end | ||
|
||
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e | ||
# Check xpack endpoint: If no xpack endpoint, then this version of Elasticsearch is not compatible | ||
if e.response_code == 404 | ||
raise LogStash::ConfigurationError, "Index Lifecycle management is enabled in logstash, but not installed on your Elasticsearch cluster" | ||
elsif e.response_code == 400 | ||
raise LogStash::ConfigurationError, "Index Lifecycle management is enabled in logstash, but not installed on your Elasticsearch cluster" | ||
else | ||
raise e | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def ilm_policy_default? | ||
ilm_policy == LogStash::Outputs::ElasticSearch::DEFAULT_POLICY | ||
end | ||
|
||
def maybe_create_ilm_policy | ||
if ilm_policy_default? && !client.ilm_policy_exists?(ilm_policy) | ||
client.ilm_policy_put(ilm_policy, policy_payload) | ||
end | ||
end | ||
|
||
def maybe_create_rollover_alias | ||
client.rollover_alias_put(rollover_alias_target, rollover_alias_payload) unless client.rollover_alias_exists?(ilm_rollover_alias) | ||
end | ||
|
||
def rollover_alias_target | ||
"<#{ilm_rollover_alias}-#{ilm_pattern}>" | ||
end | ||
|
||
def rollover_alias_payload | ||
{ | ||
'aliases' => { | ||
ilm_rollover_alias =>{ | ||
'is_write_index' => true | ||
} | ||
} | ||
} | ||
end | ||
|
||
def policy_payload | ||
policy_path = ::File.expand_path(ILM_POLICY_PATH, ::File.dirname(__FILE__)) | ||
LogStash::Json.load(::IO.read(policy_path)) | ||
end | ||
end | ||
end end end |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.