Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
Add ignore config check
Browse files Browse the repository at this point in the history
  • Loading branch information
toshitanian committed Jan 14, 2016
1 parent 58e6671 commit 18ac42a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/fluent/plugin/out_http_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def initialize

# Raise errors when HTTP response code was not successful.
config_param :raise_on_http_failure, :bool, :default => false

config_param :ignore_http_status_code, :string, :default => nil
# nil | 'none' | 'basic'
config_param :authentication, :string, :default => nil
config_param :username, :string, :default => ''
Expand Down
65 changes: 61 additions & 4 deletions test/plugin/test_out_http_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def setup
res.status = 200
res.body = 'slow_10'
}
srv.mount_proc('/status_code') { |req,res|
code = Hash[*(req.body.split('&').map{|kv|kv.split('=')}.flatten)][:code].to_i
res.status = code
res.body = ''
}

srv.start
ensure
Expand Down Expand Up @@ -180,14 +185,28 @@ class HTTPOutputTest < HTTPOutputTestBase
rate_limit_msec #{RATE_LIMIT_MSEC}
]

CONFIG_NOT_READ_TIMEOUT = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/slow_5/
read_timeout 7
]
CONFIG_READ_TIMEOUT = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/slow_10/
read_timeout 7
]

CONFIG_NOT_READ_TIMEOUT = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/slow_5/
read_timeout 7
CONFIG_IGNORE_NONE = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code?code=409/
]
CONFIG_IGNORE_409 = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code?code=409/
ignore_http_status_code 409
]
CONFIG_IGNORE_4XX = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code?code=409/
ignore_http_status_code 400..499
]
CONFIG_IGNORE_4XX_5XX = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code?code=409/
ignore_http_status_code 400..599
]

def create_driver(conf=CONFIG, tag='test.metrics')
Expand Down Expand Up @@ -342,6 +361,44 @@ def test_not_read_timeout
end
end

def test_ignore_none
d = create_driver CONFIG_IGNORE_NONE
assert_equal [], d.instance.ignore_http_status_code

# d.emit({})
# d.run
end

def test_ignore_409
d = create_driver CONFIG_IGNORE_409
assert_equal [409], d.instance.ignore_http_status_code

# assert_nothing_raised do
# d.emit({})
# d.run
# end
end

def test_ignore_4XX
d = create_driver CONFIG_IGNORE_4XX
assert_equal (400..499).to_a, d.instance.ignore_http_status_code

# assert_nothing_raised do
# d.emit({})
# d.run
# end
end

def test_ignore_4XX_5XX
d = create_driver CONFIG_IGNORE_4XX_5XX
assert_equal (400..599).to_a, d.instance.ignore_http_status_code

# assert_nothing_raised do
# d.emit({})
# d.run
# end
end

def _current_msec
Time.now.to_f * 1000
end
Expand Down

0 comments on commit 18ac42a

Please sign in to comment.