Skip to content

Commit 77ca162

Browse files
authored
Avoid to populate version and version type attributes when processing integration metadata and datastream is enabled (#1161)
During PR #1155 the resolution of version and version_type ES parameters was moved from the index only event action tuple creation to the common method. This changed was due to do the intent to collect all integration-aware metadata fields in one place, but the common method is used also by the datastream part this result in populating event and event_type request parameters not only for normal index operations. During an index operation on a datastream, if one of those parameters is valued, generated an error on ES indexing, resulting in request fail. This PR move the processing and creation of event and event_type parameters, back in its original position, splitting the capture of integration metadata in 2 parts.
1 parent cfd82fa commit 77ca162

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 11.22.1
2+
- Fix, avoid to populate `version` and `version_type` attributes when processing integration metadata and datastream is enabled. [#1161](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1161)
3+
14
## 11.22.0
25
- Added support for propagating event processing metadata when this output is downstream of an Elastic Integration Filter and configured _without_ explicit `version`, `version_type`, or `routing` directives [#1158](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1158)
36

lib/logstash/outputs/elasticsearch.rb

+11-7
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,16 @@ def event_action_tuple(event)
499499
params[retry_on_conflict_action_name] = @retry_on_conflict
500500
end
501501

502+
event_control = event.get("[@metadata][_ingest_document]")
503+
event_version, event_version_type = event_control&.values_at("version", "version_type") rescue nil
504+
505+
resolved_version = resolve_version(event, event_version)
506+
resolved_version_type = resolve_version_type(event, event_version_type)
507+
508+
# avoid to add nil valued key-value pairs
509+
params[:version] = resolved_version unless resolved_version.nil?
510+
params[:version_type] = resolved_version_type unless resolved_version_type.nil?
511+
502512
EventActionTuple.new(action, params, event)
503513
end
504514

@@ -538,7 +548,7 @@ def initialize(bad_action)
538548
# @private shared event params factory between index and data_stream mode
539549
def common_event_params(event)
540550
event_control = event.get("[@metadata][_ingest_document]")
541-
event_id, event_pipeline, event_index, event_routing, event_version, event_version_type = event_control&.values_at("id","pipeline","index", "routing", "version", "version_type") rescue nil
551+
event_id, event_pipeline, event_index, event_routing = event_control&.values_at("id","pipeline","index", "routing") rescue nil
542552

543553
params = {
544554
:_id => resolve_document_id(event, event_id),
@@ -554,12 +564,6 @@ def common_event_params(event)
554564
# }
555565
params[:pipeline] = target_pipeline unless (target_pipeline.nil? || target_pipeline.empty?)
556566

557-
resolved_version = resolve_version(event, event_version)
558-
resolved_version_type = resolve_version_type(event, event_version_type)
559-
# avoid to add nil valued key-value pairs
560-
params[:version] = resolved_version unless resolved_version.nil?
561-
params[:version_type] = resolved_version_type unless resolved_version_type.nil?
562-
563567
params
564568
end
565569

logstash-output-elasticsearch.gemspec

+1-1
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 = '11.22.0'
3+
s.version = '11.22.1'
44
s.licenses = ['apache-2.0']
55
s.summary = "Stores logs in Elasticsearch"
66
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"

spec/unit/outputs/elasticsearch_spec.rb

+26-4
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,19 @@
297297
context "when the event contains an integration metadata version" do
298298
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"version" => "456"}}}) }
299299

300-
it "event's metadata version is used" do
301-
expect(subject.send(:event_action_tuple, event)[1]).to include(:version => "456")
300+
context "when datastream settings are NOT configured" do
301+
it "event's metadata version is used" do
302+
expect(subject.send(:event_action_tuple, event)[1]).to include(:version => "456")
303+
end
304+
end
305+
306+
context "when datastream settings are configured" do
307+
# NOTE: we validate with datastream-specific `data_stream_event_action_tuple`
308+
let(:event_fields) { super().merge({"data_stream" => {"type" => "logs", "dataset" => "generic", "namespace" => "default"}}) }
309+
310+
it "no version is used" do
311+
expect(subject.send(:data_stream_event_action_tuple, event)[1]).to_not include(:version)
312+
end
302313
end
303314
end
304315

@@ -315,8 +326,19 @@
315326
context "when the event contains an integration metadata version_type" do
316327
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"version_type" => "external"}}}) }
317328

318-
it "plugin's version_type is used" do
319-
expect(subject.send(:event_action_tuple, event)[1]).to include(:version_type => "internal")
329+
context "when datastream settings are NOT configured" do
330+
it "plugin's version_type is used" do
331+
expect(subject.send(:event_action_tuple, event)[1]).to include(:version_type => "internal")
332+
end
333+
end
334+
335+
context "when datastream settings are configured" do
336+
# NOTE: we validate with datastream-specific `data_stream_event_action_tuple`
337+
let(:event_fields) { super().merge({"data_stream" => {"type" => "logs", "dataset" => "generic", "namespace" => "default"}}) }
338+
339+
it "no version_type is used" do
340+
expect(subject.send(:data_stream_event_action_tuple, event)[1]).to_not include(:version_type)
341+
end
320342
end
321343
end
322344

0 commit comments

Comments
 (0)