Added k8s health checks and metrics scraping
This commit is contained in:
parent
e4247cd0bd
commit
a3f7942d0d
|
@ -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');
|
||||
|
|
|
@ -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: <CI_PROJECT_PATH_SLUG>
|
||||
environment: <CI_ENVIRONMENT_SLUG>
|
||||
commit: <CI_COMMIT_SHORT_SHA>
|
||||
annotations:
|
||||
prometheus.io/port: '80'
|
||||
prometheus.io/scrape: 'true'
|
||||
spec:
|
||||
type: ClusterIP
|
||||
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 [
|
||||
'/api',
|
||||
'/atom',
|
||||
'/health',
|
||||
'/ical',
|
||||
'/metrics',
|
||||
'/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