logstash-filter-elasticsearch 4.0.0 → 4.1.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ca5815c2b1127152e31b4ca9e0192021bfb0b0d9d2807ca090c2123feea2bb8
|
4
|
+
data.tar.gz: b3983e01f4e73076e48f3d793f2061cb3210490b09394352146b65377f946137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65822b043de7055e2422810c4b03662c45fb15d58f45edadd677a220287d37a8f8c7d1382e3b1dc04e00ac51e261a1e5f7e11c06b4d57481218be9da2f498534
|
7
|
+
data.tar.gz: 8738742640bf8729297f556154d6ef11878e99b55bfe1193da459f2f83cf255d5e5973537bc6e97e5d32021d1976f6aa4c284081a98f5b7a84c1073dfa039cc2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 4.1.1
|
2
|
+
- Add elastic-transport client support used in elasticsearch-ruby 8.x [#191](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/191)
|
3
|
+
|
4
|
+
## 4.1.0
|
5
|
+
- Added support for custom headers [#188](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/188)
|
6
|
+
|
1
7
|
## 4.0.0
|
2
8
|
- SSL settings that were marked deprecated in version `3.15.0` are now marked obsolete, and will prevent the plugin from starting.
|
3
9
|
- These settings are:
|
data/docs/index.asciidoc
CHANGED
@@ -134,6 +134,7 @@ NOTE: As of version `4.0.0` of this plugin, a number of previously deprecated se
|
|
134
134
|
| <<plugins-{type}s-{plugin}-ca_trusted_fingerprint>> |<<string,string>>|No
|
135
135
|
| <<plugins-{type}s-{plugin}-cloud_auth>> |<<password,password>>|No
|
136
136
|
| <<plugins-{type}s-{plugin}-cloud_id>> |<<string,string>>|No
|
137
|
+
| <<plugins-{type}s-{plugin}-custom_headers>> |<<hash,hash>>|No
|
137
138
|
| <<plugins-{type}s-{plugin}-docinfo_fields>> |<<hash,hash>>|No
|
138
139
|
| <<plugins-{type}s-{plugin}-enable_sort>> |<<boolean,boolean>>|No
|
139
140
|
| <<plugins-{type}s-{plugin}-fields>> |<<array,array>>|No
|
@@ -230,6 +231,16 @@ Cloud ID, from the Elastic Cloud web console. If set `hosts` should not be used.
|
|
230
231
|
For more info, check out the
|
231
232
|
{logstash-ref}/connecting-to-cloud.html[Logstash-to-Cloud documentation].
|
232
233
|
|
234
|
+
|
235
|
+
[id="plugins-{type}s-{plugin}-custom_headers"]
|
236
|
+
===== `custom_headers`
|
237
|
+
|
238
|
+
* Value type is <<hash,hash>>
|
239
|
+
* Default value is empty
|
240
|
+
|
241
|
+
Pass a set of key value pairs as the headers sent in each request to Elasticsearch.
|
242
|
+
These custom headers will override any headers previously set by the plugin such as the User Agent or Authorization headers.
|
243
|
+
|
233
244
|
[id="plugins-{type}s-{plugin}-docinfo_fields"]
|
234
245
|
===== `docinfo_fields`
|
235
246
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "elasticsearch"
|
3
3
|
require "base64"
|
4
|
-
require "elasticsearch/transport/transport/http/manticore"
|
5
4
|
|
6
5
|
|
7
6
|
module LogStash
|
@@ -9,6 +8,7 @@ module LogStash
|
|
9
8
|
class ElasticsearchClient
|
10
9
|
|
11
10
|
attr_reader :client
|
11
|
+
attr_reader :es_transport_client_type
|
12
12
|
|
13
13
|
BUILD_FLAVOR_SERVERLESS = 'serverless'.freeze
|
14
14
|
DEFAULT_EAV_HEADER = { "Elastic-Api-Version" => "2023-10-31" }.freeze
|
@@ -20,6 +20,8 @@ module LogStash
|
|
20
20
|
api_key = options.fetch(:api_key, nil)
|
21
21
|
proxy = options.fetch(:proxy, nil)
|
22
22
|
user_agent = options[:user_agent]
|
23
|
+
custom_headers = options[:custom_headers]
|
24
|
+
|
23
25
|
|
24
26
|
transport_options = { }
|
25
27
|
transport_options[:headers] = options.fetch(:serverless, false) ? DEFAULT_EAV_HEADER.dup : {}
|
@@ -27,6 +29,7 @@ module LogStash
|
|
27
29
|
transport_options[:headers].merge!(setup_api_key(api_key))
|
28
30
|
transport_options[:headers].merge!({ 'user-agent' => "#{user_agent}" })
|
29
31
|
transport_options[:headers].merge!(INTERNAL_ORIGIN_HEADER)
|
32
|
+
transport_options[:headers].merge!(custom_headers) unless custom_headers.empty?
|
30
33
|
|
31
34
|
transport_options[:pool_max] = 1000
|
32
35
|
transport_options[:pool_max_per_route] = 100
|
@@ -41,7 +44,7 @@ module LogStash
|
|
41
44
|
|
42
45
|
client_options = {
|
43
46
|
hosts: hosts,
|
44
|
-
transport_class:
|
47
|
+
transport_class: get_transport_client_class,
|
45
48
|
transport_options: transport_options,
|
46
49
|
ssl: ssl_options,
|
47
50
|
retry_on_failure: options[:retry_on_failure],
|
@@ -95,6 +98,20 @@ module LogStash
|
|
95
98
|
token = ::Base64.strict_encode64(api_key.value)
|
96
99
|
{ 'Authorization' => "ApiKey #{token}" }
|
97
100
|
end
|
101
|
+
|
102
|
+
def get_transport_client_class
|
103
|
+
# LS-core includes `elasticsearch` gem. The gem is composed of two separate gems: `elasticsearch-api` and `elasticsearch-transport`
|
104
|
+
# And now `elasticsearch-transport` is old, instead we have `elastic-transport`.
|
105
|
+
# LS-core updated `elasticsearch` > 8: https://github.com/elastic/logstash/pull/17161
|
106
|
+
# Following source bits are for the compatibility to support both `elasticsearch-transport` and `elastic-transport` gems
|
107
|
+
require "elasticsearch/transport/transport/http/manticore"
|
108
|
+
es_transport_client_type = "elasticsearch_transport"
|
109
|
+
::Elasticsearch::Transport::Transport::HTTP::Manticore
|
110
|
+
rescue ::LoadError
|
111
|
+
require "elastic/transport/transport/http/manticore"
|
112
|
+
es_transport_client_type = "elastic_transport"
|
113
|
+
::Elastic::Transport::Transport::HTTP::Manticore
|
114
|
+
end
|
98
115
|
end
|
99
116
|
end
|
100
117
|
end
|
@@ -6,7 +6,6 @@ require 'logstash/plugin_mixins/ca_trusted_fingerprint_support'
|
|
6
6
|
require "monitor"
|
7
7
|
|
8
8
|
require_relative "elasticsearch/client"
|
9
|
-
require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
|
10
9
|
|
11
10
|
class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
12
11
|
config_name "elasticsearch"
|
@@ -32,6 +31,9 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
32
31
|
# Array of fields to copy from old event (found via elasticsearch) into new event
|
33
32
|
config :fields, :validate => :array, :default => {}
|
34
33
|
|
34
|
+
# Custom headers for Elasticsearch requests
|
35
|
+
config :custom_headers, :validate => :hash, :default => {}
|
36
|
+
|
35
37
|
# Hash of docinfo fields to copy from old event (found via elasticsearch) into new event
|
36
38
|
config :docinfo_fields, :validate => :hash, :default => {}
|
37
39
|
|
@@ -171,6 +173,9 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
171
173
|
|
172
174
|
test_connection!
|
173
175
|
setup_serverless
|
176
|
+
if get_client.es_transport_client_type == "elasticsearch_transport"
|
177
|
+
require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
|
178
|
+
end
|
174
179
|
end # def register
|
175
180
|
|
176
181
|
def filter(event)
|
@@ -260,7 +265,8 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
260
265
|
:ssl => client_ssl_options,
|
261
266
|
:retry_on_failure => @retry_on_failure,
|
262
267
|
:retry_on_status => @retry_on_status,
|
263
|
-
:user_agent => prepare_user_agent
|
268
|
+
:user_agent => prepare_user_agent,
|
269
|
+
:custom_headers => @custom_headers
|
264
270
|
}
|
265
271
|
end
|
266
272
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-elasticsearch'
|
4
|
-
s.version = '4.
|
4
|
+
s.version = '4.1.1'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Copies fields from previous log events in Elasticsearch to current events "
|
7
7
|
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"
|
8
8
|
s.authors = ["Elastic"]
|
9
9
|
s.email = 'info@elastic.co'
|
10
|
-
s.homepage = "
|
10
|
+
s.homepage = "https://elastic.co/logstash"
|
11
11
|
s.require_paths = ["lib"]
|
12
12
|
|
13
13
|
# Files
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
# Gem dependencies
|
23
23
|
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
24
|
-
s.add_runtime_dependency 'elasticsearch', ">= 7.14.9"
|
24
|
+
s.add_runtime_dependency 'elasticsearch', ">= 7.14.9", '< 9'
|
25
25
|
s.add_runtime_dependency 'manticore', ">= 0.7.1"
|
26
26
|
s.add_runtime_dependency 'logstash-mixin-ca_trusted_fingerprint_support', '~> 1.0'
|
27
27
|
s.add_development_dependency 'cabin', ['~> 0.6']
|
@@ -60,9 +60,18 @@ describe LogStash::Filters::Elasticsearch do
|
|
60
60
|
allow(plugin).to receive(:get_client).and_return(filter_client)
|
61
61
|
allow(filter_client).to receive(:serverless?).and_return(true)
|
62
62
|
allow(filter_client).to receive(:client).and_return(es_client)
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
|
64
|
+
if elastic_ruby_v8_client_available?
|
65
|
+
allow(es_client).to receive(:info)
|
66
|
+
.with(a_hash_including(
|
67
|
+
:headers => LogStash::Filters::ElasticsearchClient::DEFAULT_EAV_HEADER))
|
68
|
+
.and_raise(Elastic::Transport::Transport::Errors::BadRequest.new)
|
69
|
+
else
|
70
|
+
allow(es_client).to receive(:info)
|
71
|
+
.with(a_hash_including(
|
72
|
+
:headers => LogStash::Filters::ElasticsearchClient::DEFAULT_EAV_HEADER))
|
73
|
+
.and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest.new)
|
74
|
+
end
|
66
75
|
end
|
67
76
|
|
68
77
|
it "raises an exception when Elastic Api Version is not supported" do
|
@@ -103,6 +112,11 @@ describe LogStash::Filters::Elasticsearch do
|
|
103
112
|
|
104
113
|
before(:each) do
|
105
114
|
allow(LogStash::Filters::ElasticsearchClient).to receive(:new).and_return(client)
|
115
|
+
if elastic_ruby_v8_client_available?
|
116
|
+
allow(client).to receive(:es_transport_client_type).and_return('elastic_transport')
|
117
|
+
else
|
118
|
+
allow(client).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
|
119
|
+
end
|
106
120
|
allow(client).to receive(:search).and_return(response)
|
107
121
|
allow(plugin).to receive(:test_connection!)
|
108
122
|
allow(plugin).to receive(:setup_serverless)
|
@@ -333,6 +347,35 @@ describe LogStash::Filters::Elasticsearch do
|
|
333
347
|
end
|
334
348
|
end
|
335
349
|
|
350
|
+
context "with custom headers" do
|
351
|
+
let(:config) do
|
352
|
+
{
|
353
|
+
"query" => "*",
|
354
|
+
"custom_headers" => { "Custom-Header-1" => "Custom Value 1", "Custom-Header-2" => "Custom Value 2" }
|
355
|
+
}
|
356
|
+
end
|
357
|
+
|
358
|
+
let(:plugin) { LogStash::Filters::Elasticsearch.new(config) }
|
359
|
+
let(:client_double) { double("client") }
|
360
|
+
let(:transport_double) { double("transport", options: { transport_options: { headers: config["custom_headers"] } }) }
|
361
|
+
|
362
|
+
before do
|
363
|
+
allow(plugin).to receive(:get_client).and_return(client_double)
|
364
|
+
if elastic_ruby_v8_client_available?
|
365
|
+
allow(client_double).to receive(:es_transport_client_type).and_return('elastic_transport')
|
366
|
+
else
|
367
|
+
allow(client_double).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
|
368
|
+
end
|
369
|
+
allow(client_double).to receive(:client).and_return(transport_double)
|
370
|
+
end
|
371
|
+
|
372
|
+
it "sets custom headers" do
|
373
|
+
plugin.register
|
374
|
+
client = plugin.send(:get_client).client
|
375
|
+
expect(client.options[:transport_options][:headers]).to match(hash_including(config["custom_headers"]))
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
336
379
|
context "if query is on nested field" do
|
337
380
|
let(:config) do
|
338
381
|
{
|
@@ -482,7 +525,12 @@ describe LogStash::Filters::Elasticsearch do
|
|
482
525
|
# this spec is a safeguard to trigger an assessment of thread-safety should
|
483
526
|
# we choose a different transport adapter in the future.
|
484
527
|
transport_class = extract_transport(client).options.fetch(:transport_class)
|
485
|
-
|
528
|
+
if elastic_ruby_v8_client_available?
|
529
|
+
allow(client).to receive(:es_transport_client_type).and_return("elastic_transport")
|
530
|
+
expect(transport_class).to equal ::Elastic::Transport::Transport::HTTP::Manticore
|
531
|
+
else
|
532
|
+
expect(transport_class).to equal ::Elasticsearch::Transport::Transport::HTTP::Manticore
|
533
|
+
end
|
486
534
|
end
|
487
535
|
|
488
536
|
it 'uses a client with sufficient connection pool size' do
|
@@ -797,6 +845,11 @@ describe LogStash::Filters::Elasticsearch do
|
|
797
845
|
|
798
846
|
before(:each) do
|
799
847
|
allow(LogStash::Filters::ElasticsearchClient).to receive(:new).and_return(client)
|
848
|
+
if elastic_ruby_v8_client_available?
|
849
|
+
allow(client).to receive(:es_transport_client_type).and_return('elastic_transport')
|
850
|
+
else
|
851
|
+
allow(client).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
|
852
|
+
end
|
800
853
|
allow(plugin).to receive(:test_connection!)
|
801
854
|
allow(plugin).to receive(:setup_serverless)
|
802
855
|
plugin.register
|
@@ -811,11 +864,19 @@ describe LogStash::Filters::Elasticsearch do
|
|
811
864
|
end
|
812
865
|
end
|
813
866
|
|
814
|
-
|
815
|
-
|
867
|
+
def extract_transport(client)
|
868
|
+
# on 7x: client.transport.transport
|
869
|
+
# on >=8.x: client.transport
|
816
870
|
client.transport.respond_to?(:transport) ? client.transport.transport : client.transport
|
817
871
|
end
|
818
872
|
|
873
|
+
def elastic_ruby_v8_client_available?
|
874
|
+
Elasticsearch::Transport
|
875
|
+
false
|
876
|
+
rescue NameError # NameError: uninitialized constant Elasticsearch::Transport if Elastic Ruby client is not available
|
877
|
+
true
|
878
|
+
end
|
879
|
+
|
819
880
|
class MockResponse
|
820
881
|
attr_reader :code, :headers
|
821
882
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -36,6 +36,9 @@ dependencies:
|
|
36
36
|
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: 7.14.9
|
39
|
+
- - "<"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '9'
|
39
42
|
name: elasticsearch
|
40
43
|
type: :runtime
|
41
44
|
prerelease: false
|
@@ -44,6 +47,9 @@ dependencies:
|
|
44
47
|
- - ">="
|
45
48
|
- !ruby/object:Gem::Version
|
46
49
|
version: 7.14.9
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '9'
|
47
53
|
- !ruby/object:Gem::Dependency
|
48
54
|
requirement: !ruby/object:Gem::Requirement
|
49
55
|
requirements:
|
@@ -160,7 +166,7 @@ files:
|
|
160
166
|
- spec/filters/fixtures/test_certs/ls.der.sha256
|
161
167
|
- spec/filters/fixtures/test_certs/ls.key
|
162
168
|
- spec/filters/integration/elasticsearch_spec.rb
|
163
|
-
homepage:
|
169
|
+
homepage: https://elastic.co/logstash
|
164
170
|
licenses:
|
165
171
|
- Apache License (2.0)
|
166
172
|
metadata:
|