laravel / horizon

Dashboard and code-driven configuration for Laravel queues.
https://laravel.com/docs/horizon
MIT License
3.87k stars 657 forks source link

Obsolete Jobs/Queues in Metrics #1152

Closed Cellard closed 2 years ago

Cellard commented 2 years ago

Description:

Metrics is showing jobs and queues, that were already removed or renamed.

Steps To Reproduce:

  1. Create and run a job

  2. Rename job class and run it again

  3. Define a queue, run a job through it

  4. Rename queue and run a job again

In both cases old names remained in Horizon Metics panel. I hoped they will be removed after metrics.trim_snapshots exceeded, but they wasn't.

driesvints commented 2 years ago

This is expected. The metrics show historical data. Renaming doesn't changes the data that was snapshotted.

Cellard commented 2 years ago

Is there a way to completely reset metrics?

erickneverson commented 2 years ago

I recognize this issue is closed, but am also curious about how to reset this particular metric. Do we need to create some sort of custom command until one is provided by the framework?

Thanks

trevorgehman commented 1 year ago

I'm also wondering the same thing. Is there some kind of command to just completely wipe the Horizon metrics that are stored in Redis?

trevorgehman commented 1 year ago

Here's something I came up with to clear all Horizon metrics:



use Laravel\Horizon\Repositories\RedisMetricsRepository;

$redis = resolve(RedisMetricsRepository::class)->connection();

$redis->del('measured_jobs');
$redis->del('measured_queues');
$redis->del('last_snapshot_at');

foreach($redis->keys('snapshot:*') as $key) {
  $redis->del(str($key)->after(config('horizon.prefix')));
}

foreach($redis->keys('metrics:*') as $key) {
  $redis->del(str($key)->after(config('horizon.prefix')));
}
trevorgehman commented 1 year ago

Here's something I came up with to clear all Horizon metrics:

use Laravel\Horizon\Repositories\RedisMetricsRepository;

$redis = resolve(RedisMetricsRepository::class)->connection();

$redis->del('measured_jobs');
$redis->del('measured_queues');
$redis->del('last_snapshot_at');

foreach($redis->keys('snapshot:*') as $key) {
  $redis->del(str($key)->after(config('horizon.prefix')));
}

foreach($redis->keys('metrics:*') as $key) {
  $redis->del(str($key)->after(config('horizon.prefix')));
}

@driesvints Would you consider a PR for adding this command?

driesvints commented 1 year ago

@trevorgehman I think that could maybe be useful yeah. You could attempt a PR to see if Taylor also finds it useful, thanks.