Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8804933

Browse files
flaper87jsvd
andcommittedAug 13, 2020
Don't set the pipeline parameter if the value resolves to an empty string
bump to 10.7.0 Co-authored-by: João Duarte <[email protected]>
1 parent 6a16a39 commit 8804933

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed
 

‎CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 10.7.0
2+
- Changed: don't set the pipeline parameter if the value resolves to an empty string [#962](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/962)
3+
14
## 10.6.2
25
- [DOC] Added clarifying info on http compression settings and behaviors [#943](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/943)
36
- [DOC] Fixed entry for ilm_policy default value[#956](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/956)

‎docs/index.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,8 @@ not also set this field. That will raise an error at startup
647647
* Value type is <<string,string>>
648648
* Default value is `nil`
649649

650-
Set which ingest pipeline you wish to execute for an event. You can also use event dependent configuration
651-
here like `pipeline => "%{INGEST_PIPELINE}"`
650+
Set which ingest pipeline you wish to execute for an event. You can also use event dependent configuration here
651+
like `pipeline => "%{[@metadata][pipeline]}"`. The pipeline parameter won't be set if the value resolves to empty string ("").
652652

653653
[id="plugins-{type}s-{plugin}-pool_max"]
654654
===== `pool_max`

‎lib/logstash/outputs/elasticsearch/common.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ def event_action_tuple(event)
8484
params[:_type] = get_event_type(event) if use_event_type?(nil)
8585

8686
if @pipeline
87-
params[:pipeline] = event.sprintf(@pipeline)
87+
value = event.sprintf(@pipeline)
88+
# convention: empty string equates to not using a pipeline
89+
# this is useful when using a field reference in the pipeline setting, e.g.
90+
# elasticsearch {
91+
# pipeline => "%{[@metadata][pipeline]}"
92+
# }
93+
params[:pipeline] = value unless value.empty?
8894
end
8995

9096
if @parent

‎logstash-output-elasticsearch.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-output-elasticsearch'
3-
s.version = '10.6.2'
3+
s.version = '10.7.0'
44

55
s.licenses = ['apache-2.0']
66
s.summary = "Stores logs in Elasticsearch"

‎spec/unit/outputs/elasticsearch_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,28 @@
355355
end
356356
end
357357

358+
describe "the pipeline option" do
359+
context "with a sprintf and set pipeline" do
360+
let(:options) { {"pipeline" => "%{pipeline}" } }
361+
362+
let(:event) { LogStash::Event.new("pipeline" => "my-ingest-pipeline") }
363+
364+
it "should interpolate the pipeline value and set it" do
365+
expect(subject.event_action_tuple(event)[1]).to include(:pipeline => "my-ingest-pipeline")
366+
end
367+
end
368+
369+
context "with a sprintf and empty pipeline" do
370+
let(:options) { {"pipeline" => "%{pipeline}" } }
371+
372+
let(:event) { LogStash::Event.new("pipeline" => "") }
373+
374+
it "should interpolate the pipeline value but not set it because it is empty" do
375+
expect(subject.event_action_tuple(event)[1]).not_to include(:pipeline)
376+
end
377+
end
378+
end
379+
358380
describe "SSL end to end" do
359381
let(:do_register) { false } # skip the register in the global before block, as is called here.
360382

0 commit comments

Comments
 (0)
Please sign in to comment.