Skip to content

Commit 68f2213

Browse files
authored
Merge branch 'main' into add-installation
2 parents 62f51d5 + ff7ceb5 commit 68f2213

17 files changed

Lines changed: 413 additions & 105 deletions

.github/workflows/code_coverage.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
php-version: 8.2
1414
coverage: pcov
1515

16+
# Implicitly runs `composer tests` in post update cmd. So PHPCS, MD and other static analysis is executed at
17+
# this point.
1618
- run: composer install --no-progress
1719

1820
- run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Code_Checks](https://github.com/OpenConext/Monitor-bundle/actions/workflows/code_checks.yaml/badge.svg)](https://github.com/OpenConext/Monitor-bundle/actions/workflows/code_checks.yaml)
44

5-
A Symfony 5/6/7 bundle that adds a /health and /info endpoint to your application.
5+
A Symfony 5/6/7 bundle that adds an /internal/health and /internal/info endpoint to your application.
66

77
The endpoints return JSON responses. The `/internal/info` endpoint tries to give as much information about the currently installed
88
version of the application as possible. This information is based on the build path of the installation. But also
@@ -55,11 +55,11 @@ When a health check failed the HTTP Response status code will be 503. And the JS
5555
security:
5656
firewalls:
5757
monitor:
58-
pattern: ^/(info|health)$
58+
pattern: ^/internal/(info|health)$
5959
security: false
6060
6161
```
62-
* The /info and /health endpoints should now be available for everybody. Applying custom access restriction is up to
62+
* The /internal/info and /internal/health endpoints should now be available for everybody. Applying custom access restriction is up to
6363
the implementer of this bundle.
6464
6565
## Adding Health Checks

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"require-dev": {
1717
"php-parallel-lint/php-parallel-lint": "^1.3",
18-
"phpmd/phpmd": "^2.6",
18+
"phpmd/phpmd": "^2.13",
1919
"matthiasnoback/symfony-config-test": "^4.3",
2020
"phpdocumentor/reflection-docblock": "^5.2",
2121
"phpunit/php-token-stream": "^3.1.3|^4.0.4",
@@ -38,11 +38,11 @@
3838
"scripts": {
3939
"tests": {
4040
"docheader": "vendor/bin/docheader check src/",
41-
"phpcmd": "vendor/bin/phpmd src text phpmd.xml",
4241
"phpcs": "vendor/bin/phpcs src --report=full --standard=phpcs.xml --extensions=php --warning-severity=0",
4342
"phpcpd": "vendor/bin/phpcpd src --exclude=src/Tests/*",
44-
"phpunit": "vendor/bin/phpunit --coverage-text"
45-
},
43+
"phpunit": "vendor/bin/phpunit --coverage-text",
44+
"phpmd": "vendor/bin/phpmd src text phpmd.xml --exclude 'src/Tests/*'"
45+
},
4646
"post-update-cmd": [
4747
"@tests"
4848
]

phpmd.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
<rule ref="rulesets/naming.xml">
3131
<exclude name="ShortVariable" />
3232
<exclude name="LongVariable" />
33+
<exclude name="LongClassName" />
34+
<exclude name="ShortClassName" />
3335
</rule>
3436

3537
</ruleset>

src/Controller/HealthController.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,9 @@
3030
*/
3131
class HealthController extends AbstractController
3232
{
33-
/**
34-
* @var HealthCheckChain
35-
*/
36-
private $healthChecker;
37-
38-
public function __construct(HealthCheckChain $healthChecker)
39-
{
40-
$this->healthChecker = $healthChecker;
33+
public function __construct(
34+
private readonly HealthCheckChain $healthChecker
35+
) {
4136
}
4237

4338
public function __invoke(): JsonResponse

src/Controller/InfoController.php

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
namespace OpenConext\MonitorBundle\Controller;
2020

21+
use OpenConext\MonitorBundle\Value\BuildInformationFactory;
2122
use OpenConext\MonitorBundle\Value\BuildPathFactory;
2223
use OpenConext\MonitorBundle\Value\Information;
2324
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -41,34 +42,16 @@
4142
*/
4243
class InfoController extends AbstractController
4344
{
44-
/**
45-
* @var string
46-
*/
47-
private $buildPath;
48-
49-
/**
50-
* @var string
51-
*/
52-
private $environment;
53-
54-
/**
55-
* @var bool
56-
*/
57-
private $debuggerEnabled;
58-
59-
/**
60-
* @var array
61-
*/
62-
private $systemInfo = [];
45+
private array $systemInfo = [];
6346

6447
public function __construct(
65-
$buildPath,
66-
$environment,
67-
$debuggerEnabled
48+
private readonly string $buildPath,
49+
private readonly string $environment,
50+
private readonly bool $debuggerEnabled,
51+
private readonly ?string $version,
52+
private readonly ?string $revision,
53+
private readonly ?string $commitDate,
6854
) {
69-
$this->buildPath = $buildPath;
70-
$this->environment = $environment;
71-
$this->debuggerEnabled = $debuggerEnabled;
7255

7356
if (function_exists('opcache_get_status')) {
7457
$this->systemInfo['opcache'] = opcache_get_status(false);
@@ -77,8 +60,14 @@ public function __construct(
7760

7861
public function __invoke(): JsonResponse
7962
{
63+
$buildInformation = BuildInformationFactory::build(
64+
$this->version,
65+
$this->revision,
66+
$this->commitDate,
67+
$this->buildPath
68+
);
8069
$info = Information::buildFrom(
81-
BuildPathFactory::buildFrom($this->buildPath),
70+
$buildInformation,
8271
$this->environment,
8372
$this->debuggerEnabled,
8473
$this->systemInfo

src/DependencyInjection/Compiler/HealthCheckPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class HealthCheckPass implements CompilerPassInterface
3030
/**
3131
* @SuppressWarnings(PHPMD.UnusedLocalVariable) $tags is never used in the foreach
3232
*/
33-
public function process(ContainerBuilder $container)
33+
public function process(ContainerBuilder $container): void
3434
{
3535
if (!$container->has('openconext.monitor.health_check_chain')) {
3636
return;
3737
}
3838

3939
$definition = $container->findDefinition('openconext.monitor.health_check_chain');
4040

41-
// find all service IDs with the app.mail_transport tag
41+
// find all service IDs with the openconext.monitor.health_check tag
4242
$taggedServices = $container->findTaggedServiceIds('openconext.monitor.health_check');
4343

4444
foreach ($taggedServices as $id => $tags) {

src/DependencyInjection/OpenConextMonitorExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class OpenConextMonitorExtension extends Extension
3434
/**
3535
* @throws \Exception
3636
*/
37-
public function load(array $configs, ContainerBuilder $container)
37+
public function load(array $configs, ContainerBuilder $container): void
3838
{
3939
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
4040
$loader->load('services.yml');

src/Resources/config/services.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ services:
55
- '~'
66
- '%kernel.environment%'
77
- '%kernel.debug%'
8-
public: true
8+
- '%env(default::string:OPENCONEXT_APP_VERSION)%'
9+
- '%env(default::string:OPENCONEXT_GIT_SHA)%'
10+
- '%env(default::string:OPENCONEXT_COMMIT_DATE)%'
11+
912
autowire: true
1013
tags: ['controller.service_arguments', 'container.service_subscriber']
1114

1215
openconext.monitor.controller.health:
1316
class: OpenConext\MonitorBundle\Controller\HealthController
1417
arguments:
1518
- '@openconext.monitor.health_check_chain'
16-
public: true
1719
autowire: true
1820
tags: ['controller.service_arguments', 'container.service_subscriber']
1921

@@ -30,4 +32,4 @@ services:
3032
calls:
3133
- [ setEntityManager, ['@?doctrine.orm.entity_manager']]
3234
tags:
33-
- { name: openconext.monitor.health_check }
35+
- { name: openconext.monitor.health_check }
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2024 SURFnet B.V.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
namespace OpenConext\MonitorBundle\Tests\Value;
20+
21+
use OpenConext\MonitorBundle\Value\BuildEnvVars;
22+
use OpenConext\MonitorBundle\Value\BuildInformationFactory;
23+
use OpenConext\MonitorBundle\Value\BuildPath;
24+
use PHPUnit\Framework\TestCase;
25+
26+
class BuildInformationFactoryTest extends TestCase
27+
{
28+
public function test_builds_based_on_env_vars()
29+
{
30+
$buildInformation = BuildInformationFactory::build(
31+
'1.0.0',
32+
'e97bbfc39653cb5541d453e704c64a7fab4f5b1',
33+
'1900-01-01',
34+
'My-Application-da39a3ee5e6b4b0d3255bfef95601890afd80709'
35+
);
36+
$this->assertInstanceOf(BuildEnvVars::class, $buildInformation);
37+
}
38+
public function test_builds_based_on_env_vars_commit_date_optional()
39+
{
40+
$buildInformation = BuildInformationFactory::build(
41+
'1.0.0',
42+
'e97bbfc39653cb5541d453e704c64a7fab4f5b1',
43+
null,
44+
'My-Application-da39a3ee5e6b4b0d3255bfef95601890afd80709'
45+
);
46+
$this->assertInstanceOf(BuildEnvVars::class, $buildInformation);
47+
}
48+
public function test_builds_on_path()
49+
{
50+
$buildInformation = BuildInformationFactory::build(
51+
null,
52+
null,
53+
null,
54+
'My-Application-da39a3ee5e6b4b0d3255bfef95601890afd80709'
55+
);
56+
$this->assertInstanceOf(BuildPath::class, $buildInformation);
57+
}
58+
}

0 commit comments

Comments
 (0)