• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fractalzombie / frzb-metrics-power / 8569692273

05 Apr 2024 12:19PM UTC coverage: 98.214% (-0.8%) from 99.048%
8569692273

push

github

fractalzombie
[MetricsPower] Fix consumer issue, when redis not available

14 of 16 new or added lines in 4 files covered. (87.5%)

220 of 224 relevant lines covered (98.21%)

10.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/OptionsResolver/Resolver/PrometheusOptionsResolver.php
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 fractalzombie@gmail.com
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 FRZB\Component\MetricsPower\Logger\MetricsPowerLoggerInterface;
24
use Prometheus\Exception\MetricsRegistrationException as BaseMetricsRegistrationException;
25
use Prometheus\RegistryInterface;
26
use Psr\Log\LoggerInterface;
27
use Symfony\Component\DependencyInjection\Attribute\Autowire;
28
use Symfony\Component\Messenger\Event\AbstractWorkerMessageEvent;
29
use Symfony\Component\Messenger\Event\SendMessageToTransportsEvent;
30
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
31
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
32
use Symfony\Component\Messenger\Event\WorkerMessageReceivedEvent;
33
use Symfony\Component\Messenger\Event\WorkerMessageRetriedEvent;
34

35
#[AsService, AsTagged(OptionsResolverInterface::class)]
36
class PrometheusOptionsResolver implements OptionsResolverInterface
37
{
38
    public function __construct(
39
        #[Autowire(env: 'PROMETHEUS_NAMESPACE')]
40
        private readonly string $namespace,
41
        private readonly RegistryInterface $registry,
42
        private readonly ?MetricsPowerLoggerInterface $logger = null,
43
    ) {}
16✔
44

45
    /** @throws MetricsRegistrationException */
46
    public function resolve(AbstractWorkerMessageEvent|SendMessageToTransportsEvent $event, PrometheusOptions $options): void
47
    {
48
        $postfix = match ($event::class) {
16✔
49
            WorkerMessageFailedEvent::class => 'failed',
16✔
50
            WorkerMessageHandledEvent::class => 'handled',
16✔
51
            WorkerMessageReceivedEvent::class => 'received',
16✔
52
            WorkerMessageRetriedEvent::class => 'retried',
16✔
53
            SendMessageToTransportsEvent::class => 'sent',
16✔
54
        };
16✔
55

56
        try {
57
            $this->registry
16✔
58
                ->getOrRegisterCounter($this->namespace, CounterHelper::makeName($options, postfix: $postfix), $options->help, $options->labels)
16✔
59
                ->inc($options->values);
16✔
60
        } catch (BaseMetricsRegistrationException $e) {
4✔
61
            throw MetricsRegistrationException::fromThrowable($e);
4✔
NEW
62
        } catch (\Throwable $e) {
×
NEW
63
            $this->logger?->error($event, $e);
×
64
        }
65
    }
66

67
    public static function getType(): string
68
    {
69
        return PrometheusOptions::class;
12✔
70
    }
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc