alexliesenfeld / health

A simple and flexible health check library for Go.
MIT License
775 stars 38 forks source link

Fix startup `MaxContiguousFails` and add contiguous success Check options #31

Closed jscaltreto closed 1 year ago

jscaltreto commented 2 years ago

Currently, when Check.MaxContiguousFails is set to n the first n-1 checks will return StatusUp even if it and all prior checks were a failure. This is because evaluateCheckStatus only returns StatusDown if the number of consecutive failures is >= MaxContigiousFails. The result is that on startup the status may be reported as Up when it has never actually had a successful check. The fix for this is to also return StatusDown if there were no previous successes (check that LastSuccessAt is not nil).

Additionally, this implements Check.MinContiguousSuccesses and Check.MinTimeInSuccess which function as the inverse of Check.MaxContiguousFails and Check.MaxTimeInError, respectively.

If either threshold is not satisfied then the most recent check.Status is returned; this is so that on startup StatusUnknown will continue to be returned until the threshold(s) are reached to avoid returning a misleading StatusDown.

alexliesenfeld commented 1 year ago

Nice! Thanks for submitting this PR! I'll have a look into it.

alexliesenfeld commented 1 year ago

Perfect! Thank you for your PR. It will go into the development branch, that will be released soon.

codecov[bot] commented 1 year ago

Codecov Report

Base: 91.95% // Head: 91.95% // No change to project coverage :thumbsup:

Coverage data is based on head (492443b) compared to base (dee726b). Patch has no changes to coverable lines.

:exclamation: Current head 492443b differs from pull request most recent head ce1d978. Consider uploading reports for the commit ce1d978 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## development #31 +/- ## ============================================ Coverage 91.95% 91.95% ============================================ Files 3 3 Lines 286 286 ============================================ Hits 263 263 Misses 15 15 Partials 8 8 ``` | Flag | Coverage Δ | | |---|---|---| | unittests | `91.95% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alexander+Liesenfeld#carryforward-flags-in-the-pull-request-comment) to find out more. Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alexander+Liesenfeld). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alexander+Liesenfeld)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.