Skip to content

Commit

Permalink
add health endpoint (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch authored Feb 16, 2022
1 parent 354ba13 commit 3d15485
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ build-iPhoneSimulator/

# Used by RuboCop. Remote config files pulled in from inherit_from directive.
# .rubocop-https?--*

.idea
3 changes: 3 additions & 0 deletions lib/fluent/plugin/in_http_cwm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions test/plugin/test_in_http_cwm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'helper'
require 'fluent/plugin/in_http_cwm'
require 'net/http'
require 'json'

class CwmHttpInputTest < Test::Unit::TestCase
setup do
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 3d15485

Please sign in to comment.