liip / LiipMonitorBundle

Integrates the LiipMonitor library into Symfony
http://liip.ch
467 stars 103 forks source link

No route found - Using app with autoconfigure:true #274

Closed igordeveloper closed 1 year ago

igordeveloper commented 2 years ago

Hi guys.

I'm using the configuration autoconfigure:true in my app, and the 'liip_monitor.check''check is being tagged automatically. When I' run the Health check page the check works fine, but, when i try repeat a individual custom check in the button GO the app receives the error below with route not found.

No route found for "POST http://localhost:8000/monitor/health/run/App/Diagnostics/Check/CustomCheck" (from "http://localhost:8000/monitor/health/")

My configurations:

config/services.yaml

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
config/packages/monitor.yaml

liip_monitor:
    default_group: default
    enable_controller: true
config/routes/monitor.yaml
_monitor:
    resource: "@LiipMonitorBundle/Resources/config/routing.xml"
    prefix: /monitor/health

Custom check class

<?php

declare(strict_types=1);

namespace App\Diagnostics\Check;

use Laminas\Diagnostics\Check\CheckInterface;
use Laminas\Diagnostics\Result\Failure;
use Laminas\Diagnostics\Result\Success;

class CustomCheck implements CheckInterface
{
igordeveloper commented 2 years ago

Could you please help me if i'm missing some configuration?

Thank you.

kbond commented 2 years ago

Hi @igordeveloper, sorry for the delay - I've been on vacation.

Yes, you'll need to add an alias as it's trying to match the route on the class name.

igordeveloper commented 2 years ago

Hi @igordeveloper, sorry for the delay - I've been on vacation.

Yes, you'll need to add an alias as it's trying to match the route on the class name.

Hi @kbond , no worries.

I add a alias as below, and now i have 2 entries 'Custom check' http://localhost:8000/monitor/health

    monitor.check.custom:
        class: App\Diagnostics\Check\CustomCheck
        arguments:
            - [ xhprof, apc, memcache ]
        tags:
            - { name: liip_monitor.check, alias: custom}

One of them gives an error because the route is created with 'monitor.check.mercure' and the another works.

Is there any other way to fix this, besides inserting autoconfigure: false for this service? Because my app's _defaults is set to true.

Thank you again!

kbond commented 2 years ago

Is there any other way to fix this, besides inserting autoconfigure: false for this service

I don't think so. Some work needs to be done with how checks are auto-configured.

igordeveloper commented 2 years ago

Is there any other way to fix this, besides inserting autoconfigure: false for this service

I don't think so. Some work needs to be done with how checks are auto-configured.

Sorry, needs to be done in my configuration or bundle side?

kbond commented 2 years ago

Right now, you'll need to add autoconfigure: false to your config to avoid 2 instances being registered:

    monitor.check.custom:
        class: App\Diagnostics\Check\CustomCheck
        autoconfigure: false
        arguments:
            - [ xhprof, apc, memcache ]
        tags:
            - { name: liip_monitor.check, alias: custom}

The bundle needs some work to avoid needing this.

igordeveloper commented 2 years ago

Right now, you'll need to add autoconfigure: false to your config to avoid 2 instances being registered:

    monitor.check.custom:
        class: App\Diagnostics\Check\CustomCheck
        autoconfigure: false
        arguments:
            - [ xhprof, apc, memcache ]
        tags:
            - { name: liip_monitor.check, alias: custom}

The bundle needs some work to avoid needing this.

ok, perfect.

thank you for the help, right now, i'll use with autoconfigure:false .

igordeveloper commented 2 years ago

Hi @kbond .

do you have a estimate for this work in the bundle? Can i help with a pull request suggest for this? thanks.

kbond commented 2 years ago

I'm not immediately seeing a great path to a solution. The following is true:

  1. It's valid for a check to have multiple liip_monitor.check tags (to add to multiple groups).
  2. Some amount of users (myself included) don't care about the alias. We just want CheckInterface's auto added to the default group (and we don't use the api).

Of course, I'm open to ideas but autoconfigure: false feels like the simplest solution to me.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically closed. Feel free to re-open if it is still relevant.