logstash-output-elasticsearch 11.0.5-java → 11.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e275e2ca3a658814c730aaaa7464f81826dba01d8f2fb305859dc9aa33f0f34
4
- data.tar.gz: f3dd23896923260bb9939e4ef90e56cf44c0daa0571b0987be3e39c45b9749c4
3
+ metadata.gz: a8d5dde6f4643a1482c56af7db786848d73759cac4728203ade488a8eec3ca76
4
+ data.tar.gz: 8c8e8b7b05589c7d86d92d3fc50c2d267c5650456c84806326c5bef488bfb819
5
5
  SHA512:
6
- metadata.gz: 315cc2c6a4097f3923f76899c3bd5d58bb1ff779bc6aaaef4798cdf2db6a2d368ca0a8627e15e36e39b80484ad5bfea96ff7a9d77235c266627c9d4ef76f49c8
7
- data.tar.gz: ae0591ff34ed9c88afd9b897c490e1787a28b68f44ff98816cd3ef5784cca71fd7d670c7aeee6b634ca01f837aaa2839198ec0fa8ed70454d2c0916e09e0293f
6
+ metadata.gz: aad121ec87c87db04fc35ce0bf28069eee3960b0bdca76c8297d5b1242e9e83a68b118b5f97e41ec34660073ba1f61f839e786ee2db306a56f5b2ad6c0e5dc06
7
+ data.tar.gz: 5201e002ae94e3acc00e44e79da5cd721fc80d39781e876c0d009d7c53f5ab90978a6126a691c5c07b159a30bc3e2bc38ef58801d0443094bcd3b810acbd7e98
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 11.1.0
2
+ - Feat: add `user-agent` header passed to the Elasticsearch HTTP connection [#1038](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1038)
3
+
1
4
  ## 11.0.5
2
5
  - Fixed running post-register action when Elasticsearch status change from unhealthy to healthy [#1035](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1035)
3
6
 
@@ -4,6 +4,7 @@ require 'logstash/outputs/elasticsearch/http_client/manticore_adapter'
4
4
  require 'cgi'
5
5
  require 'zlib'
6
6
  require 'stringio'
7
+ require 'java'
7
8
 
8
9
  module LogStash; module Outputs; class ElasticSearch;
9
10
  # This is a constant instead of a config option because
@@ -301,6 +302,8 @@ module LogStash; module Outputs; class ElasticSearch;
301
302
  :request_timeout => timeout,
302
303
  }
303
304
 
305
+ adapter_options[:user_agent] = prepare_user_agent
306
+
304
307
  adapter_options[:proxy] = client_settings[:proxy] if client_settings[:proxy]
305
308
 
306
309
  adapter_options[:check_connection_timeout] = client_settings[:check_connection_timeout] if client_settings[:check_connection_timeout]
@@ -322,6 +325,18 @@ module LogStash; module Outputs; class ElasticSearch;
322
325
  adapter_class = ::LogStash::Outputs::ElasticSearch::HttpClient::ManticoreAdapter
323
326
  adapter = adapter_class.new(@logger, adapter_options)
324
327
  end
328
+
329
+ def prepare_user_agent
330
+ os_name = java.lang.System.getProperty('os.name')
331
+ os_version = java.lang.System.getProperty('os.version')
332
+ os_arch = java.lang.System.getProperty('os.arch')
333
+ jvm_vendor = java.lang.System.getProperty('java.vendor')
334
+ jvm_version = java.lang.System.getProperty('java.version')
335
+
336
+ plugin_version = Gem.loaded_specs['logstash-output-elasticsearch'].version
337
+ # example: Logstash/7.14.1 (OS=Linux-5.4.0-84-generic-amd64; JVM=AdoptOpenJDK-11.0.11) logstash-output-elasticsearch/11.0.1
338
+ "Logstash/#{LOGSTASH_VERSION} (OS=#{os_name}-#{os_version}-#{os_arch}; JVM=#{jvm_vendor}-#{jvm_version}) logstash-output-elasticsearch/#{plugin_version}"
339
+ end
325
340
 
326
341
  def build_pool(options)
327
342
  adapter = build_adapter(options)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-elasticsearch'
3
- s.version = '11.0.5'
3
+ s.version = '11.1.0'
4
4
 
5
5
  s.licenses = ['apache-2.0']
6
6
  s.summary = "Stores logs in Elasticsearch"
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency 'logstash-devutils'
31
31
  s.add_development_dependency 'flores'
32
32
  s.add_development_dependency 'cabin', ['~> 0.6']
33
+ s.add_development_dependency 'webrick'
33
34
  # Still used in some specs, we should remove this ASAP
34
35
  s.add_development_dependency 'elasticsearch'
35
36
  end
@@ -80,7 +80,7 @@ module ESHelper
80
80
  end
81
81
 
82
82
  def self.es_version_satisfies?(*requirement)
83
- es_version = RSpec.configuration.filter[:es_version] || ENV['ES_VERSION'] || ENV['ELASTIC_STACK_VERSION']
83
+ es_version = nilify(RSpec.configuration.filter[:es_version]) || nilify(ENV['ES_VERSION']) || nilify(ENV['ELASTIC_STACK_VERSION'])
84
84
  if es_version.nil?
85
85
  puts "Info: ES_VERSION, ELASTIC_STACK_VERSION or 'es_version' tag wasn't set. Returning false to all `es_version_satisfies?` call."
86
86
  return false
@@ -89,6 +89,15 @@ module ESHelper
89
89
  Gem::Requirement.new(requirement).satisfied_by?(es_release_version)
90
90
  end
91
91
 
92
+ private
93
+ def self.nilify(str)
94
+ if str.nil?
95
+ return str
96
+ end
97
+ str.empty? ? nil : str
98
+ end
99
+
100
+ public
92
101
  def clean(client)
93
102
  client.indices.delete_template(:name => "*")
94
103
  client.indices.delete_index_template(:name => "logstash*") rescue nil
@@ -1,6 +1,8 @@
1
1
  require_relative "../../../../spec/spec_helper"
2
2
  require "logstash/outputs/elasticsearch/http_client"
3
3
  require "cabin"
4
+ require "webrick"
5
+ require "java"
4
6
 
5
7
  describe LogStash::Outputs::ElasticSearch::HttpClient do
6
8
  let(:ssl) { nil }
@@ -287,4 +289,71 @@ describe LogStash::Outputs::ElasticSearch::HttpClient do
287
289
  end
288
290
  end
289
291
  end
292
+
293
+ class StoppableServer
294
+
295
+ attr_reader :port
296
+
297
+ def initialize()
298
+ queue = Queue.new
299
+ @first_req_waiter = java.util.concurrent.CountDownLatch.new(1)
300
+ @first_request = nil
301
+
302
+ @t = java.lang.Thread.new(
303
+ proc do
304
+ begin
305
+ @server = WEBrick::HTTPServer.new :Port => 0, :DocumentRoot => ".",
306
+ :Logger => Cabin::Channel.get, # silence WEBrick logging
307
+ :StartCallback => Proc.new {
308
+ queue.push("started")
309
+ }
310
+ @port = @server.config[:Port]
311
+ @server.mount_proc '/headers_check' do |req, res|
312
+ res.body = 'Hello, world from WEBrick mocking server!'
313
+ @first_request = req
314
+ @first_req_waiter.countDown()
315
+ end
316
+
317
+ @server.start
318
+ rescue => e
319
+ puts "Error in webserver thread #{e}"
320
+ # ignore
321
+ end
322
+ end
323
+ )
324
+ @t.daemon = true
325
+ @t.start
326
+ queue.pop # blocks until the server is up
327
+ end
328
+
329
+ def stop
330
+ @server.shutdown
331
+ end
332
+
333
+ def wait_receive_request
334
+ @first_req_waiter.await(2, java.util.concurrent.TimeUnit::SECONDS)
335
+ @first_request
336
+ end
337
+ end
338
+
339
+ describe "#build_adapter" do
340
+ let(:client) { LogStash::Outputs::ElasticSearch::HttpClient.new(base_options) }
341
+ let!(:webserver) { StoppableServer.new } # webserver must be started before the call, so no lazy "let"
342
+
343
+ after :each do
344
+ webserver.stop
345
+ end
346
+
347
+ context "the 'user-agent' header" do
348
+ it "contains the Logstash environment details" do
349
+ adapter = client.build_adapter(client.options)
350
+ adapter.perform_request(::LogStash::Util::SafeURI.new("http://localhost:#{webserver.port}"), :get, "/headers_check")
351
+
352
+ request = webserver.wait_receive_request
353
+
354
+ transmitted_user_agent = request.header['user-agent'][0]
355
+ expect(transmitted_user_agent).to match(/Logstash\/\d*\.\d*\.\d* \(OS=.*; JVM=.*\) logstash-output-elasticsearch\/\d*\.\d*\.\d*/)
356
+ end
357
+ end
358
+ end
290
359
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.0.5
4
+ version: 11.1.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-30 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +140,20 @@ dependencies:
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0.6'
143
+ - !ruby/object:Gem::Dependency
144
+ requirement: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ name: webrick
150
+ prerelease: false
151
+ type: :development
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
143
157
  - !ruby/object:Gem::Dependency
144
158
  requirement: !ruby/object:Gem::Requirement
145
159
  requirements:
@@ -182,9 +196,6 @@ files:
182
196
  - lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-6x.json
183
197
  - lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-7x.json
184
198
  - lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-8x.json
185
- - lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-6x.json
186
- - lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-7x.json
187
- - lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-8x.json
188
199
  - lib/logstash/plugin_mixins/elasticsearch/api_configs.rb
189
200
  - lib/logstash/plugin_mixins/elasticsearch/common.rb
190
201
  - lib/logstash/plugin_mixins/elasticsearch/noop_license_checker.rb