logstash-output-elasticsearch 9.2.4-java → 9.3.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/docs/index.asciidoc +104 -2
- data/lib/logstash/outputs/elasticsearch.rb +4 -0
- data/lib/logstash/outputs/elasticsearch/common.rb +8 -5
- data/lib/logstash/outputs/elasticsearch/common_configs.rb +23 -1
- data/lib/logstash/outputs/elasticsearch/default-ilm-policy.json +14 -0
- data/lib/logstash/outputs/elasticsearch/http_client.rb +47 -2
- data/lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb +3 -3
- data/lib/logstash/outputs/elasticsearch/ilm.rb +84 -0
- data/lib/logstash/outputs/elasticsearch/template_manager.rb +21 -1
- data/logstash-output-elasticsearch.gemspec +1 -1
- data/spec/es_spec_helper.rb +70 -0
- data/spec/fixtures/template-with-policy-es6x.json +48 -0
- data/spec/fixtures/template-with-policy-es7x.json +46 -0
- data/spec/integration/outputs/create_spec.rb +1 -1
- data/spec/integration/outputs/ilm_spec.rb +542 -0
- data/spec/integration/outputs/ingest_pipeline_spec.rb +2 -2
- data/spec/integration/outputs/no_es_on_startup_spec.rb +2 -2
- data/spec/integration/outputs/retry_spec.rb +3 -3
- data/spec/integration/outputs/templates_5x_spec.rb +7 -7
- data/spec/integration/outputs/templates_spec.rb +7 -7
- data/spec/support/elasticsearch/api/actions/delete_ilm_policy.rb +19 -0
- data/spec/support/elasticsearch/api/actions/get_alias.rb +18 -0
- data/spec/support/elasticsearch/api/actions/get_ilm_policy.rb +18 -0
- data/spec/support/elasticsearch/api/actions/put_alias.rb +24 -0
- data/spec/support/elasticsearch/api/actions/put_ilm_policy.rb +25 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c6ed2c43c43667688e700d6f8db2b714b865a5653c0fc8892a8de479857397d
|
4
|
+
data.tar.gz: bf24c972d847db154b5feb1290341e92b53fdbf5673ea7916d651b77633f9e30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51939e7522f9370efdc381bf5d981c0efb7a42aa9fc68a873c2281eba9bd4497ec63c40ac951c1b1f2c9c65398073632b13a9870dad05a6d15685dae7c9c6e38
|
7
|
+
data.tar.gz: 18b48cd4103103fcf957718afcaa5f24cfdf429e5ce5949a16a6674ea79035c4801f53049bda2d2a6693469abaf9bb5699547301705961d51159383b1c05a96a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 9.3.0
|
2
|
+
- Adds support for Index Lifecycle Management for Elasticsearch 6.6.0 and above, running with at least a Basic License(Beta) [#805](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/805)
|
3
|
+
|
1
4
|
## 9.2.4
|
2
5
|
- Fixed support for Elasticsearch 7.x [#812](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/812)
|
3
6
|
|
data/docs/index.asciidoc
CHANGED
@@ -75,13 +75,13 @@ HTTP requests to the bulk API are expected to return a 200 response code. All ot
|
|
75
75
|
|
76
76
|
The following document errors are handled as follows:
|
77
77
|
|
78
|
-
* 400 and 404 errors are sent to the dead letter queue (DLQ), if enabled. If a DLQ is not enabled, a log message will be emitted, and the event will be dropped. See <<dlq-policy>> for more info.
|
78
|
+
* 400 and 404 errors are sent to the dead letter queue (DLQ), if enabled. If a DLQ is not enabled, a log message will be emitted, and the event will be dropped. See <<plugins-{type}s-{plugin}-dlq-policy>> for more info.
|
79
79
|
* 409 errors (conflict) are logged as a warning and dropped.
|
80
80
|
|
81
81
|
Note that 409 exceptions are no longer retried. Please set a higher `retry_on_conflict` value if you experience 409 exceptions.
|
82
82
|
It is more performant for Elasticsearch to retry these exceptions than this plugin.
|
83
83
|
|
84
|
-
[
|
84
|
+
[id="plugins-{type}s-{plugin}-dlq-policy"]
|
85
85
|
==== DLQ Policy
|
86
86
|
|
87
87
|
Mapping (404) errors from Elasticsearch can lead to data loss. Unfortunately
|
@@ -93,6 +93,56 @@ re-indexed to Elasticsearch. If the DLQ is not enabled, and a mapping error
|
|
93
93
|
happens, the problem is logged as a warning, and the event is dropped. See
|
94
94
|
<<dead-letter-queues>> for more information about processing events in the DLQ.
|
95
95
|
|
96
|
+
[id="plugins-{type}s-{plugin}-ilm"]
|
97
|
+
==== Index Lifecycle Management (Beta)
|
98
|
+
|
99
|
+
beta[]
|
100
|
+
|
101
|
+
[NOTE]
|
102
|
+
This feature requires an Elasticsearch instance of 6.6.0 or higher with at least a Basic license
|
103
|
+
|
104
|
+
Logstash can use the {ref}/index-lifecycle-management.html[Index Lifecycle Management] to automate the management of indices over time.
|
105
|
+
|
106
|
+
To configure the Elasticsearch output to use Index Lifecycle Management, set the `ilm_enabled` flag to true in the output definition:
|
107
|
+
|
108
|
+
[source,ruby]
|
109
|
+
output {
|
110
|
+
elasticsearch {
|
111
|
+
ilm_enabled => true
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
This will overwrite the index settings and adjust the Logstash template to write the necessary settings for the template
|
116
|
+
to support index lifecycle management, including the index policy and rollover alias to be used.
|
117
|
+
|
118
|
+
Logstash will create a rollover alias for the indices to be written to, including a pattern for how the actual indices will be named, and unless an ILM policy that already exists has been specified,
|
119
|
+
a default policy will also be created. The default policy is configured to rollover an index when it reaches either 50 gigabytes in size, or is 30 days old, whichever happens first.
|
120
|
+
|
121
|
+
The default rollover alias is called `logstash`, with a default pattern for the rollover index of `{now/d}-00001`,
|
122
|
+
which will name indices on the date that the index is rolled over, followed by an incrementing number. Note that the pattern must end with a dash and a number that will be incremented.
|
123
|
+
|
124
|
+
See the {ref}/indices-rollover-index.html#_using_date_math_with_the_rollover_api[Rollover API documentation] for more details on naming.
|
125
|
+
|
126
|
+
The rollover alias, ilm pattern and policy can be modified.
|
127
|
+
|
128
|
+
See config below for an example:
|
129
|
+
[source,ruby]
|
130
|
+
output {
|
131
|
+
elasticsearch {
|
132
|
+
ilm_enabled => true
|
133
|
+
ilm_rollover_alias: "custom"
|
134
|
+
ilm_pattern: "000001"
|
135
|
+
ilm_policy: "custom_policy"
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
NOTE: Custom ILM policies must already exist on the Elasticsearch cluster before they can be used.
|
140
|
+
|
141
|
+
NOTE: If the rollover alias or pattern is modified, the index template will need to be overwritten as the settings `index.lifecycle.name` and `index.lifecycle.rollover_alias` are automatically written to the template
|
142
|
+
|
143
|
+
NOTE: If the index property is supplied in the output definition, it will be overwritten by the rollover alias.
|
144
|
+
|
145
|
+
|
96
146
|
==== Batch Sizes
|
97
147
|
|
98
148
|
This plugin attempts to send batches of events as a single request. However, if
|
@@ -139,6 +189,10 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
139
189
|
| <<plugins-{type}s-{plugin}-healthcheck_path>> |<<string,string>>|No
|
140
190
|
| <<plugins-{type}s-{plugin}-hosts>> |<<uri,uri>>|No
|
141
191
|
| <<plugins-{type}s-{plugin}-http_compression>> |<<boolean,boolean>>|No
|
192
|
+
| <<plugins-{type}s-{plugin}-ilm_enabled>> |<<boolean,boolean>>|No
|
193
|
+
| <<plugins-{type}s-{plugin}-ilm_pattern>> |<<string,string>>|No
|
194
|
+
| <<plugins-{type}s-{plugin}-ilm_policy>> |<<string,string>>|No
|
195
|
+
| <<plugins-{type}s-{plugin}-ilm_rollover_alias>> |<<string,string>>|No
|
142
196
|
| <<plugins-{type}s-{plugin}-index>> |<<string,string>>|No
|
143
197
|
| <<plugins-{type}s-{plugin}-keystore>> |a valid filesystem path|No
|
144
198
|
| <<plugins-{type}s-{plugin}-keystore_password>> |<<password,password>>|No
|
@@ -314,6 +368,54 @@ Any special characters present in the URLs here MUST be URL escaped! This means
|
|
314
368
|
|
315
369
|
Enable gzip compression on requests. Note that response compression is on by default for Elasticsearch v5.0 and beyond
|
316
370
|
|
371
|
+
[id="plugins-{type}s-{plugin}-ilm_enabled"]
|
372
|
+
===== `ilm_enabled`
|
373
|
+
|
374
|
+
* Value type is <<boolean,boolean>>
|
375
|
+
* Default value is `false`
|
376
|
+
|
377
|
+
Setting this flag to `true` will enable indices to be managed by the Index Lifecycle Management feature in Elasticsearch.
|
378
|
+
|
379
|
+
NOTE: This feature requires a Basic License or above to be installed on an Elasticsearch cluster version 6.6.0 or later
|
380
|
+
|
381
|
+
[id="plugins-{type}s-{plugin}-ilm_pattern"]
|
382
|
+
===== `ilm_pattern`
|
383
|
+
|
384
|
+
* Value type is <<string,string>>
|
385
|
+
* Default value is `{now/d}-000001`
|
386
|
+
|
387
|
+
Pattern used for generating indices managed by Index Lifecycle Management. The value specified in the pattern will be appended to
|
388
|
+
the write alias, and incremented automatically when a new index is created by ILM.
|
389
|
+
|
390
|
+
Date Math can be used when specifying an ilm pattern, see {ref}/indices-rollover-index.html#_using_date_math_with_the_rollover_api[Rollover API docs] for details
|
391
|
+
|
392
|
+
NOTE: Updating the pattern will require the index template to be rewritten
|
393
|
+
|
394
|
+
NOTE: The pattern must finish with a dash and a number that will be automatically incremented when indices rollover.
|
395
|
+
|
396
|
+
[id="plugins-{type}s-{plugin}-ilm_policy"]
|
397
|
+
===== `ilm_policy`
|
398
|
+
|
399
|
+
* Value type is <<string,string>>
|
400
|
+
* Default value is `logstash`
|
401
|
+
|
402
|
+
Modify this setting to use a custom Index Lifecycle Management policy, rather than the default. If this value is not set, the default policy will
|
403
|
+
be automatically installed into Elasticsearch
|
404
|
+
|
405
|
+
NOTE: If this setting is specified, the policy must already exist in Elasticsearch cluster.
|
406
|
+
|
407
|
+
[id="plugins-{type}s-{plugin}-ilm_rollover_alias"]
|
408
|
+
===== `ilm_rollover_alias`
|
409
|
+
|
410
|
+
* Value type is <<string,string>>
|
411
|
+
* Default value is `logstash`
|
412
|
+
|
413
|
+
The rollover alias is the alias where indices managed using Index Lifecycle Management will be written to.
|
414
|
+
|
415
|
+
NOTE: If both `index` and `ilm_rollover_alias` are specified, `ilm_rollover_alias` takes precedence.
|
416
|
+
|
417
|
+
NOTE: Updating the rollover alias will require the index template to be rewritten
|
418
|
+
|
317
419
|
[id="plugins-{type}s-{plugin}-index"]
|
318
420
|
===== `index`
|
319
421
|
|
@@ -90,6 +90,7 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
|
|
90
90
|
require "logstash/outputs/elasticsearch/http_client_builder"
|
91
91
|
require "logstash/outputs/elasticsearch/common_configs"
|
92
92
|
require "logstash/outputs/elasticsearch/common"
|
93
|
+
require "logstash/outputs/elasticsearch/ilm"
|
93
94
|
|
94
95
|
# Protocol agnostic (i.e. non-http, non-java specific) configs go here
|
95
96
|
include(LogStash::Outputs::ElasticSearch::CommonConfigs)
|
@@ -97,6 +98,9 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
|
|
97
98
|
# Protocol agnostic methods
|
98
99
|
include(LogStash::Outputs::ElasticSearch::Common)
|
99
100
|
|
101
|
+
# Methods for ILM support
|
102
|
+
include(LogStash::Outputs::ElasticSearch::Ilm)
|
103
|
+
|
100
104
|
config_name "elasticsearch"
|
101
105
|
|
102
106
|
# The Elasticsearch action to perform. Valid actions are:
|
@@ -23,10 +23,10 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
23
23
|
|
24
24
|
setup_hosts # properly sets @hosts
|
25
25
|
build_client
|
26
|
+
setup_after_successful_connection
|
26
27
|
check_action_validity
|
27
28
|
@bulk_request_metrics = metric.namespace(:bulk_requests)
|
28
29
|
@document_level_metrics = metric.namespace(:documents)
|
29
|
-
install_template_after_successful_connection
|
30
30
|
@logger.info("New Elasticsearch output", :class => self.class.name, :hosts => @hosts.map(&:sanitized).map(&:to_s))
|
31
31
|
end
|
32
32
|
|
@@ -38,7 +38,7 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
38
38
|
retrying_submit(events.map {|e| event_action_tuple(e)})
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def setup_after_successful_connection
|
42
42
|
@template_installer ||= Thread.new do
|
43
43
|
sleep_interval = @retry_initial_interval
|
44
44
|
until successful_connection? || @stopping.true?
|
@@ -46,7 +46,11 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
46
46
|
Stud.stoppable_sleep(sleep_interval) { @stopping.true? }
|
47
47
|
sleep_interval = next_sleep_interval(sleep_interval)
|
48
48
|
end
|
49
|
-
|
49
|
+
if successful_connection?
|
50
|
+
verify_ilm_readiness if ilm_enabled?
|
51
|
+
install_template
|
52
|
+
setup_ilm if ilm_enabled?
|
53
|
+
end
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
@@ -114,7 +118,6 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
114
118
|
client.maximum_seen_major_version
|
115
119
|
end
|
116
120
|
|
117
|
-
|
118
121
|
def routing_field_name
|
119
122
|
maximum_seen_major_version >= 6 ? :routing : :_routing
|
120
123
|
end
|
@@ -353,4 +356,4 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
353
356
|
!execution_context.dlq_writer.inner_writer.is_a?(::LogStash::Util::DummyDeadLetterQueueWriter)
|
354
357
|
end
|
355
358
|
end
|
356
|
-
end
|
359
|
+
end end end
|
@@ -2,6 +2,10 @@ require 'forwardable' # Needed for logstash core SafeURI. We need to patch this
|
|
2
2
|
|
3
3
|
module LogStash; module Outputs; class ElasticSearch
|
4
4
|
module CommonConfigs
|
5
|
+
|
6
|
+
DEFAULT_INDEX_NAME = "logstash-%{+YYYY.MM.dd}"
|
7
|
+
DEFAULT_POLICY = "logstash-policy"
|
8
|
+
|
5
9
|
def self.included(mod)
|
6
10
|
# The index to write events to. This can be dynamic using the `%{foo}` syntax.
|
7
11
|
# The default value will partition your indices by day so you can more easily
|
@@ -10,7 +14,7 @@ module LogStash; module Outputs; class ElasticSearch
|
|
10
14
|
# For weekly indexes ISO 8601 format is recommended, eg. logstash-%{+xxxx.ww}.
|
11
15
|
# LS uses Joda to format the index pattern from event timestamp.
|
12
16
|
# Joda formats are defined http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html[here].
|
13
|
-
mod.config :index, :validate => :string, :default =>
|
17
|
+
mod.config :index, :validate => :string, :default => DEFAULT_INDEX_NAME
|
14
18
|
|
15
19
|
mod.config :document_type,
|
16
20
|
:validate => :string,
|
@@ -136,6 +140,24 @@ module LogStash; module Outputs; class ElasticSearch
|
|
136
140
|
# Set which ingest pipeline you wish to execute for an event. You can also use event dependent configuration
|
137
141
|
# here like `pipeline => "%{INGEST_PIPELINE}"`
|
138
142
|
mod.config :pipeline, :validate => :string, :default => nil
|
143
|
+
|
144
|
+
|
145
|
+
# -----
|
146
|
+
# ILM configurations (beta)
|
147
|
+
# -----
|
148
|
+
# Flag for enabling Index Lifecycle Management integration.
|
149
|
+
mod.config :ilm_enabled, :validate => :boolean, :default => false
|
150
|
+
|
151
|
+
# Rollover alias used for indexing data. If rollover alias doesn't exist, Logstash will create it and map it to the relevant index
|
152
|
+
mod.config :ilm_rollover_alias, :validate => :string, :default => 'logstash'
|
153
|
+
|
154
|
+
# appends “{now/d}-000001” by default for new index creation, subsequent rollover indices will increment based on this pattern i.e. “000002”
|
155
|
+
# {now/d} is date math, and will insert the appropriate value automatically.
|
156
|
+
mod.config :ilm_pattern, :validate => :string, :default => '{now/d}-000001'
|
157
|
+
|
158
|
+
# ILM policy to use, if undefined the default policy will be used.
|
159
|
+
mod.config :ilm_policy, :validate => :string, :default => DEFAULT_POLICY
|
160
|
+
|
139
161
|
end
|
140
162
|
end
|
141
163
|
end end end
|
@@ -337,17 +337,62 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
337
337
|
::LogStash::Util::SafeURI.new(raw_url)
|
338
338
|
end
|
339
339
|
|
340
|
-
def
|
341
|
-
response = @pool.head(
|
340
|
+
def exists?(path, use_get=false)
|
341
|
+
response = use_get ? @pool.get(path) : @pool.head(path)
|
342
342
|
response.code >= 200 && response.code <= 299
|
343
343
|
end
|
344
344
|
|
345
|
+
def template_exists?(name)
|
346
|
+
exists?("/_template/#{name}")
|
347
|
+
end
|
348
|
+
|
345
349
|
def template_put(name, template)
|
346
350
|
path = "_template/#{name}"
|
347
351
|
logger.info("Installing elasticsearch template to #{path}")
|
348
352
|
@pool.put(path, nil, LogStash::Json.dump(template))
|
349
353
|
end
|
350
354
|
|
355
|
+
# ILM methods
|
356
|
+
|
357
|
+
# check whether rollover alias already exists
|
358
|
+
def rollover_alias_exists?(name)
|
359
|
+
exists?(name)
|
360
|
+
end
|
361
|
+
|
362
|
+
# Create a new rollover alias
|
363
|
+
def rollover_alias_put(alias_name, alias_definition)
|
364
|
+
logger.info("Creating rollover alias #{alias_name}")
|
365
|
+
begin
|
366
|
+
@pool.put(CGI::escape(alias_name), nil, LogStash::Json.dump(alias_definition))
|
367
|
+
# If the rollover alias already exists, ignore the error that comes back from Elasticsearch
|
368
|
+
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
|
369
|
+
if e.response_code == 400
|
370
|
+
logger.info("Rollover Alias #{alias_name} already exists. Skipping")
|
371
|
+
return
|
372
|
+
end
|
373
|
+
raise e
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
def get_xpack_info
|
378
|
+
get("/_xpack")
|
379
|
+
end
|
380
|
+
|
381
|
+
def get_ilm_endpoint
|
382
|
+
@pool.get("/_ilm/policy")
|
383
|
+
end
|
384
|
+
|
385
|
+
def ilm_policy_exists?(name)
|
386
|
+
exists?("/_ilm/policy/#{name}", true)
|
387
|
+
end
|
388
|
+
|
389
|
+
def ilm_policy_put(name, policy)
|
390
|
+
path = "_ilm/policy/#{name}"
|
391
|
+
logger.info("Installing ILM policy #{policy} to #{path}")
|
392
|
+
@pool.put(path, nil, LogStash::Json.dump(policy))
|
393
|
+
end
|
394
|
+
|
395
|
+
|
351
396
|
# Build a bulk item for an elasticsearch update action
|
352
397
|
def update_action_builder(args, source)
|
353
398
|
if args[:_script]
|
@@ -103,9 +103,9 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
|
|
103
103
|
end
|
104
104
|
|
105
105
|
request_uri.query = new_query_parts.join("&") unless new_query_parts.empty?
|
106
|
-
|
107
|
-
request_uri.path = "#{request_uri.path}/#{parsed_path_and_query.
|
108
|
-
|
106
|
+
|
107
|
+
request_uri.path = "#{request_uri.path}/#{parsed_path_and_query.raw_path}".gsub(/\/{2,}/, "/")
|
108
|
+
|
109
109
|
request_uri
|
110
110
|
end
|
111
111
|
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module LogStash; module Outputs; class ElasticSearch
|
2
|
+
module Ilm
|
3
|
+
|
4
|
+
ILM_POLICY_PATH = "default-ilm-policy.json"
|
5
|
+
|
6
|
+
def setup_ilm
|
7
|
+
return unless ilm_enabled?
|
8
|
+
@logger.info("Using Index lifecycle management - this feature is currently in beta.")
|
9
|
+
@logger.warn "Overwriting supplied index name with rollover alias #{@ilm_rollover_alias}" if @index != LogStash::Outputs::ElasticSearch::CommonConfigs::DEFAULT_INDEX_NAME
|
10
|
+
@index = ilm_rollover_alias
|
11
|
+
|
12
|
+
maybe_create_rollover_alias
|
13
|
+
maybe_create_ilm_policy
|
14
|
+
end
|
15
|
+
|
16
|
+
def ilm_enabled?
|
17
|
+
@ilm_enabled
|
18
|
+
end
|
19
|
+
|
20
|
+
def verify_ilm_readiness
|
21
|
+
return unless ilm_enabled?
|
22
|
+
|
23
|
+
# Check the Elasticsearch instance for ILM readiness - this means that the version has to be a non-OSS release, with ILM feature
|
24
|
+
# available and enabled.
|
25
|
+
begin
|
26
|
+
xpack = client.get_xpack_info
|
27
|
+
features = xpack["features"]
|
28
|
+
ilm = features.nil? ? nil : features["ilm"]
|
29
|
+
raise LogStash::ConfigurationError, "Index Lifecycle management is enabled in logstash, but not installed on your Elasticsearch cluster" if features.nil? || ilm.nil?
|
30
|
+
raise LogStash::ConfigurationError, "Index Lifecycle management is enabled in logstash, but not available in your Elasticsearch cluster" unless ilm['available']
|
31
|
+
raise LogStash::ConfigurationError, "Index Lifecycle management is enabled in logstash, but not enabled in your Elasticsearch cluster" unless ilm['enabled']
|
32
|
+
|
33
|
+
unless ilm_policy_default? || client.ilm_policy_exists?(ilm_policy)
|
34
|
+
raise LogStash::ConfigurationError, "The specified ILM policy #{ilm_policy} does not exist on your Elasticsearch instance"
|
35
|
+
end
|
36
|
+
|
37
|
+
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
|
38
|
+
# Check xpack endpoint: If no xpack endpoint, then this version of Elasticsearch is not compatible
|
39
|
+
if e.response_code == 404
|
40
|
+
raise LogStash::ConfigurationError, "Index Lifecycle management is enabled in logstash, but not installed on your Elasticsearch cluster"
|
41
|
+
elsif e.response_code == 400
|
42
|
+
raise LogStash::ConfigurationError, "Index Lifecycle management is enabled in logstash, but not installed on your Elasticsearch cluster"
|
43
|
+
else
|
44
|
+
raise e
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def ilm_policy_default?
|
52
|
+
ilm_policy == LogStash::Outputs::ElasticSearch::DEFAULT_POLICY
|
53
|
+
end
|
54
|
+
|
55
|
+
def maybe_create_ilm_policy
|
56
|
+
if ilm_policy_default? && !client.ilm_policy_exists?(ilm_policy)
|
57
|
+
client.ilm_policy_put(ilm_policy, policy_payload)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def maybe_create_rollover_alias
|
62
|
+
client.rollover_alias_put(rollover_alias_target, rollover_alias_payload) unless client.rollover_alias_exists?(ilm_rollover_alias)
|
63
|
+
end
|
64
|
+
|
65
|
+
def rollover_alias_target
|
66
|
+
"<#{ilm_rollover_alias}-#{ilm_pattern}>"
|
67
|
+
end
|
68
|
+
|
69
|
+
def rollover_alias_payload
|
70
|
+
{
|
71
|
+
'aliases' => {
|
72
|
+
ilm_rollover_alias =>{
|
73
|
+
'is_write_index' => true
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def policy_payload
|
80
|
+
policy_path = ::File.expand_path(ILM_POLICY_PATH, ::File.dirname(__FILE__))
|
81
|
+
LogStash::Json.load(::IO.read(policy_path))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end end end
|