View Source KubeProbex.Check.EctoReady (Kube Probex v1.0.1)
Provides the default implementation for KubeProbex.Check.Readiness behaviour using Ecto.
This module defines a readiness probe handler that ensures database health by performing the following checks:
- Pending Migrations: Checks if there are any pending migrations for the configured repositories.
- Database Storage: If there are no migrations defined, verifies if the database storage is properly created.
If any of these checks fail, the module raises appropriate exceptions to indicate the issue:
KubeProbex.Exceptions.Ecto.PendingMigrationsErroris raised if there are pending migrations.KubeProbex.Exceptions.Ecto.DatabaseNotCreatedErroris raised if the database is not created.
When all checks pass, the module returns an HTTP response with the following attributes:
- Status:
200 - Content-Type:
application/json - Body:
{"status": "ready"}
This indicates that the application is ready to serve traffic.
Usage
Ensure your application specifies the required :ecto_repos configuration.
Example
config :my_app, :ecto_repos, [MyApp.Repo]Options
:otp_apps- A list of OTP applications whose Ecto repositories should be checked. Each application must define its Ecto repositories under the:ecto_reposconfiguration key. This option should be passed when setting theKubeProbex.Plug.Readinessplug.
Exemple
defmodule MyAppWeb.Router do
use Phoenix.Endpoint, otp_app: :my_app_web
plug KubeProbex.Plug.Readiness, path: ~w(/_ready /_readyz), otp_apps: [:my_app]
end