Commit Graph

635 Commits

Author SHA1 Message Date
Jo
062d255124
Handle ioutil deprecations (#53526)
* replace ioutil.ReadFile -> os.ReadFile

* replace ioutil.ReadAll -> io.ReadAll

* replace ioutil.TempFile -> os.CreateTemp

* replace ioutil.NopCloser -> io.NopCloser

* replace ioutil.WriteFile -> os.WriteFile

* replace ioutil.TempDir -> os.MkdirTemp

* replace ioutil.Discard -> io.Discard
2022-08-10 15:37:51 +02:00
idafurjes
6afad51761
Move SignedInUser to user service and RoleType and Roles to org (#53445)
* Move SignedInUser to user service and RoleType and Roles to org

* Use go naming convention for roles

* Fix some imports and leftovers

* Fix ldap debug test

* Fix lint

* Fix lint 2

* Fix lint 3

* Fix type and not needed conversion

* Clean up messages in api tests

* Clean up api tests 2
2022-08-10 11:56:48 +02:00
George Robinson
196b781c70
Alerting: Delete expired images from the database (#53236)
This commit adds a DeleteExpiredService that deletes expired images from the database. It is run in the periodic collector service.
2022-08-09 15:28:36 +01:00
Alex Ratner
fecf4c41ad
Dashboard: Spelling corrections in end-user visible dialogs (#53340) 2022-08-09 10:19:30 +02:00
Jean-Philippe Quéméner
54217a2037
Alerting: set dashboard and panel id using annotations in provisioning api (#53221) 2022-08-03 16:05:32 +02:00
Yuriy Tseretyan
718620c197
Alerting: Update forking request handlers to use the same errors (#52965)
* generalize error handling in forking request handlers
* remove MatchesBackend and change test to test Can
* add 404 to route specs
* change backendTypeByUID to getDatasourceByUID of expected type
* use common errors in api testing
* handle 401 in errorToResponse
* replace backend type error with "unexpected datasource type"
* update swagger spec
2022-08-02 09:33:59 -04:00
Alexander Weaver
c50cbea0bb
Alerting: Extract alert rule diff logic into separate file with exported API (#53083)
* Refactor diff logic into separate file with exported API

* Fix linter complaint
2022-08-01 23:41:23 -05:00
Yuriy Tseretyan
5fb778814c
Alerting: Update rules version when folder title is updated (#53013)
* remove support for bus from scheduler
* rename event to FolderTitleUpdated and fire only if title has changed
* add method to increase version of all rules that belong to a folder
* update ngalert service to subscribe to folder title change event call data store and update scheduler
* add tests
2022-08-01 19:28:38 -04:00
Alexander Weaver
cc20f04860
Alerting: Increase alert rule operation perf by replacing subquery with threshold calculation (#53069)
* Replace subquery with threshold calculation

* Use offset/limit to account for orgs with large gaps in IDs

* Collapse into one statement

* Drop dead constants

* Revert to 2 query approach

* Drop unused consts again
2022-08-01 16:48:34 -05:00
Alexander Emelin
e791a4e576
Search: Move entity events to transaction (#52394) 2022-08-01 18:56:36 +03:00
Konrad Lalik
54f2c056f5
Alerting: Configure alert manager data source as an external AM (#52081)
Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com>
Co-authored-by: gotjosh <josue.abreu@gmail.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
2022-08-01 10:20:43 +02:00
Yuriy Tseretyan
a081764fd8
Alerting: Scheduler to use AlertRule (#52354)
* update GetAlertRulesForSchedulingQuery to have result AlertRule
* update fetcher utils and registry to support AlertRule
* alertRuleInfo to use alert rule instead of version
* update updateCh hanlder of ruleRoutine to just clean up the state. The updated rule will be provided at the next evaluation
* update evalCh handler of ruleRoutine to use rule from the message and clear state as well as update extra labels

* remove unused function in ruleRoutine
* remove unused model SchedulableAlertRule

* store rule version in ruleRoutine instead of rule
* do not call the sender if nothing to send
2022-07-26 09:40:06 -04:00
gotjosh
d762de7aa7
Revert "Alerting: Add support for images in Line alerts (#50703)" (#52593)
This reverts commit 0af09b8c57.
2022-07-21 06:57:57 -04:00
George Robinson
0af09b8c57
Alerting: Add support for images in Line alerts (#50703) 2022-07-21 11:43:06 +02:00
gotjosh
b026f2bc5d
Alerting: Allow the webhook notifier to support a custom Authorization header (#52515)
* Allow the webhook notifier to support a custom Authorization header

Instead of doing something clever of re-using the existing username/password fields of Basic Authentication - I opted for two diffent fields to match the upstream Alertmanager configuration (that in turn is based of the HTTP Basic authentication).

 It'll fail if you have values for both HTTP Basic Authentication and Authorization.
2022-07-21 10:25:58 +01:00
Jean-Philippe Quéméner
ba9c18d9c3
Alerting: use static channel configuration to determinate secure fields (#52527)
* Alerting: use static channel configuration to determinate secure fields

* move to channels package

* introduce channel_config package to fix cyclic import

* add missing changes

* compare type to type
2022-07-20 19:58:36 +02:00
Jean-Philippe Quéméner
320262c3db
Alerting: Cleanup the alert_configuration table on write (#51497) 2022-07-20 16:54:18 +02:00
Jean-Philippe Quéméner
50ae42130b
Alerting: take datasources as external alertmanagers into consideration (#52534) 2022-07-20 16:50:49 +02:00
Yuriy Tseretyan
79d92aa03e
Alerting: Rename sender.Sender to sender.ExternalAlertmanagers (#52463) 2022-07-19 14:04:48 -04:00
George Robinson
094dfd0d4d
Alerting: Fix Slack push notifications (#52391)
This commit fixes push notifications for Slack which used to show "This content cannot be displayed". The text field is shown in both the message and the push notification.
2022-07-19 17:42:24 +01:00
Yuriy Tseretyan
054fe54b03
Alerting: Split Scheduler and AlertRouter tests (#52416)
* move fake FakeExternalAlertmanager to sender package
* move tests from scheduler to router
* update alerts router to have all fields private
* update scheduler tests to use sender mock
2022-07-19 09:32:54 -04:00
Peter Holmberg
e74c2390de
Alerting: Prevent evaluation if "for" shorter than "evaluate" (#51797)
Co-authored-by: Armand Grillet <armand.grillet@outlook.com>
2022-07-19 10:30:26 +02:00
George Robinson
e7feff6d99
Alerting: Move debug log line to where alert rules are updated (#52318) 2022-07-18 11:27:06 -04:00
idafurjes
f5cace8bbd
Rename Acl to ACL (#52342)
* Rename Acl to ACL

* Fix yaml files

* Add xorm tags and fix test
2022-07-18 15:14:58 +02:00
Joe Blubaugh
689ae96a0e
Alerting: Refactor API types generation with different names. (#51785)
This changes the API codegen template (controller-api.mustache) to simplify some names. When this package was created, most APIs "forked" to either a Grafana backend implementation or a "Lotex" remote implementation. As we have added APIs it's no longer the case. Provisioning, configuration, and testing APIs do not fork, and we are likely to add additional APIs that don't fork.

This change replaces {{classname}}ForkingService with {{classname}} for interface names, and names the concrete implementation {{classname}}Handler. It changes the implied implementation of a route handler from fork{{nickname}} to handle{{nickname}}. So PrometheusApiForkingService becomes PrometheusApi, ForkedPrometheusApi becomes PrometheusApiHandler and forkRouteGetGrafanaAlertStatuses becomes handleRouteGetGrafanaAlertStatuses

It also renames some files - APIs that do no forking go from forked_{{name}}.go to {{name}}.go and APIs that still fork go from forked_{{name}}.go to forking_{{name}}.go to capture the idea that those files a "doing forking" rather than "are a fork of something."

Signed-off-by: Joe Blubaugh <joe.blubaugh@grafana.com>
2022-07-18 03:08:08 -04:00
Yuriy Tseretyan
6e1e4a4215
Alerting: Update DbStore to use disabled orgs from the config (#52156)
* update DbStore to use UnifiedAlerting settings
* remove disabled orgs from scheduler and use config in db store instead
* remove test
2022-07-15 14:13:30 -04:00
Yuriy Tseretyan
a7509ba18b
Alerting: rule evaluation loop's update channel to provide version (#52170)
* handler for update message in rule evaluation routine ignores the message if its version greater or equal.
* replace messages to update the channel if it is not empty
2022-07-15 12:32:52 -04:00
idafurjes
17ec9cac83
Add delete user from other services/stores (#51912)
* Remove user from preferences, stars, orguser, team member

* Fix lint

* Add Delete user from org and dashboard acl

* Delete user from user auth

* Add DeleteUser to quota

* Add test files and adjust user auth store

* Rename package in wire for user auth

* Import Quota Service interface in other services

* do the same in tests

* fix lint tests

* Fix tests

* Add some tests

* Rename InsertUser and DeleteUser to InsertOrgUser and DeleteOrgUser

* Rename DeleteUser to DeleteByUser in quota

* changing a method name in few additional places

* Fix in other places

* Fix lint

* Fix tests

* Rename DeleteOrgUser to DeleteUserFromAll

* Update pkg/services/org/orgimpl/org_test.go

Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>

* Update pkg/services/preference/prefimpl/inmemory_test.go

Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>

* Rename Acl to ACL

* Fix wire after merge with main

* Move test to uni test

Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
2022-07-15 18:06:44 +02:00
Jean-Philippe Quéméner
41790083d2
Alerting: Add file provisioning for alert rules (#51635) 2022-07-14 23:53:13 +02:00
Yuriy Tseretyan
e5e8747ee9
Alerting: Update state manager to accept reserved labels (#52189)
* add tests for cache getOrCreate
* update ProcessEvalResults to accept extra lables
* extract to getRuleExtraLabels
* move populating of constant rule labels to extra labels
2022-07-14 15:59:59 -04:00
Matthew Jacobson
efa0d90093
Alerting: Fix Teams notifier not failing on 200 response with error (#52254)
Team's webhook API does not always use the status code to communicate errors.
There are cases where it returns 200 and an error message in the body.
For example, 429 - Too Many Requests or when the message is too large.
Instead, what we should be looking for is a response body = "1".

https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL#send-messages-using-curl-and-powershell
2022-07-14 13:15:18 -04:00
Michał Zielonka
b54da68765
Alerting: fix validation of alertmanager template. (#51538)
without setting function map from alertmanager we receive error:
method=PUT path=/api/v1/provisioning/templates/slack.message status=400
level=error msg="invalid object specification: invalid template: template: :1: function \"toUpper\" not defined"

So for validation we should use the same settings as alertmanager do
for templates internally.
2022-07-14 11:54:08 +02:00
George Robinson
34d45977ca
Alerting: Fix bug where state did not change between Alerting and Error (#52204)
This commit fixes a bug where the state did not change from Alerting to Error if the evaluation result returned an error, or from Error to Alerting if evaluations stopped returning errors.
2022-07-14 10:53:39 +01:00
Alexander Weaver
2d7389c34d
Alerting: Provisioning API respects global rule quota (#52180)
* Inject interface for quota service and create mock

* Check quota and return 403 if limit exceeded

* Implement tests for quota being exceeded
2022-07-13 17:36:17 -05:00
Yuriy Tseretyan
429ed4b4ee
remove unused orgStore from scheduler (#52157) 2022-07-13 10:34:35 -04:00
Yuriy Tseretyan
0d4c503d3d
update Evaluator interface to accept context (#52151) 2022-07-13 10:21:11 -04:00
Sofia Papagiannaki
21632817c5
Alerting: Fix invalid swagger specification (#51907)
* Alerting: Fix invalid swagger specification

* Add make targets for validating the generated swagger spec
2022-07-13 12:34:54 +03:00
Yuriy Tseretyan
554ebd647b
Alerting: Refactor Evaluator (#51673)
* AlertRule to return condition
* update ConditionEval to not return an error because it's always nil
* make getExprRequest private
* refactor executeCondition to just converter and move execution to the ConditionEval as this makes code more readable.
* log error if results have errors
* change signature of evaluate function to not return an error
2022-07-12 16:51:32 -04:00
Yuriy Tseretyan
a6b1090879
Alerting: refactor scheduler and separate notification logic (#48144)
* Introduce AlertsRouter in the sender package, and move all fields and methods related to notifications out of the scheduler to this router.
* Introduce a new interface AlertsSender in the schedule package and replace calls of anonymous function `notify` inside the ruleRoutine to calling methods of that interface.
* Rename interface Scheduler in api package to ExternalAlertmanagerProvider, and replace scheduler with AlertRouter as struct that implements the interface.
2022-07-12 15:13:04 -04:00
Alexander Weaver
0e066dd5f8
Alerting: Allow filtering of contact points by name (#51933)
* Define query param and regenerate

* Add query struct for contact points

* Filter contact points by name in query

* Document that name filter is optional
2022-07-11 17:11:46 -05:00
Matthew Jacobson
28dd413c1d
Alerting: Add config disabled_labels to disable reserved labels (#51832)
* Alerting: Add config disabled_labels to disable reserved labels

[unified_alerting.reserved_labels]
disabled_labels

* Replace IsGrafanaFolderDisabled with more generic IsReservedLabelDisabled

* Simplify SchedulerCfg by including UnifiedAlertingSettings
2022-07-11 12:41:40 -04:00
Matthew Jacobson
434e94ef2b
Alerting: Update default route groupBy to [grafana_folder, alertname] (#50052)
* Alerting: Update default route groupBy to [grafana_folder, alertname]

Default group by for new routes and migrations is now [grafana_folder, alertname]
2022-07-11 12:24:43 -04:00
Alexander Weaver
fce283d73e
Alerting: Add method to reset notification policy tree back to the default (#51934)
* Define route and run codegen

* Wire up HTTP layer

* Update API layer and test fakes

* Implement reset of policy tree

* Implement service layer test and authorization bindings

* API layer testing

* Be more specific when injecting settings
2022-07-08 16:23:18 -05:00
Alexander Weaver
d77731646c
Fix consistency errors and regenerate (#51935) 2022-07-08 10:33:43 -05:00
dingweiqings
119c13e666
Alerting: Add custom templated title to Wecom notifier (#51529)
* add custom title in wecom channel

* add wecom test case and setting config in ui

* Update pkg/services/ngalert/notifier/channels/wecom_test.go

Co-authored-by: Matthew Jacobson <JacobsonMT@gmail.com>

* change version in comment

* Update pkg/services/ngalert/notifier/available_channels.go

Co-authored-by: Matthew Jacobson <JacobsonMT@gmail.com>

* format

Co-authored-by: Matthew Jacobson <JacobsonMT@gmail.com>
2022-07-06 11:54:46 -04:00
Jean-Philippe Quéméner
4a76436be2
Altering: validate that the mute time intervals exist when updating routing tree (#51573)
* validate that the mute time intervals exist when updating routing tree

* run lint

* add tests
2022-07-05 13:09:17 -04:00
Alexander Weaver
b9c7eb1380
Alerting: Add method to provisioning API for obtaining a group and its rules (#51398)
* Generate shell for new route

* Propagate path parameters

* Implement route logic

* Add a couple simple tests

* Use NotFound error for not found, avoid returning pointer

* Regenerate
2022-07-05 11:53:50 -05:00
Jean-Philippe Quéméner
e64cde8727
Alerting: validate that the receiver exist when updating routing tree (#51561)
* Alerting: validate that the receiver exist when updating routing tree

* rename interface

* add missing file

* change constructor

* fix e2e tests

* only import package once

* add unit test for bug

* wording

* close response body

* Update pkg/services/ngalert/api/tooling/definitions/alertmanager_validation.go

* refactor to remove database roundtrip
2022-07-05 18:09:57 +02:00
George Robinson
6844ac9879
Alerting: Change __alertScreenshotToken__ to __alertImageToken__ (#50771) 2022-07-04 06:05:36 -04:00
Jean-Philippe Quéméner
580c5b6ad2
Alerting: add YAML support for relative time range (#51694) 2022-07-04 06:03:34 -04:00