|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
/** |
|
4
|
|
|
* /src/Controller/HealthzController.php |
|
5
|
|
|
* |
|
6
|
|
|
* @author TLe, Tarmo Leppänen <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace App\Controller; |
|
10
|
|
|
|
|
11
|
|
|
use App\Rest\ResponseHandler; |
|
|
|
|
|
|
12
|
|
|
use App\Utils\HealthzService; |
|
13
|
|
|
use Swagger\Annotations as SWG; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
16
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
17
|
|
|
use Throwable; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class HealthzController |
|
21
|
|
|
* |
|
22
|
|
|
* @package App\Controller |
|
23
|
|
|
* @author TLe, Tarmo Leppänen <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class HealthzController |
|
26
|
|
|
{ |
|
27
|
|
|
private ResponseHandler $responseHandler; |
|
28
|
|
|
private HealthzService $healthzService; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* HealthzController constructor. |
|
32
|
|
|
*/ |
|
33
|
2 |
|
public function __construct(ResponseHandler $responseHandler, HealthzService $healthzService) |
|
34
|
|
|
{ |
|
35
|
2 |
|
$this->responseHandler = $responseHandler; |
|
36
|
2 |
|
$this->healthzService = $healthzService; |
|
37
|
2 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Route for application health check. This action will make some simple |
|
41
|
|
|
* tasks to ensure that application is up and running like expected. |
|
42
|
|
|
* |
|
43
|
|
|
* @see https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/ |
|
44
|
|
|
* |
|
45
|
|
|
* @Route( |
|
46
|
|
|
* path="/healthz", |
|
47
|
|
|
* methods={"GET"} |
|
48
|
|
|
* ) |
|
49
|
|
|
* |
|
50
|
|
|
* @SWG\Response( |
|
51
|
|
|
* response=200, |
|
52
|
|
|
* description="success", |
|
53
|
|
|
* @SWG\Schema( |
|
54
|
|
|
* type="object", |
|
55
|
|
|
* example={"timestamp": "2018-01-01T13:08:05+00:00"}, |
|
56
|
|
|
* @SWG\Property(property="timestamp", type="string"), |
|
57
|
|
|
* ), |
|
58
|
|
|
* ) |
|
59
|
|
|
* |
|
60
|
|
|
* @throws Throwable |
|
61
|
|
|
*/ |
|
62
|
2 |
|
public function __invoke(Request $request): Response |
|
63
|
|
|
{ |
|
64
|
2 |
|
return $this->responseHandler->createResponse( |
|
65
|
2 |
|
$request, |
|
66
|
2 |
|
$this->healthzService->check(), |
|
67
|
2 |
|
null, |
|
68
|
2 |
|
200, |
|
69
|
2 |
|
ResponseHandler::FORMAT_JSON, |
|
70
|
|
|
[ |
|
71
|
|
|
'groups' => [ |
|
72
|
2 |
|
'Healthz.timestamp', |
|
73
|
|
|
], |
|
74
|
|
|
] |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths