From 18ac42ae4de5bcdafe058c9adef12b2a01d26de5 Mon Sep 17 00:00:00 2001 From: Toshiya Kawasaki Date: Thu, 14 Jan 2016 18:43:54 +0900 Subject: [PATCH] Add ignore config check --- lib/fluent/plugin/out_http_ext.rb | 2 +- test/plugin/test_out_http_ext.rb | 65 +++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/lib/fluent/plugin/out_http_ext.rb b/lib/fluent/plugin/out_http_ext.rb index 73f81df..c2b2f88 100644 --- a/lib/fluent/plugin/out_http_ext.rb +++ b/lib/fluent/plugin/out_http_ext.rb @@ -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 => '' diff --git a/test/plugin/test_out_http_ext.rb b/test/plugin/test_out_http_ext.rb index 34ebed8..33c7469 100644 --- a/test/plugin/test_out_http_ext.rb +++ b/test/plugin/test_out_http_ext.rb @@ -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 @@ -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') @@ -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