Skip to content

Commit d341294

Browse files
authored
Change manage_template default value for data streams (#1111)
This commit changed the `manage_template` default value to false when the data stream is enabled, the option wasn't set by the user, or the `auto` mechanism resolves to true. It also added the `manage_template => false` as a valid data stream configuration. Closes #1093
1 parent 1fef71f commit d341294

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased
2+
- Changed the `manage_template` default value to `false` when data streams is enabled [#1111](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1111)
3+
- Added the `manage_template => false` as a valid data stream option
4+
15
## 11.12.3
26
- Changed the log messages for data stream checks [#1109](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1109)
37
- Added more details about incompatible data streams supplied configurations

Diff for: docs/index.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ Set the keystore password
790790
===== `manage_template`
791791

792792
* Value type is <<boolean,boolean>>
793-
* Default value is `true`
793+
* Default value is `true` for non-time series data, and `false` for data streams.
794794

795795
From Logstash 1.3 onwards, a template is applied to Elasticsearch during
796796
Logstash's startup if one with the name <<plugins-{type}s-{plugin}-template_name>>

Diff for: lib/logstash/outputs/elasticsearch.rb

+11
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
158158
# control over template creation, (e.g. creating indices dynamically based on
159159
# field names) you should set `manage_template` to false and use the REST
160160
# API to apply your templates manually.
161+
#
162+
# Default value is `true` unless data streams is enabled
161163
config :manage_template, :validate => :boolean, :default => true
162164

163165
# This configuration option defines how the template is named inside Elasticsearch.
@@ -304,6 +306,8 @@ def register
304306
# It's being concurrently invoked by this register method and by the finish_register on the @after_successful_connection_thread
305307
data_stream_enabled = data_stream_config?
306308

309+
setup_template_manager_defaults(data_stream_enabled)
310+
307311
@after_successful_connection_thread = after_successful_connection do
308312
begin
309313
finish_register
@@ -608,6 +612,13 @@ def setup_ecs_compatibility_related_defaults
608612
@template_name ||= default_template_name
609613
end
610614

615+
def setup_template_manager_defaults(data_stream_enabled)
616+
if original_params["manage_template"].nil? && data_stream_enabled
617+
logger.debug("Disabling template management since data streams are enabled")
618+
@manage_template = false
619+
end
620+
end
621+
611622
# To be overidden by the -java version
612623
VALID_HTTP_ACTIONS = ["index", "delete", "create", "update"]
613624
def valid_actions

Diff for: lib/logstash/outputs/elasticsearch/data_stream_support.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,15 @@ def invalid_data_stream_params(params)
118118
params.reject do |name, value|
119119
# NOTE: intentionally do not support explicit DS configuration like:
120120
# - `index => ...` identifier provided by data_stream_xxx settings
121-
# - `manage_template => false` implied by not setting the parameter
122121
case name
123122
when 'action'
124123
value == 'create'
125124
when 'routing', 'pipeline'
126125
true
127126
when 'data_stream'
128127
value.to_s == 'true'
128+
when 'manage_template'
129+
value.to_s == 'false'
129130
when 'ecs_compatibility' then true # required for LS <= 6.x
130131
else
131132
name.start_with?('data_stream_') ||

Diff for: spec/unit/outputs/elasticsearch/data_stream_support_spec.rb

+33
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,39 @@
152152

153153
end
154154

155+
context 'ds value-dependent configuration' do
156+
context 'with valid values' do
157+
let(:options) { super().merge(
158+
'action' => 'create',
159+
'routing' => 'any',
160+
'pipeline' => 'any',
161+
'manage_template' => 'false',
162+
'data_stream' => 'true',
163+
'data_stream_type' => 'logs',
164+
'data_stream_dataset' => 'any',
165+
'data_stream_namespace' => 'any',
166+
'data_stream_sync_fields' => true,
167+
'data_stream_auto_routing' => true)
168+
}
169+
170+
it 'should enable data-streams by default' do
171+
expect( subject.data_stream_config? ).to be_truthy
172+
end
173+
end
174+
175+
context 'with invalid values' do
176+
let(:options) { super().merge(
177+
'data_stream' => 'true',
178+
'action' => 'index',
179+
'manage_template' => 'true')
180+
}
181+
182+
it 'should raise a configuration error' do
183+
expect { subject.data_stream_config? }.to raise_error(LogStash::ConfigurationError, 'Invalid data stream configuration: ["action", "manage_template"]')
184+
end
185+
end
186+
end
187+
155188
context "default (non data-stream) configuration (on 7.x)" do
156189

157190
let(:options) do

Diff for: spec/unit/outputs/elasticsearch_spec.rb

+22-2
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,26 @@
606606
end
607607
end
608608

609+
describe "the manage_template option" do
610+
context "with data stream enabled" do
611+
let(:options) { {"data_stream" => "true", "data_stream_type" => "logs" } }
612+
let(:do_register) { true }
613+
614+
it "should default to false" do
615+
expect(subject).to have_attributes(manage_template: false)
616+
end
617+
end
618+
619+
context "with data stream disabled" do
620+
let(:options) { {"data_stream" => "false", "index" => "logs" } }
621+
let(:do_register) { true }
622+
623+
it "should default to true" do
624+
expect(subject).to have_attributes(manage_template: true)
625+
end
626+
end
627+
end
628+
609629
describe "SSL end to end" do
610630
let(:do_register) { false } # skip the register in the global before block, as is called here.
611631

@@ -870,7 +890,7 @@
870890
end if LOGSTASH_VERSION > '6.0'
871891

872892
context 'handling elasticsearch document-level status meant for the DLQ' do
873-
let(:options) { { "manage_template" => false } }
893+
let(:options) { { "manage_template" => false, "data_stream" => 'false' } }
874894
let(:action) { LogStash::Outputs::ElasticSearch::EventActionTuple.new(:action, :params, LogStash::Event.new("foo" => "bar")) }
875895

876896
context 'when @dlq_writer is nil' do
@@ -1140,7 +1160,7 @@
11401160
describe "post-register ES setup" do
11411161
let(:do_register) { false }
11421162
let(:es_version) { '7.10.0' } # DS default on LS 8.x
1143-
let(:options) { { 'hosts' => '127.0.0.1:9999' } }
1163+
let(:options) { { 'hosts' => '127.0.0.1:9999', 'data_stream' => 'false' } }
11441164
let(:logger) { subject.logger }
11451165

11461166
before do

0 commit comments

Comments
 (0)