Commit Graph

461 Commits

Author SHA1 Message Date
Sofia Papagiannaki
b1eec36df3
Alerting: Fix authorisation to use namespace UIDs for scope (#81231) 2024-01-25 15:19:51 -05:00
William Wernert
2203bc2a3d
Alerting: Refactor provisioning tests/fakes (#81205)
* Fix up test Alertmanager config JSON

* Move fake AM config and provisioning stores to fakes package
2024-01-24 17:15:55 -05:00
Julien Duchesne
40312c527b
ngalert openapi: Fix ObjectMatchers definition (#79477)
These don't get marshalled and unmarshalled in the same way as they are represented in Go
This PR changes the OpenAPI spec to reflect what the API accepts and sends back
2024-01-19 14:37:11 -05:00
Julien Duchesne
c9211fbd69
ngalert openapi: Use same basePath as rest of Grafana (#79025)
* ngalert openapi: Use same `basePath` as rest of Grafana
Currently, there are two issues that prevent easily merging `ngalert` and grafana openapi specs:
- The basePath is different. `grafana` has `/api` and `ngalert` has `/api/v1`. I changed `ngalert` to use `/api`
- The `ngalert` endpoints have their basePath in the each operation path. The basePath should actually be omitted
---------

Co-authored-by: Yuriy Tseretyan <yuriy.tseretyan@grafana.com>
2024-01-17 11:53:16 -05:00
Jean-Philippe Quéméner
82638d059f
feat(alerting): add state persister interface (#80384) 2024-01-17 13:33:13 +01:00
Sofia Papagiannaki
d1dab5828d
Alerting: Update rule API to address folders by UID (#74600)
* Change ruler API to expect the folder UID as namespace

* Update example requests

* Fix tests

* Update swagger

* Modify FIle field in /api/prometheus/grafana/api/v1/rules

* Fix ruler export

* Modify folder in responses to be formatted as <parent UID>/<title>

* Add alerting test with nested folders

* Apply suggestion from code review

* Alerting: use folder UID instead of title in rule API (#77166)

Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>

* Drop a few more latent uses of namespace_id

* move getNamespaceKey to models package

* switch GetAlertRulesForScheduling to use folder table

* update GetAlertRulesForScheduling to return folder titles in format `parent_uid/title`.

* fi tests

* add tests for GetAlertRulesForScheduling when parent uid

* fix integration tests after merge

* fix test after merge

* change format of the namespace to JSON array

this is needed for forward compatibility, when we migrate to full paths

* update EF code to decode nested folder

---------

Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
Co-authored-by: Virginia Cepeda <virginia.cepeda@grafana.com>
Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>
Co-authored-by: Alex Weaver <weaver.alex.d@gmail.com>
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
2024-01-17 11:07:39 +02:00
Julien Duchesne
2fb03dfa56
fix(swagger): Mute Timing PUT OK status is 202 (#80459) 2024-01-12 16:58:20 -05:00
Yuri Tseretyan
4479e7218d
Alerting: MuteTiming service return errutil + GetTiming by name (#79772)
* add get mute timing by name to MuteTimingService
* update get mute timing request handler to use the service method

* replace validation, uniqueness and used errors with errutils
* update mute timing methods return errutil responses
* use the term "time interval" in errors bevause mute timings are deprecated in Alertmanager and will be replaced by time intervals in the future.

* update create and update methods to return struct instead of pointer
2024-01-12 21:23:44 +02:00
idafurjes
cb419e799b
Remove folderid service test (#80433)
* Remove FolderID from service tests

* Add models

* Add folderID pack to publicdashboard tests

* Remove folderID from dashboard tests

* Remove folderID from folders

* Remove folderID from ngalert tests

* Remove nolint comment

* Add back some tests after rebase
2024-01-12 16:43:39 +01:00
Matthew Jacobson
afa33f12b2
Alerting: Create alertingQueryOptimization feature flag for alert query optimization (#78932)
* Alerting: Create feature flag for alert query optimization

Adds a feature flag alertingQueryOptimization for an already existing 
functionality: alert query optimization. This feature flag will now be disabled 
by default.
2024-01-10 15:52:58 -05:00
Matthew Jacobson
f365d35cf8
Alerting: Show warning when query optimized (#78751)
* Alerting: Show warning when query optimized

* Use frame.AppendNotices

* Improve warning to include why and a prompt for action
2024-01-10 14:40:00 -05:00
Matthew Jacobson
1d4419fbe4
Alerting: Fix NoData & Error alerts not resolving when rule is reset (#80184)
* Alerting: Fix NoData & Error alerts not resolving when rule is reset

On rule reset, when creating the PostableAlerts StateToPostableAlert did not
attach the correct NoData/Error alertname and rulename labels to expire/resolve
the active alerts when the previous cached state was NoData/Error.
2024-01-09 14:47:19 -05:00
Matthew Jacobson
aa03b8f8a7
Alerting: Guided legacy alerting upgrade dry-run (#80071)
This PR has two steps that together create a functional dry-run capability for the migration.

By enabling the feature flag alertingPreviewUpgrade when on legacy alerting it will:
    a. Allow all Grafana Alerting background services except for the scheduler to start (multiorg alertmanager, state manager, routes, …).
    b. Allow the UI to show Grafana Alerting pages alongside legacy ones (with appropriate in-app warnings that UA is not actually running).
    c. Show a new “Alerting Upgrade” page and register associated /api/v1/upgrade endpoints that will allow the user to upgrade their organization live without restart and present a summary of the upgrade in a table.
2024-01-05 18:19:12 -05:00
Santiago
1f6575e65e
Alerting: Test MOA in remote secondary mode (#79828) 2024-01-05 11:05:27 +01:00
Alexander Weaver
cf8e8852c3
Alerting: Drop NamespaceID from responses on unstable ngalert API endpoints in favor of NamespaceUID (#79359)
* Drop from API response

* Drop from swagger docs

* Drop from integration tests

* regenerate public swagger docs

* Drop from frontend

* Drop asserts for namespaceID field
2023-12-15 11:06:53 -06:00
Julien Duchesne
884e0427e6
ngalert openapi: Add X-Disable-Provenance to missing operations (#79278)
Swagger(ngalert): Add `X-Disable-Provenance` to missing operations
I added all functions that call the `determineProvenance` function

Schema changes are from:
`make` in `pkg/services/ngalert/api/tooling`
`make swagger-clean && make openapi3-gen` in root
2023-12-13 10:55:59 -05:00
Alexander Weaver
aa63e91a43
Alerting: Use mux router to match hooks, add support for path variables and methods (#79345)
* Use a router inside hooks rather than plain string matching

* Add test for mismatched method
2023-12-12 14:43:11 -06:00
Julien Duchesne
f977e3faf5
ngalert swagger: Fix status code (#79415)
This endpoint returns a 202, not a 204
Let me know if we should instead change the response of the API
2023-12-12 13:40:36 -05:00
Santiago
57e0d6bcb5
Chore: Simplify function signature for GetLatestAlertmanagerConfiguration (#79392) 2023-12-12 13:49:54 +01:00
Yuri Tseretyan
8af08d0df2
Alerting: Add export of mute timings to file provisioning formats (#79225)
* add export of mute timings to file provisioning formats
* support export of mute timings to HCL
2023-12-11 21:36:51 -05:00
Alexander Weaver
b867505bd4
alerting: Add tests for hooks (#79284)
Add tests for hooks
2023-12-11 13:20:48 -06:00
Yuri Tseretyan
2be7605794
Alerting: Fix fine-grained rule access control to use 403 for authorization error (#79239)
* use 403 for authorization error
* update silences API
* add ForbiddenError to rule API responses
2023-12-07 13:43:58 -05:00
Yuri Tseretyan
7e331c8507
Alerting: Support for condition field in /api/v1/eval (#79032)
Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>
2023-12-06 11:28:43 -05:00
Rodrigo Villablanca
ab83bc7346
Alerting: Fix export of notification policy to JSON (#78021)
* Export Notification Policy correctly (#78020)

The JSON version of an exported Notification Policy now
inline correctly the policy in the same way the Yaml version
does.

Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
2023-12-04 16:57:37 -05:00
Julien Duchesne
3c51190392
ngalert make: Support GNU install on Darwin (#78482)
* ngalert `make`: Support GNU install on Darwin
Currently, the Makefile assumes that Darwin is using the Mac version of `sed`
I have the GNU version, so it failed. With this PR, it checks which version is installed
I also called `make` and there are some changes that came out of it

* swagger-gen
2023-12-04 10:11:39 -05:00
Yuri Tseretyan
64feeddc23
Alerting: Update rule access control to return errutil errors (#78284)
* update rule access control to return errutil errors
* use alerting in msgID
2023-12-02 01:42:11 +02:00
Alexander Weaver
ab0ef5276f
Alerting: Decouple quota configuration logic from API interfaces and add tests (#78930)
* Separate usage reporter from API

* Extract quota registration

* Decouple from API store interface

* Move to ngalert package and add tests

* linter
2023-12-01 10:47:19 -06:00
Matthew Jacobson
ce90a1f2be
Alerting: Apply query optimization to eval endpoints (#78566)
* Alerting: Apply query optimization to eval endpoints

Previously, query optimization was applied to alert queries when scheduled but
not when ran through `api/v1/eval` or `/api/v1/rule/test/grafana`. This could
lead to discrepancies between preview and scheduled alert results.
2023-11-28 19:44:28 -05:00
Kat Yang
2f2ce3edbb
Chore: Deprecate ID from Folder (#78281)
* Chore: Deprecate ID from Folder

* chore: add more linter comments

* chore: add missing lint comment
2023-11-20 15:44:51 -05:00
Yuri Tseretyan
7cec741bae
Alerting: Extract alerting rules authorization logic to a service (#77006)
* extract alerting authorization logic to separate package
* convert authorization logic to service
2023-11-15 18:54:54 +02:00
Ryan McKinley
f69fd3726b
FeatureToggles: Add context and and an explicit global check (#78081) 2023-11-14 12:50:27 -08:00
Jo
580477bf8e
NGAlerting: Use identity.Requester interface instead of SignedInUser (#76360)
* unfurl SignedInUserAttrs services

* replace signedInUser with Requester

replace signedInUser with requester

* fix tests

* linting

---------

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
2023-11-14 14:47:34 +00:00
Yuri Tseretyan
85425b2194
Alerting: Fix flaky test TestExportRules (#77519)
* fix test to correclty mock data store

* Update pkg/services/ngalert/api/api_ruler_export_test.go

Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com>

* Update pkg/services/ngalert/api/api_ruler_export_test.go

---------

Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com>
2023-11-01 21:35:04 +02:00
Kyle Brandt
e4d1fdc3d0
Errors: Make errors the same in dev as prod (#77366)
When running in dev mode, error messages would contain an additional "error" property alongside "message". Since this causes confusion, that has been removed and now error messages are the same both modes (using "message").
2023-10-30 14:06:26 -04:00
Yuri Tseretyan
48b55f39bf
Alerting: Add support for responders to Opsgenie integration (#77159)
* add support for responders in opsgenie UI config
* update export model

Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>
2023-10-27 13:06:46 -04:00
Santiago
f9fc2e4568
Alerting: Remove ConfigHash() from the Alertmanager interface (#77134) 2023-10-25 17:11:53 +02:00
Alexander Weaver
39599fa7f7
Alerting: Alert rule constraint violations return as 400s in provisioning API (#76396)
Constraint violations become 400s
2023-10-23 10:28:40 -05:00
Santiago
a60ec150f9
Alerting: Fetch receivers from remote Alertmanager (#76841)
* Alerting: fetch receivers from remote Alertmanager

* make linter happy

* change require.Eventually() timeout and tick
2023-10-20 11:34:17 +02:00
Steve Simpson
a0476741f2
Alerting: Fix HCL export for alerts with non-zero "for" field. (#76739)
* Alerting: Fix HCL export for alerts with non-zero "for" field.

Fixes #76734

* fix tests

---------

Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
2023-10-20 11:09:08 +02:00
Santiago
61cb26711e
Alerting: Fetch alerts from a remote Alertmanager (#75844)
* Alerting: post alerts to the remote Alertmanager and fetch them

* fix broken tests

* Alerting: Add Mimir Backend image to devenv (blocks)

* add alerting as code owner for mimir_backend block

* Alerting: Use Mimir image to run integration tests for the remote Alertmanager

* skip integration test when running all tests

* skipping integration test when no Alertmanager URL is provided

* fix bad host for mimir_backend

* remove basic auth testing until we have an nginx image in our CI

* add integration tests for alerts

* fix tests

* change SendCtx -> Send, add context.Context to Send, fix CI

* add reover() for functions from the Prometheus Alertmanager HTTP client that could panic

* add TODO to implement PutAlerts in a way that mimicks what Prometheus does

* fix log format
2023-10-19 11:27:37 +02:00
Yuri Tseretyan
372082d254
Alerting: Export of contact points to HCL (#75849)
* add compat layer to convert from Export model to "new" API models
2023-10-12 22:33:57 +01:00
Yuri Tseretyan
c4ac4eb41b
Alerting: Export of notification policies to HCL (#76411) 2023-10-12 12:10:08 -04:00
Matthew Jacobson
82f3127e23
Alerting: Move legacy alert migration from sqlstore migration to service (#72702) 2023-10-12 13:43:10 +01:00
Alexander Weaver
f6649d7a97
Revert "Alerting: Remove vendored models in migration service" (#76387)
Revert "Alerting: Remove vendored models in migration service (#74503)"

This reverts commit 6a8649d544.
2023-10-11 14:21:21 -05:00
Matthew Jacobson
6a8649d544
Alerting: Remove vendored models in migration service (#74503)
This PR replaces the vendored models in the migration with their equivalent ngalert models. It also replaces the raw SQL selects and inserts with service calls.

It also fills in some gaps in the testing suite around:

    - Migration of alert rules: verifying that the actual data model (queries, conditions) are correct 9a7cfa9
    - Secure settings migration: verifying that secure fields remain encrypted for all available notifiers and certain fields migrate from plain text to encrypted secure settings correctly e7d3993

Replacing the checks for custom dashboard ACLs will be replaced in a separate targeted PR as it will be complex enough alone.
2023-10-11 17:22:09 +01:00
George Robinson
05e12e787b
Alerting: Add provenance field to /api/v1/provisioning/alert-rules (#76252)
This commit adds the missing Provenance field to responses for
/api/v1/provisioning/alert-rules.
2023-10-11 14:51:20 +01:00
Jo
dcd0c6b11e
Identity: Unfurl OrgID in pkg/services to allow using identity.Requester interface (#76113)
Unfurl OrgID in pkg/services to allow using identity.Requester interface
2023-10-09 10:40:19 +02:00
Yuri Tseretyan
2497db4bd6
Alerting: Add UID of rules to response that were affected by update group request (#75985)
* update storage's method InstertRules to return ids of added rules as slice to keep the same order as rules in the argument
* schematize response of update rule group endpoint, add created, updated, deleted fields that contain UID of affected rules.
* update integration tests to use the new fields
2023-10-07 01:11:24 +03:00
Yuri Tseretyan
0a50ca7231
Alerting: Let users with regular permissions access export endpoints (#76082)
let users with regular permissions access export endpoints
2023-10-06 14:48:20 -04:00
Yuri Tseretyan
51499d7763
Alerting: Update alert rule export models to omit default values (#75918)
* do not include rule uid in response if it's empty
* make some fields of export models nillable
2023-10-05 15:16:44 -04:00