Skip to content

Commit b06ebdd

Browse files
committed
Fix issue with types and pre-created client
1 parent 53c2ffe commit b06ebdd

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

pkg/monitoring/DatadogStorage.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use DataDog\DogStatsd;
99
use Enqueue\Client\Config;
1010
use Enqueue\Dsn\Dsn;
11-
use Interop\Queue\Queue;
1211

1312
class DatadogStorage implements StatsStorage
1413
{
@@ -30,8 +29,8 @@ public function __construct($config = 'datadog:')
3029

3130
$this->config = $this->prepareConfig($config);
3231

33-
if (false === $this->datadog) {
34-
if (true === $this->config['batched']) {
32+
if (null === $this->datadog) {
33+
if (true === filter_var($this->config['batched'], FILTER_VALIDATE_BOOLEAN)) {
3534
$this->datadog = new BatchedDogStatsd($this->config);
3635
} else {
3736
$this->datadog = new DogStatsd($this->config);
@@ -42,26 +41,19 @@ public function __construct($config = 'datadog:')
4241
public function pushConsumerStats(ConsumerStats $stats): void
4342
{
4443
$queues = $stats->getQueues();
45-
array_walk($queues, function (Queue $queue) use ($stats) {
44+
array_walk($queues, function (string $queue) use ($stats) {
4645
$tags = [
4746
'queue' => $queue,
4847
'consumerId' => $stats->getConsumerId(),
4948
];
5049

51-
$values = [
52-
'startedAtMs' => $stats->getStartedAtMs(),
53-
'started' => $stats->isStarted(),
54-
'finished' => $stats->isFinished(),
55-
'failed' => $stats->isFailed(),
56-
];
57-
5850
if ($stats->getFinishedAtMs()) {
5951
$values['finishedAtMs'] = $stats->getFinishedAtMs();
6052
}
6153

62-
$this->datadog->gauge($this->config['metric.consumers.started'], $stats->isStarted(), 1, $tags);
63-
$this->datadog->gauge($this->config['metric.consumers.finished'], $stats->isFinished(), 1, $tags);
64-
$this->datadog->gauge($this->config['metric.consumers.failed'], $stats->isFailed(), 1, $tags);
54+
$this->datadog->gauge($this->config['metric.consumers.started'], (int) $stats->isStarted(), 1, $tags);
55+
$this->datadog->gauge($this->config['metric.consumers.finished'], (int) $stats->isFinished(), 1, $tags);
56+
$this->datadog->gauge($this->config['metric.consumers.failed'], (int) $stats->isFailed(), 1, $tags);
6557
$this->datadog->gauge($this->config['metric.consumers.received'], $stats->getReceived(), 1, $tags);
6658
$this->datadog->gauge($this->config['metric.consumers.acknowledged'], $stats->getAcknowledged(), 1, $tags);
6759
$this->datadog->gauge($this->config['metric.consumers.rejected'], $stats->getRejected(), 1, $tags);
@@ -163,7 +155,6 @@ private function prepareConfig($config): array
163155
return array_replace([
164156
'host' => 'localhost',
165157
'port' => 8125,
166-
'global_tags' => 'enqueue',
167158
'batched' => true,
168159
'metric.messages.sent' => 'enqueue.messages.sent',
169160
'metric.messages.consumed' => 'enqueue.messages.consumed',

0 commit comments

Comments
 (0)