Repository navigation
Return 503 from an unhealthy health check - #370
Merged
Merged
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #319.
An unhealthy health check now answers 503 Service Unavailable instead of 500, on FastAPI, Litestar, FastMCP and FastStream. The route is unhealthy when a probe returns
Falseor raises, and on FastStream also when a broker ping fails. The JSON body is unchanged.A 500 says the handler failed. A 503 says the service can't serve right now, so alerting can tell a dependency the probe found down apart from a crashing handler. Both are 5xx, so a rule on all 5xx still fires. Kubernetes treats any status from 200 to 399 as success, so probes behave the same as before.
Changes
HTTP_503_SERVICE_UNAVAILABLEfromfastapi.status,litestar.status_codesandstarlette.status. FastStream's literal changes from 500 to 503.configuration.mdgives the new status.Tests
Written first, as the issue lists. The two failing cases in
HEALTH_PROBE_CASESand the three FastStream assertions now expect 503. On main, 11 cases failed across all four frameworks:one-returns-falseandone-raisescases of each framework'stest_*_health_check_runs_probestest_faststream_bootstrap_health_check_wo_brokertest_faststream_health_check_fails_when_second_broker_is_downtest_faststream_health_check_fails_on_broker_ping_despite_passing_probeThe full suite passes, 557 tests at 100% coverage (
just test-ci).just lint(includingty),just adr-checkandjust docs-buildpass too. No floor changes.Breaking changes
Monitoring or load-balancer rules that match a 500 from the health route stop matching. Match 503, or any 5xx.