|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
7
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
8
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
9
|
|
|
* |
|
10
|
|
|
* Copyright (c) 2024 Mykhailo Shtanko [email protected] |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please view the LICENSE.MD |
|
13
|
|
|
* file that was distributed with this source code. |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace FRZB\Component\MetricsPower\OptionsResolver\Resolver; |
|
17
|
|
|
|
|
18
|
|
|
use FRZB\Component\DependencyInjection\Attribute\AsService; |
|
19
|
|
|
use FRZB\Component\DependencyInjection\Attribute\AsTagged; |
|
20
|
|
|
use FRZB\Component\MetricsPower\Attribute\PrometheusOptions; |
|
|
|
|
|
|
21
|
|
|
use FRZB\Component\MetricsPower\Exception\MetricsRegistrationException; |
|
22
|
|
|
use FRZB\Component\MetricsPower\Helper\CounterHelper; |
|
23
|
|
|
use Prometheus\Exception\MetricsRegistrationException as BaseMetricsRegistrationException; |
|
24
|
|
|
use Prometheus\RegistryInterface; |
|
25
|
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire; |
|
26
|
|
|
use Symfony\Component\Messenger\Event\AbstractWorkerMessageEvent; |
|
27
|
|
|
use Symfony\Component\Messenger\Event\SendMessageToTransportsEvent; |
|
28
|
|
|
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent; |
|
29
|
|
|
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent; |
|
30
|
|
|
use Symfony\Component\Messenger\Event\WorkerMessageReceivedEvent; |
|
31
|
|
|
use Symfony\Component\Messenger\Event\WorkerMessageRetriedEvent; |
|
32
|
|
|
|
|
33
|
|
|
#[AsService, AsTagged(OptionsResolverInterface::class)] |
|
34
|
|
|
class PrometheusOptionsResolver implements OptionsResolverInterface |
|
35
|
|
|
{ |
|
36
|
|
|
public function __construct( |
|
37
|
|
|
#[Autowire(env: 'PROMETHEUS_NAMESPACE')] |
|
38
|
|
|
private readonly string $namespace, |
|
39
|
|
|
private readonly RegistryInterface $registry, |
|
40
|
|
|
) {} |
|
41
|
|
|
|
|
42
|
|
|
/** @throws MetricsRegistrationException */ |
|
43
|
|
|
public function resolve(AbstractWorkerMessageEvent|SendMessageToTransportsEvent $event, PrometheusOptions $options): void |
|
44
|
|
|
{ |
|
45
|
|
|
$postfix = match ($event::class) { |
|
46
|
|
|
WorkerMessageFailedEvent::class => 'failed', |
|
47
|
|
|
WorkerMessageHandledEvent::class => 'handled', |
|
48
|
|
|
WorkerMessageReceivedEvent::class => 'received', |
|
49
|
|
|
WorkerMessageRetriedEvent::class => 'retried', |
|
50
|
|
|
SendMessageToTransportsEvent::class => 'sent', |
|
51
|
|
|
}; |
|
52
|
|
|
|
|
53
|
|
|
try { |
|
54
|
|
|
$this->registry |
|
55
|
|
|
->getOrRegisterCounter($this->namespace, CounterHelper::makeName($options, postfix: $postfix), $options->help, $options->labels) |
|
56
|
|
|
->inc($options->values); |
|
57
|
|
|
} catch (BaseMetricsRegistrationException $e) { |
|
58
|
|
|
throw MetricsRegistrationException::fromThrowable($e); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function getType(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return PrometheusOptions::class; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths