diff --git a/.gitignore b/.gitignore index e3200e0..4f987fe 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,5 @@ build-iPhoneSimulator/ # Used by RuboCop. Remote config files pulled in from inherit_from directive. # .rubocop-https?--* + +.idea diff --git a/lib/fluent/plugin/in_http_cwm.rb b/lib/fluent/plugin/in_http_cwm.rb index e6b4c32..17f6584 100644 --- a/lib/fluent/plugin/in_http_cwm.rb +++ b/lib/fluent/plugin/in_http_cwm.rb @@ -104,6 +104,9 @@ def start # return HTTP 200 OK response with emtpy body [200, { 'Content-Type' => 'text/plain' }, nil] end + server.get("/health") do |req| + [200, { 'Content-Type' => 'application/json' }, {}.to_json] + end end end diff --git a/test/plugin/test_in_http_cwm.rb b/test/plugin/test_in_http_cwm.rb index 948d552..f817cf3 100644 --- a/test/plugin/test_in_http_cwm.rb +++ b/test/plugin/test_in_http_cwm.rb @@ -3,6 +3,7 @@ require 'helper' require 'fluent/plugin/in_http_cwm' require 'net/http' +require 'json' class CwmHttpInputTest < Test::Unit::TestCase setup do @@ -64,8 +65,13 @@ def create_driver(conf) res_codes = [] lines = 0 + health_res_code = '' + health_res_body = '' driver.run do + health_res = get('/health') + health_res_code = health_res.code + health_res_body = health_res.body File.readlines('./test/logs.txt').each do |line| res = post('/test', line.chomp) res_codes << res.code @@ -77,6 +83,9 @@ def create_driver(conf) assert_equal '200', res_codes[0] assert_equal 1, res_codes.uniq.size + assert_equal '200', health_res_code + assert_equal ({}), JSON.parse(health_res_body) + # run and test private flushing methods `redis-cli FLUSHALL` sleep(redis.grace_period) @@ -107,4 +116,10 @@ def post(path, body) req.body = body http.request(req) end + + def get(path) + http = Net::HTTP.new('127.0.0.1', 8080) + req = Net::HTTP::Get.new(path) + http.request(req) + end end