views: Add a /health healthcheck endpoint.

This endpoint verifies that the services that Zulip needs to function
are running, and Django can talk to them.  It is designed to be used
as a readiness probe[^1] for Zulip, either by Kubernetes, or some other
reverse-proxy load-balancer in front of Zulip.  Because of this, it
limits access to only localhost and the IP addresses of configured
reverse proxies.

Tests are limited because we cannot stop running services (which would
impact other concurrent tests) and there would be extremely limited
utility to mocking the very specific methods we're calling to raising
the exceptions that we're looking for.

[^1]: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
This commit is contained in:
Alex Vandiver
2023-09-12 20:34:54 +00:00
committed by Tim Abbott
parent e60a4c4d01
commit 5ee4b642ad
7 changed files with 120 additions and 1 deletions

View File

@@ -42,6 +42,7 @@ class ErrorCode(Enum):
MOVE_MESSAGES_TIME_LIMIT_EXCEEDED = auto()
REACTION_ALREADY_EXISTS = auto()
REACTION_DOES_NOT_EXIST = auto()
SERVER_NOT_READY = auto()
class JsonableError(Exception):
@@ -533,3 +534,8 @@ class ApiParamValidationError(JsonableError):
def __init__(self, msg: str, error_type: str) -> None:
super().__init__(msg)
self.error_type = error_type
class ServerNotReadyError(JsonableError):
code = ErrorCode.SERVER_NOT_READY
http_status_code = 500