Skip to content

Commit

Permalink
Handle zero payload (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryTsepelev committed Feb 26, 2023
1 parent 18d44c9 commit ca85892
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Change log

- [PR#22](https://github.com/DmitryTsepelev/io_monitor/pull/22) Handle zero payload ([@DmitryTsepelev])
- [PR#17](https://github.com/DmitryTsepelev/io_monitor/pull/17) Prometheus publisher ([@maxshend])

## main
Expand Down
6 changes: 3 additions & 3 deletions lib/io_monitor/publishers/base_publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def process_action(payload)
(payload.keys - [:response]).each do |source|
ratio = ratio(payload[:response], payload[source])

if ratio < IoMonitor.config.warn_threshold
publish(source, ratio)
end
publish(source, ratio) if ratio < IoMonitor.config.warn_threshold
end
end

private

def ratio(response_size, io_size)
return 0 if io_size.to_f.zero?

response_size.to_f / io_size.to_f
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/io_monitor/publishers/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@

publisher.process_action(payload)
end

context "when io_payload_size is zero" do
let(:io_payload_size) { 0 }
let(:ratio) { 0 }

it "calls .publish method with source and ratio" do
expect(publisher).to receive(:publish).with(io_kind, ratio)

publisher.process_action(payload)
end
end
end
end
end

0 comments on commit ca85892

Please sign in to comment.