appsignal / appsignal-ruby

🟥 AppSignal for Ruby gem
https://www.appsignal.com/ruby
MIT License
183 stars 115 forks source link

Implement heartbeat checkins #1293

Closed unflxw closed 1 month ago

unflxw commented 2 months ago

Part of https://github.com/appsignal/integration-guide/issues/169.

Ensure stubs are called exactly once

[@tombruijn could you take a look? I tried more reasonable approaches within webmock before reaching this count-requests-separately solution, but maybe I missed something in webmock that would solve this in a less awkward way]

Ensure that the stubs are called exactly once -- that is, that the same stub is not used several times, potentially masking a bug where several transmissions happen for the same events, and that no stubs are declared which are left unused.

The strange way in which it is implemented is due to certain quirks of how the webmock gem works. I could not find a way to have a stub automatically disable itself when called, similar to what the nock Node.js package provides -- so I implemented this by passing a number of request bodies to expect to respond to when declaring the mock, and erroring if more requests are made than the request bodies provided.

That, however, does not cover the scenario where the stub is not called at all. Somewhat bafflingly, the have_been_requested matcher does not check a counter that has been incremented for each request. Instead, it re-runs the requests it has stored by the stubs again, and counts how many match. Given the implementation described above, where the stub is exhausting a list of request bodies as it goes, the matcher will fail when attempting to go a second time around.

So instead, we increment a counter when a request is processed (without said request having exhausted the matcher) and we return that counter from the stub. The tests store these counters in a let binding, and an after block checks that each stored counter has been increased to one. This is done in an after block not only for convenience, but because some tests are mocking a call that will only be performed in that same after block, when the scheduler is stopped.

Implement heartbeat check-ins

Add an Appsignal::CheckIn.heartbeat helper that emits a single heartbeat for the check-in identifier given.

When given continuous: true as the second argument, it spawns a separate thread that emits a heartbeat every thirty seconds. This is a convenience method for the use case where the heartbeat is only meant as a check that the process is alive.

Split functions that deal with different event kinds out of the scheduler and test them independently.

backlog-helper[bot] commented 2 months ago

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] commented 2 months ago

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] commented 2 months ago

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] commented 2 months ago

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] commented 2 months ago

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] commented 1 month ago

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] commented 1 month ago

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] commented 1 month ago

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] commented 1 month ago

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback