fluent-plugin-http-pull 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +12 -0
- data/Rakefile +24 -13
- data/fluent-plugin-http-pull.gemspec +3 -1
- data/lib/fluent/plugin/in_http_pull.rb +15 -4
- data/test/helper.rb +4 -0
- data/test/helper/stub_proxy.rb +39 -0
- data/test/helper/stub_server.rb +84 -0
- data/test/plugin/test_in_http_pull.rb +317 -35
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 533830e127ee4cbc297f6dcfd1c4a3a08882ca9d
|
4
|
+
data.tar.gz: a689af041c24cc88e64fd61b14c54b42dbfe6450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a813fd4dbee8607a9188676e0fa01f477aee8747064f848767a06949825973a09c1f233d767dd410911d6471c0d73714d586cf6cc2d0d518a9e63adb6342de5d
|
7
|
+
data.tar.gz: 616f089b1f0ebacc78fe871c21f4ee9131c6746e1bc88a905dee489f835f8cb5ffac409863b0f930b0235099926a9b115b8def19deb8c8a78585b3d6cf44f002
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -139,6 +139,18 @@ If status_only is true, body is not parsed.
|
|
139
139
|
|
140
140
|
The timeout of each request.
|
141
141
|
|
142
|
+
### proxy (string) (optional, default: nil)
|
143
|
+
|
144
|
+
The HTTP proxy URL to use for each requests
|
145
|
+
|
146
|
+
### user (string) (optional, default: nil)
|
147
|
+
|
148
|
+
The user for basic auth
|
149
|
+
|
150
|
+
### password (string) (optional, default: nil)
|
151
|
+
|
152
|
+
The password for basic auth
|
153
|
+
|
142
154
|
## In case of remote error
|
143
155
|
|
144
156
|
### Can receive response from remote
|
data/Rakefile
CHANGED
@@ -1,13 +1,24 @@
|
|
1
|
-
require "bundler"
|
2
|
-
Bundler::GemHelper.install_tasks
|
3
|
-
|
4
|
-
require "rake/testtask"
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
|
1
|
+
require "bundler"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require "rake/testtask"
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
if File.exists? "stub_server.log"
|
9
|
+
puts "clear stub_server.log"
|
10
|
+
FileUtils.rm "stub_server.log"
|
11
|
+
end
|
12
|
+
|
13
|
+
if File.exists? "stub_proxy.log"
|
14
|
+
puts "clear stub_proxy.log"
|
15
|
+
FileUtils.rm "stub_proxy.log"
|
16
|
+
end
|
17
|
+
|
18
|
+
t.libs.push("lib", "test")
|
19
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
20
|
+
t.verbose = true
|
21
|
+
t.warning = true
|
22
|
+
end
|
23
|
+
|
24
|
+
task default: [:test]
|
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "fluent-plugin-http-pull"
|
6
|
-
spec.version = "0.
|
6
|
+
spec.version = "0.4.0"
|
7
7
|
spec.authors = ["filepang"]
|
8
8
|
spec.email = ["filepang@gmail.com"]
|
9
9
|
|
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.test_files = test_files
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
+
spec.required_ruby_version = '>= 2.1'
|
24
|
+
|
23
25
|
spec.add_development_dependency "rake", "~> 12.0"
|
24
26
|
spec.add_development_dependency "simplecov", "~> 0.7"
|
25
27
|
spec.add_development_dependency "test-unit", "~> 3.0"
|
@@ -35,8 +35,15 @@ module Fluent
|
|
35
35
|
config_param :interval, :time
|
36
36
|
desc 'status_only'
|
37
37
|
config_param :status_only, :bool, default: false
|
38
|
-
desc 'timeout
|
38
|
+
desc 'The timeout stime of each request'
|
39
39
|
config_param :timeout, :time, default: 10
|
40
|
+
desc 'The HTTP proxy URL to use for each requests'
|
41
|
+
config_param :proxy, :string, default: nil
|
42
|
+
|
43
|
+
desc 'user of basic auth'
|
44
|
+
config_param :user, :string, default: nil
|
45
|
+
desc 'password of basic auth'
|
46
|
+
config_param :password, :string, default: nil
|
40
47
|
|
41
48
|
def configure(conf)
|
42
49
|
compat_parameters_convert(conf, :parser)
|
@@ -55,9 +62,13 @@ module Fluent
|
|
55
62
|
record = { "url" => @url }
|
56
63
|
|
57
64
|
begin
|
58
|
-
|
59
|
-
|
60
|
-
|
65
|
+
request_options = { method: :get, url: @url, timeout: @timeout }
|
66
|
+
|
67
|
+
request_options[:proxy] = @proxy if @proxy
|
68
|
+
request_options[:user] = @user if @user
|
69
|
+
request_options[:password] = @password if @password
|
70
|
+
|
71
|
+
res = RestClient::Request.execute request_options
|
61
72
|
record["status"] = res.code
|
62
73
|
record["body"] = res.body
|
63
74
|
rescue StandardError => err
|
data/test/helper.rb
CHANGED
@@ -21,5 +21,9 @@ require "fluent/test/helpers"
|
|
21
21
|
|
22
22
|
require "test/unit/rr"
|
23
23
|
|
24
|
+
# require stub_server
|
25
|
+
require "test/helper/stub_server"
|
26
|
+
require "test/helper/stub_proxy"
|
27
|
+
|
24
28
|
Test::Unit::TestCase.include(Fluent::Test::Helpers)
|
25
29
|
Test::Unit::TestCase.extend(Fluent::Test::Helpers)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
require 'webrick/httpproxy'
|
3
|
+
|
4
|
+
class StubProxy
|
5
|
+
def initialize
|
6
|
+
create_proxy
|
7
|
+
end
|
8
|
+
|
9
|
+
def start
|
10
|
+
@thread = Thread.new { @proxy.start }
|
11
|
+
end
|
12
|
+
|
13
|
+
def shutdown
|
14
|
+
@proxy.shutdown
|
15
|
+
|
16
|
+
# wait until webrick was shutting down
|
17
|
+
while true
|
18
|
+
break if @thread.status == false
|
19
|
+
|
20
|
+
# issue webrick shutdown once more
|
21
|
+
@proxy.shutdown
|
22
|
+
sleep 1
|
23
|
+
end
|
24
|
+
|
25
|
+
# then exit thread
|
26
|
+
@thread.exit
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def create_proxy
|
31
|
+
@log_file = File.open("stub_proxy.log", "a+")
|
32
|
+
@log = WEBrick::Log.new @log_file
|
33
|
+
@access_log = [
|
34
|
+
[@log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
|
35
|
+
]
|
36
|
+
|
37
|
+
@proxy = WEBrick::HTTPProxyServer.new :Port => 4040, :Logger => @log, :AccessLog => @access_log
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
|
3
|
+
class StubServer
|
4
|
+
def initialize
|
5
|
+
create_server
|
6
|
+
|
7
|
+
# mount handler
|
8
|
+
@server.mount_proc '/', &method(:ok)
|
9
|
+
@server.mount_proc '/not_exist', &method(:not_exist)
|
10
|
+
@server.mount_proc '/timeout', &method(:timeout)
|
11
|
+
@server.mount_proc '/internal_error', &method(:internal_error)
|
12
|
+
@server.mount_proc '/redirect', &method(:redirect)
|
13
|
+
@server.mount_proc '/protected', &method(:protected)
|
14
|
+
end
|
15
|
+
|
16
|
+
def start
|
17
|
+
@thread = Thread.new { @server.start }
|
18
|
+
end
|
19
|
+
|
20
|
+
def shutdown
|
21
|
+
@server.shutdown
|
22
|
+
|
23
|
+
# wait until webrick was shutting down
|
24
|
+
while true
|
25
|
+
break if @thread.status == false
|
26
|
+
|
27
|
+
# issue webrick shutdown once more
|
28
|
+
@server.shutdown
|
29
|
+
sleep 1
|
30
|
+
end
|
31
|
+
|
32
|
+
# then exit thread
|
33
|
+
@thread.exit
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def create_server
|
38
|
+
@log_file = File.open("stub_server.log", "a+")
|
39
|
+
@log = WEBrick::Log.new @log_file
|
40
|
+
@access_log = [
|
41
|
+
[@log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
|
42
|
+
]
|
43
|
+
|
44
|
+
@server = WEBrick::HTTPServer.new :Port => 3939, :Logger => @log, :AccessLog => @access_log
|
45
|
+
end
|
46
|
+
|
47
|
+
def ok(req, res)
|
48
|
+
res.status = 200
|
49
|
+
res['Content-Type'] = 'application/json'
|
50
|
+
res.body = '{ "status": "OK" }'
|
51
|
+
end
|
52
|
+
|
53
|
+
def not_exist(req, res)
|
54
|
+
res.status = 404
|
55
|
+
res.body = ''
|
56
|
+
end
|
57
|
+
|
58
|
+
def timeout(req, res)
|
59
|
+
sleep 3
|
60
|
+
|
61
|
+
res.status = 200
|
62
|
+
res['Content-Type'] = 'application/json'
|
63
|
+
res.body = '{ "status": "OK" }'
|
64
|
+
end
|
65
|
+
|
66
|
+
def internal_error(req, res)
|
67
|
+
res.status = 500
|
68
|
+
res.body = ''
|
69
|
+
end
|
70
|
+
|
71
|
+
def redirect(req, res)
|
72
|
+
res.set_redirect WEBrick::HTTPStatus::TemporaryRedirect, "http://127.0.0.1:3939/"
|
73
|
+
end
|
74
|
+
|
75
|
+
def protected(req, res)
|
76
|
+
WEBrick::HTTPAuth.basic_auth(req, res, 'protected') do |user, password|
|
77
|
+
user == 'HatsuneMiku' && password == '3939'
|
78
|
+
end
|
79
|
+
|
80
|
+
res.status = 200
|
81
|
+
res['Content-Type'] = 'application/json'
|
82
|
+
res.body = '{ "status": "OK" }'
|
83
|
+
end
|
84
|
+
end
|
@@ -4,14 +4,21 @@ require "fluent/plugin/in_http_pull.rb"
|
|
4
4
|
require 'ostruct'
|
5
5
|
|
6
6
|
class HttpPullInputTest < Test::Unit::TestCase
|
7
|
+
@stub_server = nil
|
8
|
+
|
7
9
|
setup do
|
8
|
-
|
10
|
+
@stub_server = StubServer.new
|
11
|
+
@stub_server.start
|
12
|
+
end
|
13
|
+
|
14
|
+
teardown do
|
15
|
+
@stub_server.shutdown
|
9
16
|
end
|
10
17
|
|
11
18
|
sub_test_case "default value of each options" do
|
12
19
|
TEST_DEFAULT_VALUE_CONFIG = %[
|
13
20
|
tag test
|
14
|
-
url http://127.0.0.1
|
21
|
+
url http://127.0.0.1:3939
|
15
22
|
|
16
23
|
interval 3s
|
17
24
|
format json
|
@@ -30,13 +37,33 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
30
37
|
|
31
38
|
assert_equal(10, d.instance.timeout)
|
32
39
|
end
|
40
|
+
|
41
|
+
test 'user' do
|
42
|
+
d = create_driver TEST_DEFAULT_VALUE_CONFIG
|
43
|
+
assert_equal("test", d.instance.tag)
|
44
|
+
|
45
|
+
assert_equal(nil, d.instance.user)
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'password' do
|
49
|
+
d = create_driver TEST_DEFAULT_VALUE_CONFIG
|
50
|
+
assert_equal("test", d.instance.tag)
|
51
|
+
|
52
|
+
assert_equal(nil, d.instance.password)
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'proxy' do
|
56
|
+
d = create_driver TEST_DEFAULT_VALUE_CONFIG
|
57
|
+
assert_equal("test", d.instance.tag)
|
58
|
+
|
59
|
+
assert_equal(nil, d.instance.proxy)
|
60
|
+
end
|
33
61
|
end
|
34
62
|
|
35
|
-
sub_test_case "success case
|
63
|
+
sub_test_case "success case" do
|
36
64
|
TEST_INTERVAL_3_CONFIG = %[
|
37
65
|
tag test
|
38
|
-
url http://127.0.0.1
|
39
|
-
timeout 10
|
66
|
+
url http://127.0.0.1:3939
|
40
67
|
|
41
68
|
interval 3s
|
42
69
|
format none
|
@@ -45,29 +72,26 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
45
72
|
|
46
73
|
TEST_INTERVAL_5_CONFIG = %[
|
47
74
|
tag test
|
48
|
-
url http://127.0.0.1
|
49
|
-
timeout 10
|
75
|
+
url http://127.0.0.1:3939
|
50
76
|
|
51
77
|
interval 5s
|
52
78
|
format json
|
53
79
|
]
|
54
80
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
81
|
+
TEST_INTERVAL_3_REDIRECT_CONFIG = %[
|
82
|
+
tag test
|
83
|
+
url http://127.0.0.1:3939/redirect
|
84
|
+
|
85
|
+
interval 3s
|
86
|
+
format json
|
87
|
+
]
|
64
88
|
|
65
89
|
test 'interval 3 with status_only' do
|
66
90
|
d = create_driver TEST_INTERVAL_3_CONFIG
|
67
91
|
assert_equal("test", d.instance.tag)
|
68
92
|
assert_equal(3, d.instance.interval)
|
69
93
|
|
70
|
-
d.run(timeout:
|
94
|
+
d.run(timeout: 8) do
|
71
95
|
sleep 7
|
72
96
|
end
|
73
97
|
assert_equal(2, d.events.size)
|
@@ -75,7 +99,7 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
75
99
|
d.events.each do |tag, time, record|
|
76
100
|
assert_equal("test", tag)
|
77
101
|
|
78
|
-
assert_equal({"url"=>"http://127.0.0.1","status"=>200}, record)
|
102
|
+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200}, record)
|
79
103
|
assert(time.is_a?(Fluent::EventTime))
|
80
104
|
end
|
81
105
|
end
|
@@ -85,7 +109,7 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
85
109
|
assert_equal("test", d.instance.tag)
|
86
110
|
assert_equal(5, d.instance.interval)
|
87
111
|
|
88
|
-
d.run(timeout:
|
112
|
+
d.run(timeout: 12) do
|
89
113
|
sleep 11
|
90
114
|
end
|
91
115
|
assert_equal(2, d.events.size)
|
@@ -93,12 +117,92 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
93
117
|
d.events.each do |tag, time, record|
|
94
118
|
assert_equal("test", tag)
|
95
119
|
|
96
|
-
assert_equal({"url"=>"http://127.0.0.1","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
120
|
+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
121
|
+
assert(time.is_a?(Fluent::EventTime))
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
test 'interval 3 with redirect' do
|
126
|
+
d = create_driver TEST_INTERVAL_3_REDIRECT_CONFIG
|
127
|
+
assert_equal("test", d.instance.tag)
|
128
|
+
assert_equal(3, d.instance.interval)
|
129
|
+
|
130
|
+
d.run(timeout: 8) do
|
131
|
+
sleep 7
|
132
|
+
end
|
133
|
+
assert_equal(2, d.events.size)
|
134
|
+
|
135
|
+
d.events.each do |tag, time, record|
|
136
|
+
assert_equal("test", tag)
|
137
|
+
|
138
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/redirect","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
97
139
|
assert(time.is_a?(Fluent::EventTime))
|
98
140
|
end
|
99
141
|
end
|
100
142
|
end
|
101
143
|
|
144
|
+
sub_test_case "fail when not 200 OK" do
|
145
|
+
TEST_404_INTERVAL_3_CONFIG = %[
|
146
|
+
tag test
|
147
|
+
url http://127.0.0.1:3939/not_exist
|
148
|
+
|
149
|
+
interval 3s
|
150
|
+
format none
|
151
|
+
status_only true
|
152
|
+
]
|
153
|
+
|
154
|
+
TEST_500_INTERVAL_3_CONFIG = %[
|
155
|
+
tag test
|
156
|
+
url http://127.0.0.1:3939/internal_error
|
157
|
+
|
158
|
+
interval 3s
|
159
|
+
format none
|
160
|
+
status_only true
|
161
|
+
]
|
162
|
+
|
163
|
+
test '404' do
|
164
|
+
d = create_driver TEST_404_INTERVAL_3_CONFIG
|
165
|
+
assert_equal("test", d.instance.tag)
|
166
|
+
assert_equal(3, d.instance.interval)
|
167
|
+
|
168
|
+
d.run(timeout: 8) do
|
169
|
+
sleep 7
|
170
|
+
end
|
171
|
+
assert_equal(2, d.events.size)
|
172
|
+
|
173
|
+
d.events.each do |tag, time, record|
|
174
|
+
assert_equal("test", tag)
|
175
|
+
|
176
|
+
assert_equal("http://127.0.0.1:3939/not_exist", record["url"])
|
177
|
+
assert(time.is_a?(Fluent::EventTime))
|
178
|
+
|
179
|
+
assert_equal(404, record["status"])
|
180
|
+
assert_not_nil(record["error"])
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
test '500' do
|
185
|
+
d = create_driver TEST_500_INTERVAL_3_CONFIG
|
186
|
+
assert_equal("test", d.instance.tag)
|
187
|
+
assert_equal(3, d.instance.interval)
|
188
|
+
|
189
|
+
d.run(timeout: 8) do
|
190
|
+
sleep 7
|
191
|
+
end
|
192
|
+
assert_equal(2, d.events.size)
|
193
|
+
|
194
|
+
d.events.each do |tag, time, record|
|
195
|
+
assert_equal("test", tag)
|
196
|
+
|
197
|
+
assert_equal("http://127.0.0.1:3939/internal_error", record["url"])
|
198
|
+
assert(time.is_a?(Fluent::EventTime))
|
199
|
+
|
200
|
+
assert_equal(500, record["status"])
|
201
|
+
assert_not_nil(record["error"])
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
102
206
|
sub_test_case "fail when remote down" do
|
103
207
|
TEST_REFUSED_CONFIG = %[
|
104
208
|
tag test
|
@@ -111,7 +215,7 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
111
215
|
d = create_driver TEST_REFUSED_CONFIG
|
112
216
|
assert_equal("test", d.instance.tag)
|
113
217
|
|
114
|
-
d.run(timeout:
|
218
|
+
d.run(timeout: 4) do
|
115
219
|
sleep 3
|
116
220
|
end
|
117
221
|
|
@@ -131,30 +235,19 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
131
235
|
sub_test_case "fail when remote timeout" do
|
132
236
|
TEST_TIMEOUT_FAIL_CONFIG = %[
|
133
237
|
tag test
|
134
|
-
url http://127.0.0.1
|
238
|
+
url http://127.0.0.1:3939/timeout
|
135
239
|
timeout 2s
|
136
240
|
|
137
241
|
interval 3s
|
138
242
|
format json
|
139
243
|
]
|
140
244
|
|
141
|
-
setup do
|
142
|
-
mock(RestClient::Request).
|
143
|
-
execute(method: :get,
|
144
|
-
url: "http://127.0.0.1",
|
145
|
-
timeout: 2).
|
146
|
-
times(2) do
|
147
|
-
sleep 2
|
148
|
-
raise RestClient::Exceptions::Timeout.new
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
245
|
test "timeout" do
|
153
246
|
d = create_driver TEST_TIMEOUT_FAIL_CONFIG
|
154
247
|
assert_equal("test", d.instance.tag)
|
155
248
|
assert_equal(2, d.instance.timeout)
|
156
249
|
|
157
|
-
d.run(timeout:
|
250
|
+
d.run(timeout: 8) do
|
158
251
|
sleep 7
|
159
252
|
end
|
160
253
|
assert_equal(2, d.events.size)
|
@@ -162,7 +255,7 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
162
255
|
d.events.each do |tag, time, record|
|
163
256
|
assert_equal("test", tag)
|
164
257
|
|
165
|
-
assert_equal("http://127.0.0.1", record["url"])
|
258
|
+
assert_equal("http://127.0.0.1:3939/timeout", record["url"])
|
166
259
|
assert(time.is_a?(Fluent::EventTime))
|
167
260
|
|
168
261
|
assert_equal(0, record["status"])
|
@@ -171,6 +264,195 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
171
264
|
end
|
172
265
|
end
|
173
266
|
|
267
|
+
sub_test_case "remote is prtected by basic auth" do
|
268
|
+
TEST_AUTH_SUCCESS_CONFIG = %[
|
269
|
+
tag test
|
270
|
+
url http://127.0.0.1:3939/protected
|
271
|
+
timeout 2s
|
272
|
+
user HatsuneMiku
|
273
|
+
password 3939
|
274
|
+
|
275
|
+
interval 3s
|
276
|
+
format json
|
277
|
+
]
|
278
|
+
|
279
|
+
TEST_AUTH_FAIL_CONFIG = %[
|
280
|
+
tag test
|
281
|
+
url http://127.0.0.1:3939/protected
|
282
|
+
timeout 2s
|
283
|
+
user HatsuneMiku
|
284
|
+
password wrong_password
|
285
|
+
|
286
|
+
interval 3s
|
287
|
+
format json
|
288
|
+
]
|
289
|
+
|
290
|
+
TEST_AUTH_FAIL_NOT_GIVEN_CONFIG = %[
|
291
|
+
tag test
|
292
|
+
url http://127.0.0.1:3939/protected
|
293
|
+
timeout 2s
|
294
|
+
|
295
|
+
interval 3s
|
296
|
+
format json
|
297
|
+
]
|
298
|
+
|
299
|
+
test 'interval 3 with corrent password' do
|
300
|
+
d = create_driver TEST_AUTH_SUCCESS_CONFIG
|
301
|
+
assert_equal("test", d.instance.tag)
|
302
|
+
assert_equal(3, d.instance.interval)
|
303
|
+
|
304
|
+
d.run(timeout: 8) do
|
305
|
+
sleep 7
|
306
|
+
end
|
307
|
+
assert_equal(2, d.events.size)
|
308
|
+
|
309
|
+
d.events.each do |tag, time, record|
|
310
|
+
assert_equal("test", tag)
|
311
|
+
|
312
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/protected","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
313
|
+
assert(time.is_a?(Fluent::EventTime))
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
test 'interval 3 with wrong password' do
|
318
|
+
d = create_driver TEST_AUTH_FAIL_CONFIG
|
319
|
+
assert_equal("test", d.instance.tag)
|
320
|
+
assert_equal(3, d.instance.interval)
|
321
|
+
|
322
|
+
d.run(timeout: 8) do
|
323
|
+
sleep 7
|
324
|
+
end
|
325
|
+
assert_equal(2, d.events.size)
|
326
|
+
|
327
|
+
d.events.each do |tag, time, record|
|
328
|
+
assert_equal("test", tag)
|
329
|
+
|
330
|
+
assert_equal("http://127.0.0.1:3939/protected", record["url"])
|
331
|
+
assert(time.is_a?(Fluent::EventTime))
|
332
|
+
|
333
|
+
assert_equal(401, record["status"])
|
334
|
+
assert_not_nil(record["error"])
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
test 'interval 3 without auth info' do
|
339
|
+
d = create_driver TEST_AUTH_FAIL_CONFIG
|
340
|
+
assert_equal("test", d.instance.tag)
|
341
|
+
assert_equal(3, d.instance.interval)
|
342
|
+
|
343
|
+
d.run(timeout: 8) do
|
344
|
+
sleep 7
|
345
|
+
end
|
346
|
+
assert_equal(2, d.events.size)
|
347
|
+
|
348
|
+
d.events.each do |tag, time, record|
|
349
|
+
assert_equal("test", tag)
|
350
|
+
|
351
|
+
assert_equal("http://127.0.0.1:3939/protected", record["url"])
|
352
|
+
assert(time.is_a?(Fluent::EventTime))
|
353
|
+
|
354
|
+
assert_equal(401, record["status"])
|
355
|
+
assert_not_nil(record["error"])
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
sub_test_case "success case behind proxy" do
|
361
|
+
TEST_INTERVAL_3_PROXY_CONFIG = %[
|
362
|
+
tag test
|
363
|
+
url http://127.0.0.1:3939
|
364
|
+
proxy http://127.0.0.1:4040
|
365
|
+
|
366
|
+
interval 3s
|
367
|
+
format none
|
368
|
+
status_only true
|
369
|
+
]
|
370
|
+
|
371
|
+
TEST_INTERVAL_3_REDIRECT_PROXY_CONFIG = %[
|
372
|
+
tag test
|
373
|
+
url http://127.0.0.1:3939/redirect
|
374
|
+
proxy http://127.0.0.1:4040
|
375
|
+
|
376
|
+
interval 3s
|
377
|
+
format json
|
378
|
+
]
|
379
|
+
|
380
|
+
TEST_AUTH_SUCCESS_PROXY_CONFIG = %[
|
381
|
+
tag test
|
382
|
+
url http://127.0.0.1:3939/protected
|
383
|
+
proxy http://127.0.0.1:4040
|
384
|
+
timeout 2s
|
385
|
+
user HatsuneMiku
|
386
|
+
password 3939
|
387
|
+
|
388
|
+
interval 3s
|
389
|
+
format json
|
390
|
+
]
|
391
|
+
|
392
|
+
setup do
|
393
|
+
@proxy_server = StubProxy.new
|
394
|
+
@proxy_server.start
|
395
|
+
end
|
396
|
+
|
397
|
+
teardown do
|
398
|
+
@proxy_server.shutdown
|
399
|
+
end
|
400
|
+
|
401
|
+
test 'interval 3 with status_only' do
|
402
|
+
d = create_driver TEST_INTERVAL_3_PROXY_CONFIG
|
403
|
+
assert_equal("test", d.instance.tag)
|
404
|
+
assert_equal(3, d.instance.interval)
|
405
|
+
|
406
|
+
d.run(timeout: 8) do
|
407
|
+
sleep 7
|
408
|
+
end
|
409
|
+
assert_equal(2, d.events.size)
|
410
|
+
|
411
|
+
d.events.each do |tag, time, record|
|
412
|
+
assert_equal("test", tag)
|
413
|
+
|
414
|
+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200}, record)
|
415
|
+
assert(time.is_a?(Fluent::EventTime))
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
test 'interval 3 with redirect' do
|
420
|
+
d = create_driver TEST_INTERVAL_3_REDIRECT_PROXY_CONFIG
|
421
|
+
assert_equal("test", d.instance.tag)
|
422
|
+
assert_equal(3, d.instance.interval)
|
423
|
+
|
424
|
+
d.run(timeout: 8) do
|
425
|
+
sleep 7
|
426
|
+
end
|
427
|
+
assert_equal(2, d.events.size)
|
428
|
+
|
429
|
+
d.events.each do |tag, time, record|
|
430
|
+
assert_equal("test", tag)
|
431
|
+
|
432
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/redirect","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
433
|
+
assert(time.is_a?(Fluent::EventTime))
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
test 'interval 3 with corrent password' do
|
438
|
+
d = create_driver TEST_AUTH_SUCCESS_PROXY_CONFIG
|
439
|
+
assert_equal("test", d.instance.tag)
|
440
|
+
assert_equal(3, d.instance.interval)
|
441
|
+
|
442
|
+
d.run(timeout: 8) do
|
443
|
+
sleep 7
|
444
|
+
end
|
445
|
+
assert_equal(2, d.events.size)
|
446
|
+
|
447
|
+
d.events.each do |tag, time, record|
|
448
|
+
assert_equal("test", tag)
|
449
|
+
|
450
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/protected","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
451
|
+
assert(time.is_a?(Fluent::EventTime))
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
174
456
|
private
|
175
457
|
|
176
458
|
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.4.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-
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -144,6 +144,8 @@ files:
|
|
144
144
|
- fluent-plugin-http-pull.gemspec
|
145
145
|
- lib/fluent/plugin/in_http_pull.rb
|
146
146
|
- test/helper.rb
|
147
|
+
- test/helper/stub_proxy.rb
|
148
|
+
- test/helper/stub_server.rb
|
147
149
|
- test/plugin/test_in_http_pull.rb
|
148
150
|
homepage: https://github.com/HatsuneMiku3939/fluent-plugin-http-pull
|
149
151
|
licenses:
|
@@ -157,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
159
|
requirements:
|
158
160
|
- - ">="
|
159
161
|
- !ruby/object:Gem::Version
|
160
|
-
version: '
|
162
|
+
version: '2.1'
|
161
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
164
|
requirements:
|
163
165
|
- - ">="
|
@@ -171,4 +173,6 @@ specification_version: 4
|
|
171
173
|
summary: fluent-plugin-http-pull
|
172
174
|
test_files:
|
173
175
|
- test/helper.rb
|
176
|
+
- test/helper/stub_proxy.rb
|
177
|
+
- test/helper/stub_server.rb
|
174
178
|
- test/plugin/test_in_http_pull.rb
|