diff --git a/config/routes.php b/config/routes.php index c46b1b95..b277751d 100644 --- a/config/routes.php +++ b/config/routes.php @@ -7,6 +7,7 @@ use FastRoute\RouteCollector; // Pages $route->get('/', 'HomeController@index'); $route->get('/credits', 'CreditsController@index'); +$route->get('/health', 'HealthController@index'); // Authentication $route->get('/login', 'AuthController@login'); diff --git a/deployment.tpl.yaml b/deployment.tpl.yaml index 5b2377b7..05bc07c2 100644 --- a/deployment.tpl.yaml +++ b/deployment.tpl.yaml @@ -150,6 +150,10 @@ spec: env: - name: PHP_FPM_HOST value: localhost + livenessProbe: + httpGet: + path: /health + port: 80 --- apiVersion: v1 @@ -160,6 +164,9 @@ metadata: app: environment: commit: + annotations: + prometheus.io/port: '80' + prometheus.io/scrape: 'true' spec: type: ClusterIP ports: diff --git a/src/Controllers/HealthController.php b/src/Controllers/HealthController.php new file mode 100644 index 00000000..1ffccdbf --- /dev/null +++ b/src/Controllers/HealthController.php @@ -0,0 +1,27 @@ +response = $response; + } + + /** + * @return Response + */ + public function index(): Response + { + return $this->response->withContent('Ok'); + } +} diff --git a/src/Middleware/SessionHandlerServiceProvider.php b/src/Middleware/SessionHandlerServiceProvider.php index 7bffb059..e389ec30 100644 --- a/src/Middleware/SessionHandlerServiceProvider.php +++ b/src/Middleware/SessionHandlerServiceProvider.php @@ -15,6 +15,7 @@ class SessionHandlerServiceProvider extends ServiceProvider return [ '/api', '/atom', + '/health', '/ical', '/metrics', '/shifts-json-export', diff --git a/tests/Unit/Controllers/HealthControllerTest.php b/tests/Unit/Controllers/HealthControllerTest.php new file mode 100644 index 00000000..a3788b48 --- /dev/null +++ b/tests/Unit/Controllers/HealthControllerTest.php @@ -0,0 +1,25 @@ +createMock(Response::class); + $this->setExpects($response, 'withContent', ['Ok'], $response); + + $controller = new HealthController($response); + $controller->index(); + } +}