Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Metrics snapshot config proposal and fix for race condition #936

Merged
merged 2 commits into from Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions config/horizon.php
Expand Up @@ -113,8 +113,9 @@
|--------------------------------------------------------------------------
|
| Here you can configure how many snapshots should be kept to display in
| the metrics graph. This will get used in combination with Horizon's
| `horizon:snapshot` schedule to define how long to retain metrics.
| the metrics graph and how often they can be stored.
| This will get used in combination with Horizon's `horizon:snapshot`
| schedule to define how long to retain metrics.
|
*/

Expand All @@ -123,6 +124,7 @@
'job' => 24,
'queue' => 24,
],
'snapshot_lock' => 300,
],

/*
Expand Down
2 changes: 1 addition & 1 deletion src/Console/SnapshotCommand.php
Expand Up @@ -31,7 +31,7 @@ class SnapshotCommand extends Command
*/
public function handle(Lock $lock, MetricsRepository $metrics)
{
if ($lock->get('metrics:snapshot', 300)) {
if ($lock->get('metrics:snapshot', config('horizon.metrics.snapshot_lock', 300) - 30)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -30 here is a slight change in behavior. We may not want to do that on a minor/patch release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the bugfix. Can be smaller too, but the point is:

  1. Cron executes at 09:00:00
  2. Command for metrics runs at 09:00:05 and is taken
  3. Metric snapshot is taken
  4. Cron executes at 09:05:00
  5. Command for metrics runs at 09:05:01 and is not available, because lock is till 09:05:05.

That's the bug. The -30 is "a" solution, not the only one off-course. I'm open for suggestions.

$metrics->snapshot();

$this->info('Metrics snapshot stored successfully.');
Expand Down