-
Notifications
You must be signed in to change notification settings - Fork 77
feat: sync alert jobs #3059
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
feat: sync alert jobs #3059
Changes from 3 commits
5299d1d
8586dc4
ce68f8a
fe79e92
6fed4f6
8d0800f
6b05ebe
65a196a
5b301b6
0f58560
d2b35c7
6135d10
492095f
55fc122
4519e14
21a834f
c7c6204
0b25355
f88dc83
f57c296
3a93b06
6247067
8bf16ad
951cca3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,7 +210,7 @@ defmodule Logflare.Alerting do | |
| @spec create_alert_job_struct(AlertQuery.t()) :: Quantum.Job.t() | ||
| def create_alert_job_struct(%AlertQuery{} = alert_query) do | ||
| AlertsScheduler.new_job(run_strategy: Quantum.RunStrategy.Local) | ||
| |> Quantum.Job.set_task({__MODULE__, :run_alert, [alert_query, :scheduled]}) | ||
| |> Quantum.Job.set_task({__MODULE__, :run_alert, [alert_query.id, :scheduled]}) | ||
| |> Quantum.Job.set_schedule(Crontab.CronExpression.Parser.parse!(alert_query.cron)) | ||
| |> Quantum.Job.set_name(to_job_name(alert_query)) | ||
| end | ||
|
|
@@ -268,8 +268,17 @@ defmodule Logflare.Alerting do | |
|
|
||
| Send notifications if necessary configurations are set. If no results are returned from the query execution, no alert is sent. | ||
| """ | ||
| @spec run_alert(AlertQuery.t(), :scheduled) :: | ||
| @spec run_alert(AlertQuery.t() | integer(), :scheduled) :: | ||
| :ok | {:error, :not_enabled} | {:error, :below_min_cluster_size} | ||
| def run_alert(alert_id, :scheduled) when is_integer(alert_id) do | ||
| # sync the alert job for the next run | ||
| sync_alert_job(alert_id) | ||
|
||
|
|
||
| if alert_query = get_alert_query_by(id: alert_id) do | ||
| run_alert(alert_query, :scheduled) | ||
| end | ||
| end | ||
|
|
||
| def run_alert(%AlertQuery{} = alert_query, :scheduled) do | ||
| # perform pre-run checks | ||
| cfg = Application.get_env(:logflare, Logflare.Alerting) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's possible for alert schedule be rarer than alerts_scheduler_sync schedule, less than once in 60 minutes? That would probably mean that those jobs would never run, since in the current
do_sync_alert_jobsthey would keep getting re-added (which in Quantum doesn't seem (?) to execute the job right away but kind of reschedules and effectively postpones them indefinitely).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes there are jobs that run on a minutely basis, or every hour
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm that behaviour would not be good. Perhaps separate sync schedule jobs, syncing once a day for hourly schedules and once a minute for jobs less than an hour
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I was wrong and misunderstood how Quantum works. The original "wipe and re-add" approach is safe for all but the jobs coinciding with
alerts_scheduler_syncschedule ("0 * * * *") so I think it still makes sense to makedo_sync_alert_jobsa bit smarter. Right now I'm going with something like this