logstash-input-http_poller 5.3.0 → 5.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/logstash/inputs/http_poller.rb +27 -6
- data/logstash-input-http_poller.gemspec +1 -1
- data/spec/inputs/http_poller_spec.rb +22 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 510ac72c358c306a8377a8cd714a1f58c867283b792e68f0374c79737f758126
|
4
|
+
data.tar.gz: 8c375ba083f4d8e6b8b20ced9d2b5c81c7f1322e36c0115dcbedcdc91087d16d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54b5171093fc938cb49e273cad550c6430179812b1c47d34b6fd1c307281612ad872a50aee10f420e39002a46e7a7b143162ae331a90bdc42fc4a534e2666762
|
7
|
+
data.tar.gz: 87bc152a391d0e76942ead58d80679ce5581275f89863e6e629248751713f17052ecef2d5ca7dcd778d776828be7f20e5fd9338ad4c181d0e5d9ec837faea775
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 5.3.1
|
2
|
+
- Fix: make sure plugin is closing the http client [#130](https://github.com/logstash-plugins/logstash-input-http_poller/pull/130)
|
3
|
+
|
1
4
|
## 5.3.0
|
2
5
|
- Feat: added ssl_supported_protocols option [#133](https://github.com/logstash-plugins/logstash-input-http_poller/pull/133)
|
3
6
|
|
@@ -49,19 +49,35 @@ class LogStash::Inputs::HTTP_Poller < LogStash::Inputs::Base
|
|
49
49
|
def register
|
50
50
|
@host = Socket.gethostname.force_encoding(Encoding::UTF_8)
|
51
51
|
|
52
|
-
@logger.info("Registering http_poller Input", :type => @type, :schedule => @schedule, :timeout => @timeout)
|
53
|
-
|
54
52
|
setup_ecs_field!
|
55
53
|
setup_requests!
|
56
54
|
end
|
57
55
|
|
58
56
|
# @overload
|
59
57
|
def stop
|
58
|
+
shutdown_scheduler_and_close_client(:wait)
|
59
|
+
end
|
60
|
+
|
61
|
+
# @overload
|
62
|
+
def close
|
63
|
+
shutdown_scheduler_and_close_client
|
64
|
+
end
|
65
|
+
|
66
|
+
def shutdown_scheduler_and_close_client(opt = nil)
|
67
|
+
@logger.debug("closing http client", client: client)
|
68
|
+
begin
|
69
|
+
client.close # since Manticore 0.9.0 this shuts-down/closes all resources
|
70
|
+
rescue => e
|
71
|
+
details = { exception: e.class, message: e.message }
|
72
|
+
details[:backtrace] = e.backtrace if @logger.debug?
|
73
|
+
@logger.warn "failed closing http client", details
|
74
|
+
end
|
60
75
|
if @scheduler
|
61
|
-
@
|
76
|
+
@logger.debug("shutting down scheduler", scheduler: @scheduler)
|
77
|
+
@scheduler.shutdown(opt) # on newer Rufus (3.8) this joins on the scheduler thread
|
62
78
|
end
|
63
|
-
# TODO implement client.close as we as releasing it's pooled resources!
|
64
79
|
end
|
80
|
+
private :shutdown_scheduler_and_close_client
|
65
81
|
|
66
82
|
private
|
67
83
|
def setup_requests!
|
@@ -179,15 +195,18 @@ class LogStash::Inputs::HTTP_Poller < LogStash::Inputs::Base
|
|
179
195
|
|
180
196
|
def run_once(queue)
|
181
197
|
@requests.each do |name, request|
|
198
|
+
# prevent executing a scheduler kick after the plugin has been stop-ed
|
199
|
+
# this could easily happen as the scheduler shutdown is not immediate
|
200
|
+
return if stop?
|
182
201
|
request_async(queue, name, request)
|
183
202
|
end
|
184
203
|
|
185
|
-
client.execute!
|
204
|
+
client.execute! unless stop?
|
186
205
|
end
|
187
206
|
|
188
207
|
private
|
189
208
|
def request_async(queue, name, request)
|
190
|
-
@logger.debug? && @logger.debug("
|
209
|
+
@logger.debug? && @logger.debug("async queueing fetching url", name: name, url: request)
|
191
210
|
started = Time.now
|
192
211
|
|
193
212
|
method, *request_opts = request
|
@@ -204,6 +223,7 @@ class LogStash::Inputs::HTTP_Poller < LogStash::Inputs::Base
|
|
204
223
|
|
205
224
|
private
|
206
225
|
def handle_success(queue, name, request, response, execution_time)
|
226
|
+
@logger.debug? && @logger.debug("success fetching url", name: name, url: request)
|
207
227
|
body = response.body
|
208
228
|
# If there is a usable response. HEAD requests are `nil` and empty get
|
209
229
|
# responses come up as "" which will cause the codec to not yield anything
|
@@ -242,6 +262,7 @@ class LogStash::Inputs::HTTP_Poller < LogStash::Inputs::Base
|
|
242
262
|
private
|
243
263
|
# Beware, on old versions of manticore some uncommon failures are not handled
|
244
264
|
def handle_failure(queue, name, request, exception, execution_time)
|
265
|
+
@logger.debug? && @logger.debug("failed fetching url", name: name, url: request)
|
245
266
|
event = event_factory.new_event
|
246
267
|
event.tag("_http_request_failure")
|
247
268
|
apply_metadata(event, name, request, nil, execution_time)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-input-http_poller'
|
3
|
-
s.version = '5.3.
|
3
|
+
s.version = '5.3.1'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = "Decodes the output of an HTTP API into events"
|
6
6
|
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"
|
@@ -7,6 +7,15 @@ require "timecop"
|
|
7
7
|
require 'rspec/matchers/built_in/raise_error.rb'
|
8
8
|
require 'logstash/plugin_mixins/ecs_compatibility_support/spec_helper'
|
9
9
|
|
10
|
+
begin
|
11
|
+
# TODO: CI work-around - will most likely be moved to the scheduler mixin
|
12
|
+
require 'et-orbi.rb' # a dependency of rufus-scheduler since 3.4
|
13
|
+
::EtOrbi::EoTime.now # might take a long time to initialize - loading time zone
|
14
|
+
# data (from tz-info) and thus gets un-predictable on CI, since the scheduler worker
|
15
|
+
# thread might be stuck starting while we attempt to shutdown in a given time frame
|
16
|
+
rescue LoadError
|
17
|
+
end
|
18
|
+
|
10
19
|
describe LogStash::Inputs::HTTP_Poller do
|
11
20
|
let(:metadata_target) { "_http_poller_metadata" }
|
12
21
|
let(:queue) { Queue.new }
|
@@ -201,8 +210,8 @@ describe LogStash::Inputs::HTTP_Poller do
|
|
201
210
|
end
|
202
211
|
|
203
212
|
it "should run at the schedule" do
|
204
|
-
run_plugin_and_yield_queue(plugin, sleep: 3) do |queue|
|
205
|
-
try(
|
213
|
+
run_plugin_and_yield_queue(plugin, sleep: 3.1) do |queue|
|
214
|
+
try(10) { expect(queue.size).to be >= 2 }
|
206
215
|
end
|
207
216
|
end
|
208
217
|
end
|
@@ -227,8 +236,8 @@ describe LogStash::Inputs::HTTP_Poller do
|
|
227
236
|
end
|
228
237
|
|
229
238
|
it "should run at the schedule" do
|
230
|
-
run_plugin_and_yield_queue(plugin, sleep:
|
231
|
-
try(
|
239
|
+
run_plugin_and_yield_queue(plugin, sleep: 4.1) do |queue|
|
240
|
+
try(10) { expect(queue.size).to eq(1) }
|
232
241
|
end
|
233
242
|
end
|
234
243
|
end
|
@@ -247,7 +256,7 @@ describe LogStash::Inputs::HTTP_Poller do
|
|
247
256
|
#T 0123456
|
248
257
|
#events x x x x
|
249
258
|
#expects 3 events at T=5
|
250
|
-
try(
|
259
|
+
try(10) { expect(queue.size).to be_between(2, 3) }
|
251
260
|
end
|
252
261
|
end
|
253
262
|
end
|
@@ -255,15 +264,15 @@ describe LogStash::Inputs::HTTP_Poller do
|
|
255
264
|
context "given 'in' expression" do
|
256
265
|
let(:opts) {
|
257
266
|
{
|
258
|
-
"schedule" => { "in" => "
|
267
|
+
"schedule" => { "in" => "1s"},
|
259
268
|
"urls" => default_urls,
|
260
269
|
"codec" => "json",
|
261
270
|
"metadata_target" => metadata_target
|
262
271
|
}
|
263
272
|
}
|
264
273
|
it "should run at the schedule" do
|
265
|
-
run_plugin_and_yield_queue(plugin, sleep: 2.
|
266
|
-
try(
|
274
|
+
run_plugin_and_yield_queue(plugin, sleep: 2.05) do |queue|
|
275
|
+
try(10) { expect(queue.size).to eq(1) }
|
267
276
|
end
|
268
277
|
end
|
269
278
|
end
|
@@ -410,14 +419,15 @@ describe LogStash::Inputs::HTTP_Poller do
|
|
410
419
|
before do
|
411
420
|
plugin.register
|
412
421
|
u = url.is_a?(Hash) ? url["url"] : url # handle both complex specs and simple string URLs
|
413
|
-
plugin.client.stub(u,
|
414
|
-
:body => response_body,
|
415
|
-
:code => code
|
416
|
-
)
|
422
|
+
plugin.client.stub(u, :body => response_body, :code => code)
|
417
423
|
allow(plugin).to receive(:decorate)
|
418
424
|
plugin.send(:run_once, queue)
|
419
425
|
end
|
420
426
|
|
427
|
+
after do
|
428
|
+
plugin.close
|
429
|
+
end
|
430
|
+
|
421
431
|
it "should have a matching message" do
|
422
432
|
expect(event.to_hash).to include(payload)
|
423
433
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-http_poller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.3.
|
4
|
+
version: 5.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-06-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|