logstash-output-opensearch 1.3.0-java → 2.0.2-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.
@@ -199,6 +199,13 @@ class LogStash::Outputs::OpenSearch < LogStash::Outputs::Base
199
199
  # Set which ingest pipeline you wish to execute for an event. You can also use event dependent configuration
200
200
  # here like `pipeline => "%{INGEST_PIPELINE}"`
201
201
  config :pipeline, :validate => :string, :default => nil
202
+
203
+ # When set to true, use legacy templates via the _template API
204
+ # When false, use index templates using the _index_template API
205
+ config :legacy_template, :validate => :boolean, :default => true
206
+
207
+ # The OpenSearch server major version to use when it's not available from the Healthcheck endpoint.
208
+ config :default_server_major_version, :validate => :number
202
209
 
203
210
  attr_reader :client
204
211
  attr_reader :default_index
@@ -11,7 +11,7 @@ signing_key_path = "gem-private_key.pem"
11
11
 
12
12
  Gem::Specification.new do |s|
13
13
  s.name = 'logstash-output-opensearch'
14
- s.version = '1.3.0'
14
+ s.version = '2.0.2'
15
15
 
16
16
  s.licenses = ['Apache-2.0']
17
17
  s.summary = "Stores logs in OpenSearch"
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
45
45
  s.add_runtime_dependency 'stud', ['>= 0.0.17', '~> 0.0']
46
46
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
47
47
  s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~>1.0'
48
- s.add_runtime_dependency 'aws-sdk', '>= 2.11.632', '~> 2'
48
+ s.add_runtime_dependency 'aws-sdk', '~> 3'
49
49
  s.add_runtime_dependency 'json', '>= 2.3.0', '~> 2'
50
50
 
51
51
  s.add_development_dependency 'logstash-codec-plain'
@@ -61,31 +61,89 @@ describe LogStash::Outputs::OpenSearch::HttpClient::ManticoreAdapter do
61
61
  "aws_access_key_id"=>"AAAAAAAAAAAAAAAAAAAA",
62
62
  "aws_secret_access_key"=>"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}
63
63
  } }
64
+ let(:options_svc) { {
65
+ :auth_type => {
66
+ "type"=>"aws_iam",
67
+ "aws_access_key_id"=>"AAAAAAAAAAAAAAAAAAAA",
68
+ "aws_secret_access_key"=>"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
69
+ "service_name"=>"svc_test"}
70
+ } }
64
71
  subject { described_class.new(logger, options) }
65
72
  let(:uri) { ::LogStash::Util::SafeURI.new("http://localhost:9200") }
66
- let(:sign_aws_request) { }
67
73
 
68
- it "should validate AWS IAM credentials initialization" do
69
- expect(subject.aws_iam_auth_initialization(options)).not_to be_nil
70
- end
74
+ let(:expected_uri) {
75
+ expected_uri = uri.clone
76
+ expected_uri.path = "/"
77
+ expected_uri
78
+ }
71
79
 
72
- it "should validate signing aws request" do
80
+ let(:resp) {
73
81
  resp = double("response")
74
82
  allow(resp).to receive(:call)
75
83
  allow(resp).to receive(:code).and_return(200)
76
- allow(subject).to receive(:sign_aws_request).with(any_args).and_return(sign_aws_request)
84
+ resp
85
+ }
77
86
 
78
- expected_uri = uri.clone
79
- expected_uri.path = "/"
87
+ context 'with a signer' do
88
+ let(:sign_aws_request) { }
80
89
 
81
- expect(subject.manticore).to receive(:get).
82
- with(expected_uri.to_s, {
83
- :headers => {"content-type"=> "application/json"}
84
- }
90
+ it "should validate AWS IAM credentials initialization" do
91
+ expect(subject.aws_iam_auth_initialization(options)).not_to be_nil
92
+ expect(subject.get_service_name).to eq("es")
93
+ end
94
+
95
+ it "should validate AWS IAM service_name config" do
96
+ expect(subject.aws_iam_auth_initialization(options_svc)).not_to be_nil
97
+ expect(subject.get_service_name).to eq("svc_test")
98
+ end
99
+
100
+ it "should validate signing aws request" do
101
+ allow(subject).to receive(:sign_aws_request).with(any_args).and_return(sign_aws_request)
102
+
103
+ expect(subject.manticore).to receive(:get).
104
+ with(expected_uri.to_s, {
105
+ :headers => {"content-type"=> "application/json"}
106
+ }
107
+ ).and_return resp
108
+
109
+ expect(subject).to receive(:sign_aws_request)
110
+ subject.perform_request(uri, :get, "/")
111
+ end
112
+ end
113
+
114
+ context 'sign_aws_request' do
115
+ it 'handles UTF-8' do
116
+ encoded_body = body = "boîte de réception"
117
+ expect_any_instance_of(Aws::Sigv4::Signer).to receive(:sign_request).with(hash_including({
118
+ body: body,
119
+ })).and_return(
120
+ double(headers: {})
121
+ )
122
+ expect(subject.manticore).to receive(:post).
123
+ with(expected_uri.to_s, {
124
+ :body => encoded_body,
125
+ :headers => {"content-type"=> "application/json"}
126
+ }
85
127
  ).and_return resp
128
+ subject.perform_request(uri, :post, "/", { body: encoded_body })
129
+ end
86
130
 
87
- expect(subject).to receive(:sign_aws_request)
88
- subject.perform_request(uri, :get, "/")
131
+ it 'encodes body before signing to match manticore adapter encoding' do
132
+ body = "boîte de réception"
133
+ encoded_body = body.encode("ISO-8859-1")
134
+ expect_any_instance_of(Aws::Sigv4::Signer).to receive(:sign_request).with(hash_including({
135
+ body: body,
136
+ })).and_return(
137
+ double(headers: {})
138
+ )
139
+ expect(subject.manticore).to receive(:post).
140
+ with(expected_uri.to_s, {
141
+ :body => encoded_body,
142
+ :headers => {"content-type"=> "application/json"}
143
+ }
144
+ ).and_return resp
145
+ subject.perform_request(uri, :post, "/", { body: encoded_body })
146
+ end
89
147
  end
90
148
  end
91
149
 
@@ -162,6 +162,26 @@ describe LogStash::Outputs::OpenSearch::HttpClient do
162
162
  end
163
163
  end
164
164
 
165
+ describe "legacy_template" do
166
+ let(:template_name) { "logstash" }
167
+ let(:template) { {} }
168
+ let(:get_response) {
169
+ double("response", :body => {}, :code => 404)
170
+ }
171
+ [true, false].each do |legacy_template|
172
+ context "when legacy_template => #{legacy_template}" do
173
+ let(:base_options) { super().merge(:client_settings => {:legacy_template => legacy_template}) }
174
+ subject { described_class.new(base_options) }
175
+ endpoint = legacy_template ? "_template" : "_index_template"
176
+ it "should call template_endpoint #{endpoint}" do
177
+ expect(subject.pool).to receive(:head).with("/#{endpoint}/#{template_name}").and_return(get_response)
178
+ expect(subject.pool).to receive(:put).with("/#{endpoint}/#{template_name}", nil, anything).and_return(get_response)
179
+ subject.template_install(template_name, template)
180
+ end
181
+ end
182
+ end
183
+ end
184
+
165
185
  describe "join_bulk_responses" do
166
186
  subject { described_class.new(base_options) }
167
187
 
@@ -13,27 +13,15 @@ require "logstash/outputs/opensearch/template_manager"
13
13
  describe LogStash::Outputs::OpenSearch::TemplateManager do
14
14
 
15
15
  describe ".default_template_path" do
16
- [1, 2].each do |major_version|
17
- context "when ECS is disabled with OpenSearch #{major_version}.x" do
18
- it 'resolves' do
19
- expect(described_class.default_template_path(major_version)).to end_with("/templates/ecs-disabled/#{major_version}x.json")
20
- end
21
- it 'resolves' do
22
- expect(described_class.default_template_path(major_version, :disabled)).to end_with("/templates/ecs-disabled/#{major_version}x.json")
23
- end
24
- end
25
- end
26
16
  [7, 1, 2].each do |major_version|
27
- context "when ECS v1 is requested with OpenSearch #{major_version}.x" do
28
- it 'resolves' do
29
- expect(described_class.default_template_path(major_version, :v1)).to end_with("/templates/ecs-v1/#{major_version}x.json")
30
- end
31
- end
32
- end
33
- [1, 2].each do |major_version|
34
- context "when ECS v8 is requested with OpenSearch #{major_version}.x" do
35
- it 'resolves' do
36
- expect(described_class.default_template_path(major_version, :v8)).to end_with("/templates/ecs-v8/#{major_version}x.json")
17
+ [:disabled, :v1, :v8].each do |ecs_ver|
18
+ [true, false].each do |legacy_template|
19
+ context "when ECS is #{ecs_ver} with OpenSearch #{major_version}.x legacy_template:#{legacy_template}" do
20
+ suffix = legacy_template ? "" : "_index"
21
+ it 'resolves' do
22
+ expect(described_class.default_template_path(major_version, ecs_ver, legacy_template)).to end_with("/templates/ecs-#{ecs_ver}/#{major_version}x#{suffix}.json")
23
+ end
24
+ end
37
25
  end
38
26
  end
39
27
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-opensearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.2
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
@@ -11,9 +11,9 @@ bindir: bin
11
11
  cert_chain:
12
12
  - |
13
13
  -----BEGIN CERTIFICATE-----
14
- MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRMwEQYDVQQDDApvcGVu
14
+ MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQsFADBCMRMwEQYDVQQDDApvcGVu
15
15
  c2VhcmNoMRYwFAYKCZImiZPyLGQBGRYGYW1hem9uMRMwEQYKCZImiZPyLGQBGRYD
16
- Y29tMB4XDTIyMDgxNzE3NTIzNFoXDTIzMDgxNzE3NTIzNFowQjETMBEGA1UEAwwK
16
+ Y29tMB4XDTIzMDgyNDIwNDIwNFoXDTI0MDgyMzIwNDIwNFowQjETMBEGA1UEAwwK
17
17
  b3BlbnNlYXJjaDEWMBQGCgmSJomT8ixkARkWBmFtYXpvbjETMBEGCgmSJomT8ixk
18
18
  ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM1z3/jcitjV
19
19
  umXwRFn+JSBBd36qZB54Dtucf6+E2fmNPzBRhgYN5XJy/+clQJ9NIJV7C8H52P3V
@@ -24,14 +24,14 @@ cert_chain:
24
24
  zfR37/NQFkECAwEAAaN9MHswCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
25
25
  BBYEFJJ2myhLXK742btavNbG0IWrMNBIMCAGA1UdEQQZMBeBFW9wZW5zZWFyY2hA
26
26
  YW1hem9uLmNvbTAgBgNVHRIEGTAXgRVvcGVuc2VhcmNoQGFtYXpvbi5jb20wDQYJ
27
- KoZIhvcNAQEFBQADggEBAH5pWLYwKWFh1OjdCReGz/VEAiF4jXXputoN5Z8ga+1Z
28
- lg8/diJf0PlP2B46PdmxH/TVc/o+qglNO2cHVEp8xZfEd83dfioOBeK90URQUpC5
29
- UZmO0LZusg46SQKwKa2ukpIy2fNi3PeHRiV+W2Zv69GoWppyLun+fMez7wVoah2r
30
- r5ROUYuAvFUvga1Vm+49pKiPM5n+MAYP5t/vWhgymY3SYQ1TfewkvKAFiFXikOR+
31
- r+j7FLyKuk5DzIxiCp8QN5dU71BbGUmsHf/C5UV76WLPOFX/szeaHhPwpjR3sK7r
32
- 5zLgCV1KP7cgDdCYMlmZGeSViU8NV+Yy8/ghrzGpqVw=
27
+ KoZIhvcNAQELBQADggEBABAQpnELuY5AgdNUIlIVRVATO6iZOXTbt3a9oVbQdLPe
28
+ BfMObZyJydg0+leyR3oFyN9ZIFiEFwpd0biFf39DuC0M6Oge0Rv4oO9GRI3yyv77
29
+ 9m59he+5DI3hbqtGje108oqRe61NZMlKcy/DCBVkzzZFsJ17GC09tY/gwhmNRtLV
30
+ 3vYIEY6vmn57wrGn1NUzWdG+x/XVjYPw5Kwo+/rCxxZqpVTklMqVWV43N/lFrUOe
31
+ 1DlemA1SsUBIoF7CwtVd/RTG/K1iT6nBD08fdKxodMhI5ujkP3N7gkxzRf6aKN4z
32
+ glnDJYZjluKBUsKTOLdPW1CZpb0AHLpNqDf8SVHsPFk=
33
33
  -----END CERTIFICATE-----
34
- date: 2022-08-17 00:00:00.000000000 Z
34
+ date: 2023-08-25 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -110,23 +110,17 @@ dependencies:
110
110
  - !ruby/object:Gem::Dependency
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- version: 2.11.632
116
113
  - - "~>"
117
114
  - !ruby/object:Gem::Version
118
- version: '2'
115
+ version: '3'
119
116
  name: aws-sdk
120
117
  prerelease: false
121
118
  type: :runtime
122
119
  version_requirements: !ruby/object:Gem::Requirement
123
120
  requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- version: 2.11.632
127
121
  - - "~>"
128
122
  - !ruby/object:Gem::Version
129
- version: '2'
123
+ version: '3'
130
124
  - !ruby/object:Gem::Dependency
131
125
  requirement: !ruby/object:Gem::Requirement
132
126
  requirements:
@@ -237,6 +231,7 @@ files:
237
231
  - README.md
238
232
  - RELEASING.md
239
233
  - SECURITY.md
234
+ - docs/ecs_compatibility.md
240
235
  - lib/logstash/outputs/opensearch.rb
241
236
  - lib/logstash/outputs/opensearch/http_client.rb
242
237
  - lib/logstash/outputs/opensearch/http_client/manticore_adapter.rb
@@ -244,11 +239,17 @@ files:
244
239
  - lib/logstash/outputs/opensearch/http_client_builder.rb
245
240
  - lib/logstash/outputs/opensearch/template_manager.rb
246
241
  - lib/logstash/outputs/opensearch/templates/ecs-disabled/1x.json
242
+ - lib/logstash/outputs/opensearch/templates/ecs-disabled/1x_index.json
247
243
  - lib/logstash/outputs/opensearch/templates/ecs-disabled/2x.json
244
+ - lib/logstash/outputs/opensearch/templates/ecs-disabled/2x_index.json
248
245
  - lib/logstash/outputs/opensearch/templates/ecs-disabled/7x.json
246
+ - lib/logstash/outputs/opensearch/templates/ecs-disabled/7x_index.json
249
247
  - lib/logstash/outputs/opensearch/templates/ecs-v8/1x.json
248
+ - lib/logstash/outputs/opensearch/templates/ecs-v8/1x_index.json
250
249
  - lib/logstash/outputs/opensearch/templates/ecs-v8/2x.json
250
+ - lib/logstash/outputs/opensearch/templates/ecs-v8/2x_index.json
251
251
  - lib/logstash/outputs/opensearch/templates/ecs-v8/7x.json
252
+ - lib/logstash/outputs/opensearch/templates/ecs-v8/7x_index.json
252
253
  - lib/logstash/plugin_mixins/opensearch/api_configs.rb
253
254
  - lib/logstash/plugin_mixins/opensearch/common.rb
254
255
  - logstash-output-opensearch.gemspec
@@ -306,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
307
  - !ruby/object:Gem::Version
307
308
  version: '0'
308
309
  requirements: []
309
- rubygems_version: 3.3.20
310
+ rubygems_version: 3.3.26
310
311
  signing_key:
311
312
  specification_version: 4
312
313
  summary: Stores logs in OpenSearch
metadata.gz.sig CHANGED
Binary file