Code Monkey home page Code Monkey logo

symfony-health-check-bundle's Introduction

Symfony Health Check Bundle

Version Build Status Code Coverage
master CI Coverage Status
develop CI Coverage Status

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute:

composer require macpaw/symfony-health-check-bundle

Applications that don't use Symfony Flex

enable the bundle by adding it to the list of registered bundles in config/bundles.php

// config/bundles.php
<?php

return [
            SymfonyHealthCheckBundle\SymfonyHealthCheckBundle::class => ['all' => true],

        // ...
    ];

Create Symfony Health Check Bundle Config:

Configurating health check - all available you can see here.

# config/packages/symfony_health_check.yaml`
symfony_health_check:
    health_checks:
        - id: symfony_health_check.doctrine_check
    ping_checks:
        - id: symfony_health_check.status_up_check

Change response code:

  • default response code is 200.
  • determine your custom response code in case of some check fails (Response code must be a valid HTTP status code)
symfony_health_check:
    health_checks:
        - id: symfony_health_check.doctrine_check
    ping_checks:
        - id: symfony_health_check.status_up_check
    ping_error_response_code: 500
    health_error_response_code: 404

Create Symfony Health Check Bundle Routing Config:

config/routes/symfony_health_check.yaml

health_check:
    resource: '@SymfonyHealthCheckBundle/Resources/config/routes.xml'

Step 3: Configuration

Security Optional:

If you are using symfony/security and your health check is to be used anonymously, add a new firewall to the configuration

# config/packages/security.yaml
    firewalls:
        healthcheck:
            pattern: ^/health
            security: false
        ping:
            pattern: ^/ping
            security: false

Step 4: Additional settings

Add Custom Check:

It is possible to add your custom health check:

<?php

declare(strict_types=1);

namespace YourProject\Check;

use SymfonyHealthCheckBundle\Dto\Response;

class CustomCheck implements CheckInterface
{
    public function check(): Response
    {
        return new Response('status', true, 'up');
    }
}

Then we add our custom health check to collection

symfony_health_check:
    health_checks:
        - id: symfony_health_check.doctrine_check
        - id: custom_health_check // custom service check id

How Change Route:

You can change the default behavior with a light configuration, remember to modify the routes.

# config/routes/symfony_health_check.yaml
health:
    path: /your/custom/url
    methods: GET
    controller: SymfonyHealthCheckBundle\Controller\HealthController::check
    
ping:
    path: /your/custom/url
    methods: GET
    controller: SymfonyHealthCheckBundle\Controller\PingController::check

How To Use Healthcheck In Docker

HEALTHCHECK --start-period=15s --interval=5s --timeout=3s --retries=3 CMD curl -sS {{your host}}/health || exit 1

symfony-health-check-bundle's People

Contributors

dependabot[bot] avatar iiiigorgg avatar lol768 avatar oparshyna avatar semantic-release-bot avatar tacman avatar yozhef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

symfony-health-check-bundle's Issues

Deprecation message autowiring alias ContainerInterface

Using Symfony 5.3 the profiler shows the following deprecation message:

Since symfony/dependency-injection 5.1: The "Symfony\Component\DependencyInjection\ContainerInterface" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it. It is being referenced by the "symfony_health_check.doctrine_check" service.
Show context    Hide trace
{▼
  /app/vendor/symfony/dependency-injection/Compiler/ResolveReferencesToAliasesPass.php:68 {▼
    Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass->getDefinitionId(string $id, ContainerBuilder $container): string …
    ›     $deprecation = $alias->getDeprecation($id);
    ›     trigger_deprecation($deprecation['package'], $deprecation['version'], rtrim($deprecation['message'], '. ').'. It is being referenced by the "%s" '.($container->hasDefinition($this->currentId) ? 'service.' : 'alias.'), $this->currentId);
    › }
  }
  /app/vendor/symfony/dependency-injection/Compiler/ResolveReferencesToAliasesPass.php:51 {▼
    › 
    › $defId = $this->getDefinitionId($id = (string) $value, $this->container);
    › 
  }
}

Exclude successful responses from logs

Is there any way to remove successful requests from the logs? My log files are flooded with requests (level:200/channel:request) in among all normal routing requests (which I want to retain), I can get around the log analysis by using filters but the log files are huge and it seems counterintuitive to have them both. Any advice would be most welcome.

Release 1.03 is considered higher than 1.1.0

Describe the bug
When installing the package via Composer, the latest version downloaded is 1.03, being considered newer than 1.1.0. I believe this is because version 1.03 is considered "1.3", and thus newer than 1.1.0.

To Reproduce
a. Install the bundle via Symfony Flex
b. Install the package directly
c. Check on packagist that 1.03 is sorted as newer than 1.1.0

Expected behaviour
Version 1.1.0 is installed

Screenshots
image

image

Proposed solution
Republish the latest release as 1.4, which would be newer than 1.03. Since the changes in 1.1.0 are not breaking, updating the minor version would no harm, while ensure both users of 1.03and 1.1.0 know of the update.

Deprecated message autowiring alias ContainerInterface

Using Symfony 5.3 the profiler shows the following deprecation message:

Since symfony/dependency-injection 5.1: The "Symfony\Component\DependencyInjection\ContainerInterface" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it. It is being referenced by the "symfony_health_check.doctrine_check" service.
Show context    Hide trace
{▼
  /app/vendor/symfony/dependency-injection/Compiler/ResolveReferencesToAliasesPass.php:68 {▼
    Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass->getDefinitionId(string $id, ContainerBuilder $container): string …
    ›     $deprecation = $alias->getDeprecation($id);
    ›     trigger_deprecation($deprecation['package'], $deprecation['version'], rtrim($deprecation['message'], '. ').'. It is being referenced by the "%s" '.($container->hasDefinition($this->currentId) ? 'service.' : 'alias.'), $this->currentId);
    › }
  }
  /app/vendor/symfony/dependency-injection/Compiler/ResolveReferencesToAliasesPass.php:51 {▼
    › 
    › $defId = $this->getDefinitionId($id = (string) $value, $this->container);
    › 
  }
}

Multiple routes with different check

Hi!

Is it possible to have multiple routes configured to have different checks in different routes?
Use case is kubernetes liveness and readiness probes:

  • liveness probe is the one we would like to have running pretty often (each 10 sec) and having doctrine check in it is too much.
  • but readiness probe can be done using longer interval (once per minute) and include doctrine check to make sure everything is setup correctly

Thanks!

Custom health checks don't seem to work

Always fails with "You have requested a non-existent service" despite the service having been registered in services.yaml and visible with php bin/console debug:container

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.