logstash-output-opensearch 1.0.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/ADMINS.md +29 -0
- data/CODE_OF_CONDUCT.md +25 -0
- data/CONTRIBUTING.md +99 -0
- data/DEVELOPER_GUIDE.md +208 -0
- data/Gemfile +20 -0
- data/LICENSE +202 -0
- data/MAINTAINERS.md +71 -0
- data/NOTICE +2 -0
- data/README.md +37 -0
- data/RELEASING.md +36 -0
- data/SECURITY.md +3 -0
- data/lib/logstash/outputs/opensearch.rb +449 -0
- data/lib/logstash/outputs/opensearch/distribution_checker.rb +44 -0
- data/lib/logstash/outputs/opensearch/http_client.rb +465 -0
- data/lib/logstash/outputs/opensearch/http_client/manticore_adapter.rb +140 -0
- data/lib/logstash/outputs/opensearch/http_client/pool.rb +467 -0
- data/lib/logstash/outputs/opensearch/http_client_builder.rb +182 -0
- data/lib/logstash/outputs/opensearch/template_manager.rb +60 -0
- data/lib/logstash/outputs/opensearch/templates/ecs-disabled/1x.json +44 -0
- data/lib/logstash/outputs/opensearch/templates/ecs-disabled/7x.json +44 -0
- data/lib/logstash/plugin_mixins/opensearch/api_configs.rb +168 -0
- data/lib/logstash/plugin_mixins/opensearch/common.rb +294 -0
- data/lib/logstash/plugin_mixins/opensearch/noop_distribution_checker.rb +18 -0
- data/logstash-output-opensearch.gemspec +40 -0
- data/spec/fixtures/_nodes/nodes.json +74 -0
- data/spec/fixtures/htpasswd +2 -0
- data/spec/fixtures/nginx_reverse_proxy.conf +22 -0
- data/spec/fixtures/scripts/painless/scripted_update.painless +2 -0
- data/spec/fixtures/scripts/painless/scripted_update_nested.painless +1 -0
- data/spec/fixtures/scripts/painless/scripted_upsert.painless +1 -0
- data/spec/integration/outputs/compressed_indexing_spec.rb +76 -0
- data/spec/integration/outputs/create_spec.rb +76 -0
- data/spec/integration/outputs/delete_spec.rb +72 -0
- data/spec/integration/outputs/index_spec.rb +164 -0
- data/spec/integration/outputs/index_version_spec.rb +110 -0
- data/spec/integration/outputs/ingest_pipeline_spec.rb +82 -0
- data/spec/integration/outputs/metrics_spec.rb +75 -0
- data/spec/integration/outputs/no_opensearch_on_startup_spec.rb +67 -0
- data/spec/integration/outputs/painless_update_spec.rb +147 -0
- data/spec/integration/outputs/parent_spec.rb +103 -0
- data/spec/integration/outputs/retry_spec.rb +182 -0
- data/spec/integration/outputs/routing_spec.rb +70 -0
- data/spec/integration/outputs/sniffer_spec.rb +70 -0
- data/spec/integration/outputs/templates_spec.rb +105 -0
- data/spec/integration/outputs/update_spec.rb +123 -0
- data/spec/opensearch_spec_helper.rb +141 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/unit/http_client_builder_spec.rb +194 -0
- data/spec/unit/outputs/error_whitelist_spec.rb +62 -0
- data/spec/unit/outputs/opensearch/http_client/manticore_adapter_spec.rb +159 -0
- data/spec/unit/outputs/opensearch/http_client/pool_spec.rb +306 -0
- data/spec/unit/outputs/opensearch/http_client_spec.rb +292 -0
- data/spec/unit/outputs/opensearch/template_manager_spec.rb +36 -0
- data/spec/unit/outputs/opensearch_proxy_spec.rb +112 -0
- data/spec/unit/outputs/opensearch_spec.rb +800 -0
- data/spec/unit/outputs/opensearch_ssl_spec.rb +179 -0
- metadata +289 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
|
+
#
|
3
|
+
# The OpenSearch Contributors require contributions made to
|
4
|
+
# this file be licensed under the Apache-2.0 license or a
|
5
|
+
# compatible open source license.
|
6
|
+
#
|
7
|
+
# Modifications Copyright OpenSearch Contributors. See
|
8
|
+
# GitHub history for details.
|
9
|
+
|
10
|
+
require_relative "../../../spec/opensearch_spec_helper"
|
11
|
+
|
12
|
+
describe "Ingest pipeline execution behavior", :integration => true do
|
13
|
+
subject! do
|
14
|
+
require "logstash/outputs/opensearch"
|
15
|
+
settings = {
|
16
|
+
"hosts" => "#{get_host_port()}",
|
17
|
+
"pipeline" => "apache-logs"
|
18
|
+
}
|
19
|
+
next LogStash::Outputs::OpenSearch.new(settings)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:http_client) { Manticore::Client.new }
|
23
|
+
let(:ingest_url) { "http://#{get_host_port()}/_ingest/pipeline/apache-logs" }
|
24
|
+
let(:apache_logs_pipeline) { '
|
25
|
+
{
|
26
|
+
"description" : "Pipeline to parse Apache logs",
|
27
|
+
"processors" : [
|
28
|
+
{
|
29
|
+
"grok": {
|
30
|
+
"field": "message",
|
31
|
+
"patterns": ["%{COMBINEDAPACHELOG}"]
|
32
|
+
}
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}'
|
36
|
+
}
|
37
|
+
|
38
|
+
before :each do
|
39
|
+
# Delete all templates first.
|
40
|
+
require "elasticsearch"
|
41
|
+
|
42
|
+
# Clean OpenSearch of data before we start.
|
43
|
+
@client = get_client
|
44
|
+
@client.indices.delete_template(:name => "*")
|
45
|
+
|
46
|
+
# This can fail if there are no indexes, ignore failure.
|
47
|
+
@client.indices.delete(:index => "*") rescue nil
|
48
|
+
|
49
|
+
# delete existing ingest pipeline
|
50
|
+
http_client.delete(ingest_url).call
|
51
|
+
|
52
|
+
# register pipeline
|
53
|
+
http_client.put(ingest_url, :body => apache_logs_pipeline, :headers => {"Content-Type" => "application/json" }).call
|
54
|
+
|
55
|
+
#TODO: Use esclient
|
56
|
+
#@client.ingest.put_pipeline :id => 'apache_pipeline', :body => pipeline_defintion
|
57
|
+
|
58
|
+
subject.register
|
59
|
+
subject.multi_receive([LogStash::Event.new("message" => '183.60.215.50 - - [01/Jun/2015:18:00:00 +0000] "GET /scripts/netcat-webserver HTTP/1.1" 200 182 "-" "Mozilla/5.0 (compatible; EasouSpider; +http://www.easou.com/search/spider.html)"')])
|
60
|
+
@client.indices.refresh
|
61
|
+
|
62
|
+
#Wait or fail until everything's indexed.
|
63
|
+
Stud::try(10.times) do
|
64
|
+
r = @client.search(index: 'logstash-*')
|
65
|
+
expect(r).to have_hits(1)
|
66
|
+
sleep(0.1)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "indexes using the proper pipeline" do
|
71
|
+
results = @client.search(:index => 'logstash-*', :q => "message:\"netcat\"")
|
72
|
+
expect(results).to have_hits(1)
|
73
|
+
expect(results["hits"]["hits"][0]["_source"]["response"]).to eq("200")
|
74
|
+
expect(results["hits"]["hits"][0]["_source"]["bytes"]).to eq("182")
|
75
|
+
expect(results["hits"]["hits"][0]["_source"]["verb"]).to eq("GET")
|
76
|
+
expect(results["hits"]["hits"][0]["_source"]["request"]).to eq("/scripts/netcat-webserver")
|
77
|
+
expect(results["hits"]["hits"][0]["_source"]["auth"]).to eq("-")
|
78
|
+
expect(results["hits"]["hits"][0]["_source"]["ident"]).to eq("-")
|
79
|
+
expect(results["hits"]["hits"][0]["_source"]["clientip"]).to eq("183.60.215.50")
|
80
|
+
expect(results["hits"]["hits"][0]["_source"]["junkfieldaaaa"]).to eq(nil)
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
|
+
#
|
3
|
+
# The OpenSearch Contributors require contributions made to
|
4
|
+
# this file be licensed under the Apache-2.0 license or a
|
5
|
+
# compatible open source license.
|
6
|
+
#
|
7
|
+
# Modifications Copyright OpenSearch Contributors. See
|
8
|
+
# GitHub history for details.
|
9
|
+
|
10
|
+
require_relative "../../../spec/opensearch_spec_helper"
|
11
|
+
|
12
|
+
describe "metrics", :integration => true do
|
13
|
+
subject! do
|
14
|
+
require "logstash/outputs/opensearch"
|
15
|
+
settings = {
|
16
|
+
"manage_template" => false,
|
17
|
+
"hosts" => "#{get_host_port()}"
|
18
|
+
}
|
19
|
+
plugin = LogStash::Outputs::OpenSearch.new(settings)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:metric) { subject.metric }
|
23
|
+
let(:bulk_request_metrics) { subject.instance_variable_get(:@bulk_request_metrics) }
|
24
|
+
let(:document_level_metrics) { subject.instance_variable_get(:@document_level_metrics) }
|
25
|
+
|
26
|
+
before :each do
|
27
|
+
require "elasticsearch"
|
28
|
+
|
29
|
+
# Clean OpenSearch of data before we start.
|
30
|
+
@client = get_client
|
31
|
+
clean(@client)
|
32
|
+
subject.register
|
33
|
+
end
|
34
|
+
|
35
|
+
context "after a succesful bulk insert" do
|
36
|
+
let(:bulk) { [
|
37
|
+
LogStash::Event.new("message" => "sample message here"),
|
38
|
+
LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
|
39
|
+
LogStash::Event.new("somevalue" => 100),
|
40
|
+
LogStash::Event.new("somevalue" => 10),
|
41
|
+
LogStash::Event.new("somevalue" => 1),
|
42
|
+
LogStash::Event.new("country" => "us"),
|
43
|
+
LogStash::Event.new("country" => "at"),
|
44
|
+
LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
|
45
|
+
]}
|
46
|
+
|
47
|
+
it "increases successful bulk request metric" do
|
48
|
+
expect(bulk_request_metrics).to receive(:increment).with(:successes).once
|
49
|
+
subject.multi_receive(bulk)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "increases number of successful inserted documents" do
|
53
|
+
expect(document_level_metrics).to receive(:increment).with(:successes, bulk.size).once
|
54
|
+
subject.multi_receive(bulk)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "after a bulk insert that generates errors" do
|
59
|
+
let(:bulk) { [
|
60
|
+
LogStash::Event.new("message" => "sample message here"),
|
61
|
+
LogStash::Event.new("message" => { "message" => "sample nested message here" }),
|
62
|
+
]}
|
63
|
+
it "increases bulk request with error metric" do
|
64
|
+
expect(bulk_request_metrics).to receive(:increment).with(:with_errors).once
|
65
|
+
expect(bulk_request_metrics).to_not receive(:increment).with(:successes)
|
66
|
+
subject.multi_receive(bulk)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "increases number of successful and non retryable documents" do
|
70
|
+
expect(document_level_metrics).to receive(:increment).with(:non_retryable_failures).once
|
71
|
+
expect(document_level_metrics).to receive(:increment).with(:successes).once
|
72
|
+
subject.multi_receive(bulk)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
|
+
#
|
3
|
+
# The OpenSearch Contributors require contributions made to
|
4
|
+
# this file be licensed under the Apache-2.0 license or a
|
5
|
+
# compatible open source license.
|
6
|
+
#
|
7
|
+
# Modifications Copyright OpenSearch Contributors. See
|
8
|
+
# GitHub history for details.
|
9
|
+
|
10
|
+
require "logstash/outputs/opensearch"
|
11
|
+
require_relative "../../../spec/opensearch_spec_helper"
|
12
|
+
|
13
|
+
describe "opensearch is down on startup", :integration => true do
|
14
|
+
let(:event1) { LogStash::Event.new("somevalue" => 100, "@timestamp" => "2014-11-17T20:37:17.223Z", "@metadata" => {"retry_count" => 0}) }
|
15
|
+
let(:event2) { LogStash::Event.new("message" => "a") }
|
16
|
+
|
17
|
+
subject {
|
18
|
+
LogStash::Outputs::OpenSearch.new({
|
19
|
+
"manage_template" => true,
|
20
|
+
"index" => "logstash-2014.11.17",
|
21
|
+
"template_overwrite" => true,
|
22
|
+
"hosts" => get_host_port(),
|
23
|
+
"retry_max_interval" => 64,
|
24
|
+
"retry_initial_interval" => 2
|
25
|
+
})
|
26
|
+
}
|
27
|
+
|
28
|
+
before :each do
|
29
|
+
# Delete all templates first.
|
30
|
+
require "elasticsearch"
|
31
|
+
allow(Stud).to receive(:stoppable_sleep)
|
32
|
+
|
33
|
+
# Clean OpenSearch of data before we start.
|
34
|
+
@client = get_client
|
35
|
+
@client.indices.delete_template(:name => "*")
|
36
|
+
@client.indices.delete(:index => "*")
|
37
|
+
@client.indices.refresh
|
38
|
+
end
|
39
|
+
|
40
|
+
after :each do
|
41
|
+
subject.close
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should ingest events when OpenSearch recovers before documents are sent' do
|
45
|
+
allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_version).and_raise(::LogStash::Outputs::OpenSearch::HttpClient::Pool::HostUnreachableError.new(StandardError.new, "big fail"))
|
46
|
+
subject.register
|
47
|
+
allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_version).and_return(OpenSearchHelper.version)
|
48
|
+
subject.multi_receive([event1, event2])
|
49
|
+
@client.indices.refresh
|
50
|
+
r = @client.search(index: 'logstash-*')
|
51
|
+
expect(r).to have_hits(2)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should ingest events when OpenSearch recovers after documents are sent' do
|
55
|
+
allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_version).and_raise(::LogStash::Outputs::OpenSearch::HttpClient::Pool::HostUnreachableError.new(StandardError.new, "big fail"))
|
56
|
+
subject.register
|
57
|
+
Thread.new do
|
58
|
+
sleep 4
|
59
|
+
allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_version).and_return(OpenSearchHelper.version)
|
60
|
+
end
|
61
|
+
subject.multi_receive([event1, event2])
|
62
|
+
@client.indices.refresh
|
63
|
+
r = @client.search(index: 'logstash-*')
|
64
|
+
expect(r).to have_hits(2)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
|
+
#
|
3
|
+
# The OpenSearch Contributors require contributions made to
|
4
|
+
# this file be licensed under the Apache-2.0 license or a
|
5
|
+
# compatible open source license.
|
6
|
+
#
|
7
|
+
# Modifications Copyright OpenSearch Contributors. See
|
8
|
+
# GitHub history for details.
|
9
|
+
|
10
|
+
require_relative "../../../spec/opensearch_spec_helper"
|
11
|
+
|
12
|
+
describe "Update actions using painless scripts", :integration => true, :update_tests => 'painless' do
|
13
|
+
require "logstash/outputs/opensearch"
|
14
|
+
|
15
|
+
def get_es_output( options={} )
|
16
|
+
settings = {
|
17
|
+
"manage_template" => true,
|
18
|
+
"index" => "logstash-update",
|
19
|
+
"template_overwrite" => true,
|
20
|
+
"hosts" => get_host_port(),
|
21
|
+
"action" => "update"
|
22
|
+
}
|
23
|
+
LogStash::Outputs::OpenSearch.new(settings.merge!(options))
|
24
|
+
end
|
25
|
+
|
26
|
+
before :each do
|
27
|
+
@client = get_client
|
28
|
+
# Delete all templates first.
|
29
|
+
# Clean OpenSearch of data before we start.
|
30
|
+
@client.indices.delete_template(:name => "*")
|
31
|
+
# This can fail if there are no indexes, ignore failure.
|
32
|
+
@client.indices.delete(:index => "*") rescue nil
|
33
|
+
@client.index(
|
34
|
+
:index => 'logstash-update',
|
35
|
+
:type => doc_type,
|
36
|
+
:id => "123",
|
37
|
+
:body => { :message => 'Test', :counter => 1 }
|
38
|
+
)
|
39
|
+
@client.indices.refresh
|
40
|
+
end
|
41
|
+
|
42
|
+
context "scripted updates" do
|
43
|
+
|
44
|
+
it "should increment a counter with event/doc 'count' variable with inline script" do
|
45
|
+
subject = get_es_output({
|
46
|
+
'document_id' => "123",
|
47
|
+
'script' => 'ctx._source.counter += params.event.counter',
|
48
|
+
'script_type' => 'inline'
|
49
|
+
})
|
50
|
+
subject.register
|
51
|
+
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
52
|
+
r = @client.get(:index => 'logstash-update', :type => doc_type, :id => "123", :refresh => true)
|
53
|
+
expect(r["_source"]["counter"]).to eq(4)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should increment a counter with event/doc 'count' variable with event/doc as upsert and inline script" do
|
57
|
+
subject = get_es_output({
|
58
|
+
'document_id' => "123",
|
59
|
+
'doc_as_upsert' => true,
|
60
|
+
'script' => 'if( ctx._source.containsKey("counter") ){ ctx._source.counter += params.event.counter; } else { ctx._source.counter = params.event.counter; }',
|
61
|
+
'script_type' => 'inline'
|
62
|
+
})
|
63
|
+
subject.register
|
64
|
+
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
65
|
+
r = @client.get(:index => 'logstash-update', :type => doc_type, :id => "123", :refresh => true)
|
66
|
+
expect(r["_source"]["counter"]).to eq(4)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should, with new doc, set a counter with event/doc 'count' variable with event/doc as upsert and inline script" do
|
70
|
+
subject = get_es_output({
|
71
|
+
'document_id' => "456",
|
72
|
+
'doc_as_upsert' => true,
|
73
|
+
'script' => 'if( ctx._source.containsKey("counter") ){ ctx._source.counter += params.event.counter; } else { ctx._source.counter = params.event.counter; }',
|
74
|
+
'script_type' => 'inline'
|
75
|
+
})
|
76
|
+
subject.register
|
77
|
+
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
78
|
+
r = @client.get(:index => 'logstash-update', :type => doc_type, :id => "456", :refresh => true)
|
79
|
+
expect(r["_source"]["counter"]).to eq(3)
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'with an indexed script' do
|
83
|
+
it "should increment a counter with event/doc 'count' variable with indexed script" do
|
84
|
+
@client.perform_request(:put, "_scripts/indexed_update", {}, {"script" => {"source" => "ctx._source.counter += params.event.count", "lang" => "painless"}})
|
85
|
+
plugin_parameters = {
|
86
|
+
'document_id' => "123",
|
87
|
+
'script' => 'indexed_update',
|
88
|
+
'script_type' => 'indexed'
|
89
|
+
}
|
90
|
+
|
91
|
+
plugin_parameters.merge!('script_lang' => '')
|
92
|
+
|
93
|
+
subject = get_es_output(plugin_parameters)
|
94
|
+
subject.register
|
95
|
+
subject.multi_receive([LogStash::Event.new("count" => 4 )])
|
96
|
+
r = @client.get(:index => 'logstash-update', :type => doc_type, :id => "123", :refresh => true)
|
97
|
+
expect(r["_source"]["counter"]).to eq(5)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when update with upsert" do
|
103
|
+
it "should create new documents with provided upsert" do
|
104
|
+
subject = get_es_output({ 'document_id' => "456", 'upsert' => '{"message": "upsert message"}' })
|
105
|
+
subject.register
|
106
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
107
|
+
r = @client.get(:index => 'logstash-update', :type => doc_type, :id => "456", :refresh => true)
|
108
|
+
expect(r["_source"]["message"]).to eq('upsert message')
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should create new documents with event/doc as upsert" do
|
112
|
+
subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true })
|
113
|
+
subject.register
|
114
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
115
|
+
r = @client.get(:index => 'logstash-update', :type => doc_type, :id => "456", :refresh => true)
|
116
|
+
expect(r["_source"]["message"]).to eq('sample message here')
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should fail on documents with event/doc as upsert at external version" do
|
120
|
+
subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true, 'version' => 999, "version_type" => "external" })
|
121
|
+
expect { subject.register }.to raise_error(LogStash::ConfigurationError)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "updates with scripted upsert" do
|
126
|
+
|
127
|
+
context 'with an inline script' do
|
128
|
+
it "should create new documents with upsert content" do
|
129
|
+
subject = get_es_output({ 'document_id' => "456", 'script' => 'ctx._source.counter = params.event.counter', 'upsert' => '{"message": "upsert message"}', 'script_type' => 'inline' })
|
130
|
+
subject.register
|
131
|
+
|
132
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
133
|
+
r = @client.get(:index => 'logstash-update', :type => doc_type, :id => "456", :refresh => true)
|
134
|
+
expect(r["_source"]["message"]).to eq('upsert message')
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should create new documents with event/doc as script params" do
|
138
|
+
subject = get_es_output({ 'document_id' => "456", 'script' => 'ctx._source.counter = params.event.counter', 'scripted_upsert' => true, 'script_type' => 'inline' })
|
139
|
+
subject.register
|
140
|
+
subject.multi_receive([LogStash::Event.new("counter" => 1)])
|
141
|
+
@client.indices.refresh
|
142
|
+
r = @client.get(:index => 'logstash-update', :type => doc_type, :id => "456", :refresh => true)
|
143
|
+
expect(r["_source"]["counter"]).to eq(1)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
|
+
#
|
3
|
+
# The OpenSearch Contributors require contributions made to
|
4
|
+
# this file be licensed under the Apache-2.0 license or a
|
5
|
+
# compatible open source license.
|
6
|
+
#
|
7
|
+
# Modifications Copyright OpenSearch Contributors. See
|
8
|
+
# GitHub history for details.
|
9
|
+
|
10
|
+
require_relative "../../../spec/opensearch_spec_helper"
|
11
|
+
require "logstash/outputs/opensearch"
|
12
|
+
|
13
|
+
context "join field tests", :integration => true do
|
14
|
+
|
15
|
+
shared_examples "a join field based parent indexer" do
|
16
|
+
let(:index) { 10.times.collect { rand(10).to_s }.join("") }
|
17
|
+
|
18
|
+
let(:type) { "_doc" }
|
19
|
+
|
20
|
+
let(:event_count) { 10000 + rand(500) }
|
21
|
+
let(:parent) { "not_implemented" }
|
22
|
+
let(:config) { "not_implemented" }
|
23
|
+
let(:parent_id) { "test" }
|
24
|
+
let(:join_field) { "join_field" }
|
25
|
+
let(:parent_relation) { "parent_type" }
|
26
|
+
let(:child_relation) { "child_type" }
|
27
|
+
let(:default_headers) {
|
28
|
+
{"Content-Type" => "application/json"}
|
29
|
+
}
|
30
|
+
subject { LogStash::Outputs::OpenSearch.new(config) }
|
31
|
+
|
32
|
+
before do
|
33
|
+
# Add mapping and a parent document
|
34
|
+
index_url = "http://#{get_host_port()}/#{index}"
|
35
|
+
|
36
|
+
properties = {
|
37
|
+
"properties" => {
|
38
|
+
join_field => {
|
39
|
+
"type" => "join",
|
40
|
+
"relations" => { parent_relation => child_relation }
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
mapping = { "mappings" => properties}
|
46
|
+
|
47
|
+
Manticore.put("#{index_url}", {:body => mapping.to_json, :headers => default_headers}).call
|
48
|
+
pdoc = { "message" => "ohayo", join_field => parent_relation }
|
49
|
+
Manticore.put("#{index_url}/#{type}/#{parent_id}", {:body => pdoc.to_json, :headers => default_headers}).call
|
50
|
+
|
51
|
+
subject.register
|
52
|
+
subject.multi_receive(event_count.times.map { LogStash::Event.new("link_to" => parent_id, "message" => "Hello World!", join_field => child_relation) })
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
it "ships events" do
|
57
|
+
index_url = "http://#{get_host_port()}/#{index}"
|
58
|
+
|
59
|
+
Manticore.post("#{index_url}/_refresh").call
|
60
|
+
|
61
|
+
# Wait until all events are available.
|
62
|
+
Stud::try(10.times) do
|
63
|
+
query = { "query" => { "has_parent" => { "parent_type" => parent_relation, "query" => { "match_all" => { } } } } }
|
64
|
+
response = Manticore.post("#{index_url}/_count", {:body => query.to_json, :headers => default_headers})
|
65
|
+
data = response.body
|
66
|
+
result = LogStash::Json.load(data)
|
67
|
+
cur_count = result["count"]
|
68
|
+
expect(cur_count).to eq(event_count)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "(http protocol) index events with static parent" do
|
74
|
+
it_behaves_like 'a join field based parent indexer' do
|
75
|
+
let(:config) {
|
76
|
+
{
|
77
|
+
"hosts" => get_host_port,
|
78
|
+
"index" => index,
|
79
|
+
"parent" => parent_id,
|
80
|
+
"document_type" => type,
|
81
|
+
"join_field" => join_field,
|
82
|
+
"manage_template" => false
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "(http_protocol) index events with fieldref in parent value" do
|
89
|
+
it_behaves_like 'a join field based parent indexer' do
|
90
|
+
let(:config) {
|
91
|
+
{
|
92
|
+
"hosts" => get_host_port,
|
93
|
+
"index" => index,
|
94
|
+
"parent" => "%{link_to}",
|
95
|
+
"document_type" => type,
|
96
|
+
"join_field" => join_field,
|
97
|
+
"manage_template" => false
|
98
|
+
}
|
99
|
+
}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|