Skip to content

Commit

Permalink
fix: typo in healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
cyve authored and cdaguerre committed Apr 23, 2024
1 parent 7b981c8 commit 6c046fd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
6 changes: 3 additions & 3 deletions docs/health/adding-a-healthcheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
```php
namespace App\Health;

use Instrumentation\Health\HealtcheckInterface;
use Instrumentation\Health\HealthcheckInterface;
use Symfony\Component\HttpFoundation\RequestStack;

class DummyHealthcheck implements HealtcheckInterface
class DummyHealthcheck implements HealthcheckInterface
{
public function __construct(private RequestStack $requestStack)
{
Expand All @@ -28,7 +28,7 @@ class DummyHealthcheck implements HealtcheckInterface
return $header;
}

return HealtcheckInterface::HEALTHY;
return HealthcheckInterface::HEALTHY;
}

public function getStatusMessage(): ?string
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#### Health
- A simple endpoint to expose application health (default: `/_healthz`)
- Autoconfigurable healthcheck interface to add healtchecks to be made for global application health
- Autoconfigurable healthcheck interface to add healthchecks to be made for global application health

### Installation and configuration

Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Instrumentation\DependencyInjection;

use Instrumentation\Health\HealtcheckInterface;
use Instrumentation\Health\HealthcheckInterface;
use Instrumentation\Metrics\MetricProviderInterface;
use Instrumentation\Metrics\RegistryInterface;
use Instrumentation\Metrics\Storage\HostnamePrefixedRedisFactory;
Expand Down Expand Up @@ -197,9 +197,9 @@ protected function loadHealth(array $config, ContainerBuilder $container): void
$loader->load('health.php');

$this->addPathToBlacklist($config['path'], $container);
$container->setParameter('app.path.healtcheck', $config['path']);
$container->setParameter('app.path.healthcheck', $config['path']);

$container->registerForAutoconfiguration(HealtcheckInterface::class)->addTag('app.healthcheck');
$container->registerForAutoconfiguration(HealthcheckInterface::class)->addTag('app.healthcheck');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/routes/health.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return function (RoutingConfigurator $routes) {
$routes->add('_healthz', '%app.path.healtcheck%')
$routes->add('_healthz', '%app.path.healthcheck%')
->controller(Endpoint::class)
->methods(['GET']);
};
14 changes: 7 additions & 7 deletions src/Health/Controller/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Instrumentation\Health\Controller;

use Instrumentation\Health\HealtcheckInterface;
use Instrumentation\Health\HealthcheckInterface;
use Instrumentation\Metrics\MetricProviderInterface;
use Instrumentation\Metrics\RegistryInterface;
use OpenTelemetry\SDK\Resource\ResourceInfo;
Expand All @@ -29,7 +29,7 @@ public static function getProvidedMetrics(): array
}

/**
* @param iterable<HealtcheckInterface> $checks
* @param iterable<HealthcheckInterface> $checks
*/
public function __construct(private ResourceInfo $resourceInfo, private iterable $checks, private RegistryInterface|null $registry = null, private Profiler|null $profiler = null)
{
Expand All @@ -47,7 +47,7 @@ public function __invoke(): JsonResponse
$hasDegraded = false;

foreach ($this->checks as $check) {
if (HealtcheckInterface::HEALTHY != $check->getStatus()) {
if (HealthcheckInterface::HEALTHY != $check->getStatus()) {
$hasDegraded = true;
if ($check->isCritical()) {
$hasDegradedCritical = true;
Expand All @@ -63,14 +63,14 @@ public function __invoke(): JsonResponse
];
}

$status = HealtcheckInterface::HEALTHY;
$status = HealthcheckInterface::HEALTHY;
$statusInt = 2;
if ($hasDegraded) {
$status = HealtcheckInterface::DEGRADED;
$status = HealthcheckInterface::DEGRADED;
$statusInt = 1;
}
if ($hasDegradedCritical) {
$status = HealtcheckInterface::UNHEALTHY;
$status = HealthcheckInterface::UNHEALTHY;
$statusInt = 0;
}

Expand All @@ -80,6 +80,6 @@ public function __invoke(): JsonResponse
$this->registry->getGauge('app_health')->set($statusInt);
}

return new JsonResponse($results, HealtcheckInterface::UNHEALTHY === $status ? 500 : 200);
return new JsonResponse($results, HealthcheckInterface::UNHEALTHY === $status ? 500 : 200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@

namespace Instrumentation\Health;

interface HealtcheckInterface
/**
* @deprecated
*/
interface HealtcheckInterface extends HealthcheckInterface
{
}

interface HealthcheckInterface
{
public const HEALTHY = 'healthy';
public const DEGRADED = 'degraded';
Expand All @@ -27,7 +34,7 @@ public function getDescription(): string|null;
public function getStatusMessage(): string|null;

/**
* @return string One of the HealtcheckInterface constants
* @return string One of the HealthcheckInterface constants
*/
public function getStatus(): string;

Expand Down

0 comments on commit 6c046fd

Please sign in to comment.