2017 © Pedro Peláez
 

symfony-bundle monitor-bundle

A Symfony 3 bundle that facilitates health and info endpoints to a Symfony application. The bundle is backwards compatible with Symfony 2 projects.

image

openconext/monitor-bundle

A Symfony 3 bundle that facilitates health and info endpoints to a Symfony application. The bundle is backwards compatible with Symfony 2 projects.

  • Monday, December 18, 2017
  • by joostd
  • Repository
  • 10 Watchers
  • 1 Stars
  • 6,179 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 4 Versions
  • 29 % Grown

The README.md

OpenConext Monitor bundle

Code_Checks, (*1)

A Symfony 5/6/7 bundle that adds an /internal/health and /internal/info endpoint to your application., (*2)

The endpoints return JSON responses. The /internal/info endpoint tries to give as much information about the currently installed version of the application as possible. This information is based on the build path of the installation. But also includes the Symfony environment that is currently active and whether the debugger is enabled., (*3)

The /internal/health endpoint reports on the health of the application. This information could be used for example by a load balancer. Example output:, (*4)

{"status":"UP"}

When a health check failed the HTTP Response status code will be 503. And the JSON Response is formatted like this:, (*5)

{"status":"DOWN", "message":"Lorem ipsum dolor sit"}

:exclamation: Please note that only the first failing health check is reported., (*6)

:exclamation: As of version 3.1.0 we started exposing the health and info routes on /internal/. On the next major version we will stop serving the info and health endpoints on /, (*7)

Installation

  • Add the package to your Composer file, (*8)

    composer require openconext/monitor-bundle
    
  • If you don't use Symfony Flex, you must enable the bundle manually in the application:, (*9)

    php // config/bundles.php // in older Symfony apps, enable the bundle in config/bundles.php return [ // ... OpenConext\MonitorBundle\OpenConextMonitorBundle::class => ['all' => true], ];, (*10)

  • Include the routing configuration in config/routes.yaml by adding: yaml open_conext_monitor: resource: "@OpenConextMonitorBundle/src/Controller" type: attribute prefix: / Note: this is currently done by the bundle itself, with an external dependency called https://github.com/endroid/installer, (*11)

  • Add security exceptions in config/packages/security.yaml (if this is required at all), (*12)

    security:
        firewalls:
            monitor:
                pattern: ^/internal/(info|health)$
                security: false
    
    
  • The /internal/info and /internal/health endpoints should now be available for everybody. Applying custom access restriction is up to the implementer of this bundle.

Adding Health Checks

The Monitor ships with two health checks. These checks are a - Database connection check based on Doctrine configuration - Session status check, (*13)

Create the checker

A HealthCheckInterface can be implemented to create your own health check. The example below shows an example of what an implementation of said interface could look like., (*14)

use OpenConext\MonitorBundle\HealthCheck\HealthCheckInterface;
use OpenConext\MonitorBundle\HealthCheck\HealthReportInterface;
use OpenConext\MonitorBundle\Value\HealthReport;

class ApiHealthCheck implements HealthCheckInterface
{
    public function __construct(private readonly MyService $service)
    {
    }

    public function check(HealthReportInterface $report): HealthReportInterface
    {
        if (!$this->service->everythingOk()) {
            // Return a HealthReport with a DOWN status when there are indications the application is not functioning as
            // intended. You can provide an optional message that is displayed alongside the DOWN status.
            return HealthReport::buildStatusDown('Not everything is allright.');
        }
        // By default, return the report that was passed along as a parameter to the check method
        return $report;
    }
}

:exclamation: Please note that the check method receives and returns a HealthReport. The Health report is passed along in the chain of registered health checkers. If everything was OK, just return the report that was passed to the method., (*15)

Register the checker

By implementing the HealthCheckInterface you can register your own health check. This interface is tagged automatically, so you don't have to do it yourself., (*16)

Overriding a default HealthCheck

To run a custom query with the DoctrineConnectionHealthCheck you will need to override it in your own project., (*17)

For example in your ACME bundle that is using the monitor bundle:, (*18)

services.yaml, (*19)

    # Override the service in `/src/config/services.yaml`
    OpenConext\MonitorBundle\HealthCheck\DoctrineConnectionHealthCheck:
        # Point to your own implementation of the check
        class: Acme\GreatSuccessBundle\HealthCheck\DoctrineConnectionHealthCheck

The rest of the service configuration is up to your own needs. You can inject arguments, factory calls and other service features as need be., (*20)

Release strategy

Please read: https://github.com/OpenConext/Stepup-Deploy/wiki/Release-Management for more information on the release strategy used in Stepup projects., (*21)

The Versions

18/12 2017