Added k8s health checks and metrics scraping
This commit is contained in:
parent
e4247cd0bd
commit
a3f7942d0d
|
@ -7,6 +7,7 @@ use FastRoute\RouteCollector;
|
||||||
// Pages
|
// Pages
|
||||||
$route->get('/', 'HomeController@index');
|
$route->get('/', 'HomeController@index');
|
||||||
$route->get('/credits', 'CreditsController@index');
|
$route->get('/credits', 'CreditsController@index');
|
||||||
|
$route->get('/health', 'HealthController@index');
|
||||||
|
|
||||||
// Authentication
|
// Authentication
|
||||||
$route->get('/login', 'AuthController@login');
|
$route->get('/login', 'AuthController@login');
|
||||||
|
|
|
@ -150,6 +150,10 @@ spec:
|
||||||
env:
|
env:
|
||||||
- name: PHP_FPM_HOST
|
- name: PHP_FPM_HOST
|
||||||
value: localhost
|
value: localhost
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 80
|
||||||
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
|
@ -160,6 +164,9 @@ metadata:
|
||||||
app: <CI_PROJECT_PATH_SLUG>
|
app: <CI_PROJECT_PATH_SLUG>
|
||||||
environment: <CI_ENVIRONMENT_SLUG>
|
environment: <CI_ENVIRONMENT_SLUG>
|
||||||
commit: <CI_COMMIT_SHORT_SHA>
|
commit: <CI_COMMIT_SHORT_SHA>
|
||||||
|
annotations:
|
||||||
|
prometheus.io/port: '80'
|
||||||
|
prometheus.io/scrape: 'true'
|
||||||
spec:
|
spec:
|
||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
ports:
|
ports:
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Controllers;
|
||||||
|
|
||||||
|
use Engelsystem\Http\Response;
|
||||||
|
|
||||||
|
class HealthController extends BaseController
|
||||||
|
{
|
||||||
|
/** @var Response */
|
||||||
|
protected $response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Response $response
|
||||||
|
*/
|
||||||
|
public function __construct(Response $response)
|
||||||
|
{
|
||||||
|
$this->response = $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function index(): Response
|
||||||
|
{
|
||||||
|
return $this->response->withContent('Ok');
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ class SessionHandlerServiceProvider extends ServiceProvider
|
||||||
return [
|
return [
|
||||||
'/api',
|
'/api',
|
||||||
'/atom',
|
'/atom',
|
||||||
|
'/health',
|
||||||
'/ical',
|
'/ical',
|
||||||
'/metrics',
|
'/metrics',
|
||||||
'/shifts-json-export',
|
'/shifts-json-export',
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Test\Unit\Controllers;
|
||||||
|
|
||||||
|
use Engelsystem\Controllers\HealthController;
|
||||||
|
use Engelsystem\Http\Response;
|
||||||
|
use Engelsystem\Test\Unit\TestCase;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
|
class HealthControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Controllers\HealthController::__construct
|
||||||
|
* @covers \Engelsystem\Controllers\HealthController::index
|
||||||
|
*/
|
||||||
|
public function testIndex()
|
||||||
|
{
|
||||||
|
/** @var Response|MockObject $response */
|
||||||
|
$response = $this->createMock(Response::class);
|
||||||
|
$this->setExpects($response, 'withContent', ['Ok'], $response);
|
||||||
|
|
||||||
|
$controller = new HealthController($response);
|
||||||
|
$controller->index();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue