-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a hash of hash response to Heartcheck
Add a hash of hash response to Heartcheck
- Loading branch information
Lucca Baratera
committed
May 18, 2020
1 parent
73e6045
commit 534f6b2
Showing
4 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Heartcheck | ||
module Executors | ||
class HashResponse | ||
def dispatch(checkers) | ||
checkers.map do |checker| | ||
track_and_check(checker) | ||
end.reduce({}, :merge) | ||
end | ||
|
||
def track_and_check(checker) | ||
started = Time.now | ||
checker.check.tap do |checked| | ||
value = checked.values.first.merge(time:((Time.now - started) * 1_000.0)) | ||
checked.merge!(Hash[checked.keys.first => value]) | ||
Logger.info MultiJson.dump(checked) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'heartcheck/executors/hash_response' | ||
|
||
module Heartcheck | ||
module Executors | ||
describe HashResponse do | ||
subject { described_class.new } | ||
|
||
describe '#dispatch' do | ||
let(:registered) { 3 } | ||
|
||
let(:checkers) do | ||
registered.times.collect do |current| | ||
double.tap do |checker| | ||
expect(checker).to receive(:check).and_return({ current: { status: 'ok' } }) | ||
end | ||
end | ||
end | ||
|
||
it 'should register a log entry for each checker' do | ||
expect(Logger).to receive(:info).exactly(registered).times | ||
subject.dispatch(checkers) | ||
end | ||
|
||
it "should have a :time key in the checker response" do | ||
subject.dispatch(checkers).each do |current| | ||
expect(current.last).to include(:time) | ||
end | ||
end | ||
|
||
it "should have a float value (time key)" do | ||
subject.dispatch(checkers).each do |current| | ||
expect(current.last[:time]).to be_a(Float) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters