Added k8s health checks and metrics scraping

This commit is contained in:
Igor Scheller 2020-09-01 00:27:29 +02:00 committed by msquare
parent e4247cd0bd
commit a3f7942d0d
5 changed files with 61 additions and 0 deletions

View File

@ -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');

View File

@ -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:

View File

@ -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');
}
}

View File

@ -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',

View File

@ -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();
}
}