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

Commit

Permalink
Add ignore http status code option
Browse files Browse the repository at this point in the history
  • Loading branch information
toshitanian committed Jan 14, 2016
1 parent 18ac42a commit 8d7ba95
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ A generic [fluentd][1] output plugin for sending logs to an HTTP endpoint
read_timeout 10 # default: 60
raise_on_error false # default: true
raise_on_http_failure true # default: false
ignore_http_status_code 300,400..499 # default: nil # do not raise on these http_hstatus codes
authentication basic # default: none
username alice # default: ''
password bobpop # default: '', secret: true
Expand Down
6 changes: 5 additions & 1 deletion lib/fluent/plugin/out_http_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ def send_request(req, uri)
warning = "failed to #{req.method} #{uri} (#{res_summary})"
$log.warn warning
if @raise_on_http_failure
raise warning
unless @ignore_http_status_code.include?(res.code.to_i)
raise warning
else
$log.debug "ignore http status code #{req.method}"
end
end

end #end unless
Expand Down
81 changes: 60 additions & 21 deletions test/plugin/test_out_http_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def setup
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
r = Yajl.load(req.body)
code = r["code"]
res.status = code.to_s
res.body = ''
}

Expand Down Expand Up @@ -194,18 +195,26 @@ class HTTPOutputTest < HTTPOutputTestBase
read_timeout 7
]
CONFIG_IGNORE_NONE = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code?code=409/
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code/
serializer json
raise_on_http_failure true
]
CONFIG_IGNORE_409 = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code?code=409/
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code/
serializer json
raise_on_http_failure true
ignore_http_status_code 409
]
CONFIG_IGNORE_4XX = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code?code=409/
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code/
serializer json
raise_on_http_failure true
ignore_http_status_code 400..499
]
CONFIG_IGNORE_4XX_5XX = %[
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code?code=409/
endpoint_url http://127.0.0.1:#{TEST_LISTEN_PORT}/status_code/
serializer json
raise_on_http_failure true
ignore_http_status_code 400..599
]

Expand Down Expand Up @@ -365,38 +374,68 @@ def test_ignore_none
d = create_driver CONFIG_IGNORE_NONE
assert_equal [], d.instance.ignore_http_status_code

# d.emit({})
# d.run
assert_raise do
d.emit({:code=> 409})
d.run
end

assert_raise do
d.emit({:code => 500})
d.run
end
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
assert_nothing_raised do
d.emit({:code => 409})
d.run
end
assert_raise do
d.emit({:code => 404})
d.run
end
assert_raise do
d.emit({:code => 500})
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
assert_nothing_raised do
d.emit({:code => 409})
d.run
end
assert_nothing_raised do
d.emit({:code => 404})
d.run
end
assert_raise do
d.emit({:code => 500})
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
assert_nothing_raised do
d.emit({:code => 409})
d.run
end
assert_nothing_raised do
d.emit({:code => 404})
d.run
end
assert_nothing_raised do
d.emit({:code => 500})
d.run
end
end

def _current_msec
Expand Down

0 comments on commit 8d7ba95

Please sign in to comment.