Skip to content

Commit 422005d

Browse files
fix(metrics): correct Redis key pattern in overview aggregation
The overview endpoint was returning zero counts because scanKeys() couldn't find any matching keys due to incorrect pattern. Problem: - Used pattern: queue_metrics:jobs:*:*:* - Actual keys: laravel_database_queue_metrics:jobs:redis:default:... - Laravel's Redis prefix was not included in the pattern Solution: - Build full pattern: [redis_prefix][our_prefix]:jobs:* - Pass full keys to getHash() (no prefix stripping needed) Tested in sandbox with 40+ FastJob executions - now correctly aggregates total_jobs_processed and total_jobs_failed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fb0daa4 commit 422005d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/Services/MetricsQueryService.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,21 @@ public function getOverview(): array
9595
$totalFailed = 0;
9696

9797
// Scan Redis for all job metrics keys and aggregate
98-
// StorageManager already includes the Redis prefix, so we only need our pattern
9998
$manager = app(\PHPeek\LaravelQueueMetrics\Storage\StorageManager::class);
100-
$pattern = $manager->key('jobs', '*', '*', '*');
99+
100+
// Build full pattern including Laravel Redis prefix
101+
$redisPrefix = config('database.redis.options.prefix', '');
102+
$ourPrefix = config('queue-metrics.storage.prefix');
103+
$fullPattern = $redisPrefix . $ourPrefix . ':jobs:*';
104+
101105
$driver = $manager->driver();
102106

103-
// Get all job metrics keys
104-
$keys = $driver->scanKeys($pattern);
107+
// Get all job metrics keys - scanKeys expects the FULL pattern with Laravel prefix
108+
$keys = $driver->scanKeys($fullPattern);
105109

106110
// Sum metrics from all keys
107111
foreach ($keys as $key) {
108-
// Remove the Redis prefix to get the relative key for getHash
109-
$relativeKey = str_replace(
110-
config('database.redis.options.prefix', '') . config('queue-metrics.storage.prefix') . ':',
111-
'',
112-
$key
113-
);
114-
112+
// getHash also needs the full key with prefix
115113
$data = $driver->getHash($key);
116114
if (is_array($data)) {
117115
$totalProcessed += (int) ($data['total_processed'] ?? 0);

0 commit comments

Comments
 (0)