grafana/pkg/services/ngalert/api
Alex Moreno 531b439cf1
Alerting: Add alert pausing feature (#60734)
* Add field in alert_rule model, add state to alert_instance model, and state to eval

* Remove paused state from eval package

* Skip paused alert rules in scheduler

* Add migration to add is_paused field to alert_rule table

* Convert to postable alerts only if not normal, pernding, or paused

* Handle paused eval results in state manager

* Add Paused state to eval package

* Add paused alerts logic in scheduler

* Skip alert on scheduler

* Remove paused status from eval package

* Apply suggestions from code review

Co-authored-by: George Robinson <george.robinson@grafana.com>

* Remove state

* Rethink schedule and manager for paused alerts

* Change return to continue

* Remove unused var

* Rethink alert pausing

* Paused alerts storing annotations

* Only add one state transition

* Revert boolean method renaming refactor

* Revert take image refactor

* Make registry errors public

* Revert method extraction for getting a folder title

* Revert variable renaming refactor

* Undo unnecessary changes

* Revert changes in test

* Remove IsPause check in PatchPartiLAlertRule function

* Use SetNormal to set state

* Fix text by returning to old behaviour on alert rule deletion

* Add test in schedule_unit_test.go to test ticks with paused alerts

* Add coment to clarify usage of context.Background()

* Add comment to clarify resetStateByRuleUID method usage

* Move rule get to a more limited scope

* Update pkg/services/ngalert/schedule/schedule.go

Co-authored-by: George Robinson <george.robinson@grafana.com>

* rum gofmt on pkg/services/ngalert/schedule/schedule.go

* Remove defer cancel for context

* Update pkg/services/ngalert/models/instance_test.go

Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>

* Update pkg/services/ngalert/models/testing.go

Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>

* Update pkg/services/ngalert/schedule/schedule_unit_test.go

Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>

* Update pkg/services/ngalert/schedule/schedule_unit_test.go

Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>

* Update pkg/services/ngalert/models/instance_test.go

Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>

* skip scheduler rule state clean up on paused alert rule

* Update pkg/services/ngalert/schedule/schedule.go

Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>

* Fix mock in test

* Add (hopefully) final suggestions

* Use error channel from recordAnnotationsSync to cancel context

* Run make gen-cue

* Place pause alert check in channel update after version check

* Reduce branching un update channel select

* Add if for error and move code inside if in state manager ResetStateByRuleUID

* Add reason to logs

* Update pkg/services/ngalert/schedule/schedule.go

Co-authored-by: George Robinson <george.robinson@grafana.com>

* Do not delete alert rule routine, just exit on eval if is paused

* Reduce branching and create-close a channel to avoid deadlocks

* Separate state deletion and state reset (includes history saving)

* Add current pause state in rule route in scheduler

* Split clearState and bring errCh closer to RecordStatesAsync call

* Change rule to ruleMeta in RecordStatesAsync

* copy state to be able to modify it

* Add timeout to context creation

* Shorten the timeout

* Use resetState is rule is paused and deleteState if rule is not paused

* Remove Empty state reason

* Save every rule change in historian

* Add tests for DeleteStateByRuleUID and ResetStateByRuleUID

* Remove useless line

* Remove outdated comment

Co-authored-by: George Robinson <george.robinson@grafana.com>
Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>
Co-authored-by: Armand Grillet <2117580+armandgrillet@users.noreply.github.com>
2023-01-26 18:29:10 +01:00
..
test-data Alerting: Modify endpoint for testing a datasource rule using the UID (#48070) 2022-05-17 14:10:20 +03:00
tooling Alerting: Re-generate swagger definitions (#62154) 2023-01-25 15:01:42 -06:00
api_alertmanager_guards_test.go Alerting: replace usage of simplejson to json.RawMessage in NotificationChannelConfig (#60423) 2022-12-16 13:01:06 -05:00
api_alertmanager_guards.go Alerting: replace usage of simplejson to json.RawMessage in NotificationChannelConfig (#60423) 2022-12-16 13:01:06 -05:00
api_alertmanager_test.go Docs: Rename Message templates to Notification templates (#59477) 2023-01-18 17:26:34 +00:00
api_alertmanager.go Alerting: Use alerting.GrafanaAlertmanager instead of initialising Alertmanager components directly (#61230) 2023-01-13 12:54:38 -04:00
api_configuration_test.go Alerting: Remove url based external alertmanagers config (#57918) 2022-11-10 16:34:13 +01:00
api_configuration.go Alerting: Remove url based external alertmanagers config (#57918) 2022-11-10 16:34:13 +01:00
api_prometheus_test_fixtures.go Alerting: Display query from grafana-managed alert rules on /api/v1/rules (#45969) 2022-03-14 10:39:20 +00:00
api_prometheus_test.go Alerting: Use consts from alerting package (#61241) 2023-01-10 19:59:13 +00:00
api_prometheus.go Nested Folders: Support getting of nested folder in folder service wh… (#58597) 2022-11-11 14:28:24 +01:00
api_provisioning_test.go Docs: Rename Message templates to Notification templates (#59477) 2023-01-18 17:26:34 +00:00
api_provisioning.go Docs: Rename Message templates to Notification templates (#59477) 2023-01-18 17:26:34 +00:00
api_ruler_test.go Nested Folders: Support getting of nested folder in folder service wh… (#58597) 2022-11-11 14:28:24 +01:00
api_ruler_validation_test.go Chore: Fix random indices for slices in test files (#61884) 2023-01-24 15:07:37 -03:00
api_ruler_validation.go Alerting: Set Dashboard and Panel IDs on rule group replacement (#60374) 2022-12-16 11:47:25 +01:00
api_ruler.go Alerting: Add alert pausing feature (#60734) 2023-01-26 18:29:10 +01:00
api_testing_test.go Alerting: Condition evaluator with cached pipeline (#57479) 2022-11-02 10:13:39 -04:00
api_testing.go Alerting: rule backtesting API (#57318) 2022-12-14 09:44:14 -05:00
api.go AuthN: User Quota (#61540) 2023-01-16 11:54:15 +01:00
authorization_test.go Alerting: rule backtesting API (#57318) 2022-12-14 09:44:14 -05:00
authorization.go Alerting: rule backtesting API (#57318) 2022-12-14 09:44:14 -05:00
configuration.go Alerting: New API endpoint GET /api/v1/ngalert (#55134) 2022-09-14 14:03:10 -04:00
errors.go Alerting: Update forking request handlers to use the same errors (#52965) 2022-08-02 09:33:59 -04:00
forking_alertmanager.go Alerting: Fix "Not Implemented" responses (#57710) 2022-10-26 23:35:52 -03:00
forking_prometheus.go Alerting: Update forking request handlers to use the same errors (#52965) 2022-08-02 09:33:59 -04:00
forking_ruler.go Alerting: Update forking request handlers to use the same errors (#52965) 2022-08-02 09:33:59 -04:00
generated_base_api_alertmanager.go Alerting: Fix "Not Implemented" responses (#57710) 2022-10-26 23:35:52 -03:00
generated_base_api_configuration.go Alerting: New API endpoint GET /api/v1/ngalert (#55134) 2022-09-14 14:03:10 -04:00
generated_base_api_prometheus.go Alerting: Refactor API types generation with different names. (#51785) 2022-07-18 03:08:08 -04:00
generated_base_api_provisioning.go Docs: Rename Message templates to Notification templates (#59477) 2023-01-18 17:26:34 +00:00
generated_base_api_ruler.go Alerting: Refactor API types generation with different names. (#51785) 2022-07-18 03:08:08 -04:00
generated_base_api_testing.go Alerting: Re-generate swagger definitions (#62154) 2023-01-25 15:01:42 -06:00
lotex_am.go Alerting: Fix "Not Implemented" responses (#57710) 2022-10-26 23:35:52 -03:00
lotex_prom.go Alerting: modify prometheus endpoints for proxying using the datasource UID (#48052) 2022-05-06 15:05:02 -04:00
lotex_ruler_test.go Move SignedInUser to user service and RoleType and Roles to org (#53445) 2022-08-10 11:56:48 +02:00
lotex_ruler.go Alerting: Fix feedback (#57922) 2022-11-02 22:36:14 +00:00
persist.go Alerting: Add alert pausing feature (#60734) 2023-01-26 18:29:10 +01:00
promql_compat_test.go Alerting/testing promql extraction (#34665) 2021-05-25 11:54:50 -04:00
promql_compat.go Alerting: check upstream response content type in lotex proxy (#34760) 2021-05-27 14:12:29 +03:00
provisioning.go Docs: Rename Message templates to Notification templates (#59477) 2023-01-18 17:26:34 +00:00
testing_api.go Alerting: Re-generate swagger definitions (#62154) 2023-01-25 15:01:42 -06:00
testing.go Alerting: Remove mis-behaving fake and fix masked test failure in AM config API (#47747) 2022-04-13 19:31:57 -05:00
util_test.go Chore: Fix random indices for slices in test files (#61884) 2023-01-24 15:07:37 -03:00
util.go Alerting: Fix "Not Implemented" responses (#57710) 2022-10-26 23:35:52 -03:00