fluent-plugin-http-pull 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/fluent-plugin-http-pull.gemspec +1 -1
- data/lib/fluent/plugin/in_http_pull.rb +29 -0
- data/test/helper/stub_server.rb +9 -0
- data/test/plugin/test_in_http_pull.rb +103 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56348b6b227f806a70821eaed3fafddcdc94ee6c
|
4
|
+
data.tar.gz: 34e8e11a24b5b2dac781f4556f0e534b08e403fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b5aeea895ccc1cfaf7923f8c21c9bdb54328677d384e66c508c289b0da9f8a7ab23778eb8097323e18822f493a7f1ad491544750d1230e2597910620d90e129
|
7
|
+
data.tar.gz: b0b8ced808f05bdb9c0804af5dad1c7b171c6f6e096d5eab29d840ad6305ec079276692eea1a45b875629ed26cb82650be4462c7912c8831eb96145b222fb9d5
|
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gemspec
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
@@ -45,11 +45,30 @@ module Fluent
|
|
45
45
|
desc 'password of basic auth'
|
46
46
|
config_param :password, :string, default: nil
|
47
47
|
|
48
|
+
config_section :response_header, param_name: :response_headers, multi: true do
|
49
|
+
desc 'The name of header to cature from response'
|
50
|
+
config_param :header, :string
|
51
|
+
end
|
52
|
+
|
53
|
+
config_section :request_header, param_name: :request_headers, multi: true do
|
54
|
+
desc 'The name of request header'
|
55
|
+
config_param :header, :string
|
56
|
+
|
57
|
+
desc 'The value of request header'
|
58
|
+
config_param :value, :string
|
59
|
+
end
|
60
|
+
|
48
61
|
def configure(conf)
|
49
62
|
compat_parameters_convert(conf, :parser)
|
50
63
|
super
|
51
64
|
|
52
65
|
@parser = parser_create unless @status_only
|
66
|
+
@_request_headers = @request_headers.map do |section|
|
67
|
+
header = section["header"]
|
68
|
+
value = section["value"]
|
69
|
+
|
70
|
+
[header.to_sym, value]
|
71
|
+
end.to_h
|
53
72
|
end
|
54
73
|
|
55
74
|
def start
|
@@ -67,10 +86,20 @@ module Fluent
|
|
67
86
|
request_options[:proxy] = @proxy if @proxy
|
68
87
|
request_options[:user] = @user if @user
|
69
88
|
request_options[:password] = @password if @password
|
89
|
+
request_options[:headers] = @_request_headers unless @request_headers.empty?
|
70
90
|
|
71
91
|
res = RestClient::Request.execute request_options
|
92
|
+
|
72
93
|
record["status"] = res.code
|
73
94
|
record["body"] = res.body
|
95
|
+
|
96
|
+
record["header"] = {} unless @response_headers.empty?
|
97
|
+
@response_headers.each do |section|
|
98
|
+
name = section["header"]
|
99
|
+
symbolize_name = name.downcase.gsub(/-/, '_').to_sym
|
100
|
+
|
101
|
+
record["header"][name] = res.headers[symbolize_name]
|
102
|
+
end
|
74
103
|
rescue StandardError => err
|
75
104
|
if err.respond_to? :http_code
|
76
105
|
record["status"] = err.http_code || 0
|
data/test/helper/stub_server.rb
CHANGED
@@ -11,6 +11,7 @@ class StubServer
|
|
11
11
|
@server.mount_proc '/internal_error', &method(:internal_error)
|
12
12
|
@server.mount_proc '/redirect', &method(:redirect)
|
13
13
|
@server.mount_proc '/protected', &method(:protected)
|
14
|
+
@server.mount_proc '/custom_header', &method(:custom_header)
|
14
15
|
end
|
15
16
|
|
16
17
|
def start
|
@@ -81,4 +82,12 @@ class StubServer
|
|
81
82
|
res['Content-Type'] = 'application/json'
|
82
83
|
res.body = '{ "status": "OK" }'
|
83
84
|
end
|
85
|
+
|
86
|
+
def custom_header(req, res)
|
87
|
+
res.header["HATSUNE-MIKU"] = req["HATSUNE-MIKU"] if req["HATSUNE-MIKU"]
|
88
|
+
|
89
|
+
res.status = 200
|
90
|
+
res['Content-Type'] = 'application/json'
|
91
|
+
res.body = '{ "status": "OK" }'
|
92
|
+
end
|
84
93
|
end
|
@@ -453,6 +453,109 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
453
453
|
end
|
454
454
|
end
|
455
455
|
|
456
|
+
sub_test_case "capture response header" do
|
457
|
+
TEST_INTERVAL_3_RES_HEADER_CONFIG = %[
|
458
|
+
tag test
|
459
|
+
url http://127.0.0.1:3939
|
460
|
+
|
461
|
+
interval 3s
|
462
|
+
format json
|
463
|
+
|
464
|
+
<response_header>
|
465
|
+
header Content-Type
|
466
|
+
</response_header>
|
467
|
+
]
|
468
|
+
|
469
|
+
TEST_INTERVAL_3_RES_MULTI_HEADER_CONFIG = %[
|
470
|
+
tag test
|
471
|
+
url http://127.0.0.1:3939
|
472
|
+
|
473
|
+
interval 3s
|
474
|
+
format json
|
475
|
+
|
476
|
+
<response_header>
|
477
|
+
header Content-Type
|
478
|
+
</response_header>
|
479
|
+
|
480
|
+
<response_header>
|
481
|
+
header Content-Length
|
482
|
+
</response_header>
|
483
|
+
]
|
484
|
+
|
485
|
+
test 'interval 3 with single header' do
|
486
|
+
d = create_driver TEST_INTERVAL_3_RES_HEADER_CONFIG
|
487
|
+
assert_equal("test", d.instance.tag)
|
488
|
+
assert_equal(3, d.instance.interval)
|
489
|
+
|
490
|
+
d.run(timeout: 8) do
|
491
|
+
sleep 7
|
492
|
+
end
|
493
|
+
assert_equal(2, d.events.size)
|
494
|
+
|
495
|
+
d.events.each do |tag, time, record|
|
496
|
+
assert_equal("test", tag)
|
497
|
+
|
498
|
+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"Content-Type"=>"application/json"}}, record)
|
499
|
+
assert(time.is_a?(Fluent::EventTime))
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
test 'interval 3 with multiple header' do
|
504
|
+
d = create_driver TEST_INTERVAL_3_RES_MULTI_HEADER_CONFIG
|
505
|
+
assert_equal("test", d.instance.tag)
|
506
|
+
assert_equal(3, d.instance.interval)
|
507
|
+
|
508
|
+
d.run(timeout: 8) do
|
509
|
+
sleep 7
|
510
|
+
end
|
511
|
+
assert_equal(2, d.events.size)
|
512
|
+
|
513
|
+
d.events.each do |tag, time, record|
|
514
|
+
assert_equal("test", tag)
|
515
|
+
|
516
|
+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"Content-Type"=>"application/json","Content-Length"=>"18"}}, record)
|
517
|
+
assert(time.is_a?(Fluent::EventTime))
|
518
|
+
end
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
sub_test_case "custom request header" do
|
523
|
+
TEST_INTERVAL_3_CUSTOM_HEADER_CONFIG = %[
|
524
|
+
tag test
|
525
|
+
url http://127.0.0.1:3939/custom_header
|
526
|
+
|
527
|
+
interval 3s
|
528
|
+
format json
|
529
|
+
|
530
|
+
<request_header>
|
531
|
+
header HATSUNE-MIKU
|
532
|
+
value 3939
|
533
|
+
</request_header>
|
534
|
+
|
535
|
+
<response_header>
|
536
|
+
header HATSUNE-MIKU
|
537
|
+
</response_header>
|
538
|
+
]
|
539
|
+
|
540
|
+
test 'interval 3 with single header' do
|
541
|
+
d = create_driver TEST_INTERVAL_3_CUSTOM_HEADER_CONFIG
|
542
|
+
assert_equal("test", d.instance.tag)
|
543
|
+
assert_equal(3, d.instance.interval)
|
544
|
+
|
545
|
+
d.run(timeout: 8) do
|
546
|
+
sleep 7
|
547
|
+
end
|
548
|
+
assert_equal(2, d.events.size)
|
549
|
+
|
550
|
+
d.events.each do |tag, time, record|
|
551
|
+
assert_equal("test", tag)
|
552
|
+
|
553
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/custom_header","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"HATSUNE-MIKU"=>"3939"}}, record)
|
554
|
+
assert(time.is_a?(Fluent::EventTime))
|
555
|
+
end
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
456
559
|
private
|
457
560
|
|
458
561
|
def create_driver(conf)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-http-pull
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- filepang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: '0'
|
168
168
|
requirements: []
|
169
169
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.6.13
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
173
|
summary: fluent-plugin-http-pull
|