Persist check state for TTL checks #1009
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TTL checks work on the assumption that there is an external app calling in to Consul to "ping" the check, keeping it healthy. During a Consul restart, the current behavior is to re-register the check directly into a pre-determined state. This can leave the TTL-based checks in an undesirable state for an extended period of time, depending on the TTL.
This change persists the last submitted status into the data directory. The check status, output, and an expiration timestamp are all written to disk, and restored on later agent starts. During startup, if the persisted status is still "fresh" enough (the expiration timer is based on the TTL of the check), the state and output are restored and registered as the initial status of the check.
I think we could do something similar for the other check types, but since Consul has the ability to actively run those checks, we might solve it in a different way.
Fixes #1001