732 Commits

Author SHA1 Message Date
b93cde0adb Alerting: Use default identifier for extra configs in Alertmanager API (#107049) 2025-06-26 12:44:49 +02:00
3b45f7daa5 Alerting: Fix flaky test (#107090) 2025-06-24 11:25:51 +02:00
700c9a857c Alerting: Return extra alertmanager config as a string for mimirtool (#106959) 2025-06-19 01:12:26 +02:00
4b46da9214 Alerting: Hide extra Prometheus configuration secrets (#106916) 2025-06-18 17:01:19 +02:00
426c334973 Alerting: API to create extra Alertmanager configurations (#106904)
What is this feature?

Implements the POST endpoint for deleting imported Mimir Alertmanager configurations:

    POST /api/convert/api/v1/alerts

The API endpoint creates the extra Alertmanager configuration with the provided identifier and matchers.
2025-06-18 15:05:06 +02:00
def5d889d0 Alerting: API to delete extra Alertmanager configurations (#106892) 2025-06-18 12:37:56 +02:00
8c6df8b449 Alerting: Add support for retrieving imported Prometheus Alertmanager configurations (#106864) 2025-06-18 10:49:40 +02:00
5a78ce8a4b Alerting: Support saving extra Mimir configurations (#106721) 2025-06-17 23:33:16 +02:00
74e800e427 Alerting: Add provenance to Prometheus API (#106596)
This commit adds provenance information to the Prometheus API in the ngalert service to enable compatibility with the new alert list page.
2025-06-17 23:31:42 +02:00
0e6c7f84c3 Alerting: Add filters for health and contact point in Prometheus Rules api (#106580)
This adds the ability to filter rules with the prometheus compatible api using:
1. `receiver_name` to filter by contact point name
2. `health` to filter by the health status of the rule (one of `ok`, `error`, `nodata`, or `unknown`)

This also ensures that groups with no rules (due to filters) are not returned.
2025-06-17 16:57:03 +02:00
b0ff51a903 Alerting: Support for Mimir configuration in Grafana Alertmanager (#106402) 2025-06-13 16:32:23 +02:00
0016b57486 Alerting: Add OAuth2 Support for Webhook Receiver (#106302)
* Add to available channels

* Export

* Fix bug in deeply nested secrets

BE: Slice re-use bug when traversing deeply.

FE: Only at most one level of nesting was being taken into account
when determining secureFields keys. This change adds a new field on
NotificationChannelOption: secureFieldKey. This is populated on API GET via
transform. This change gives us the option to hardcode secureFieldKey in the
backend and no longer calculate the key via settings topology.

* Update grafana/alerting to 3e20fda3b872

* Prettier

* Linting

* Fix IntegrationConfig test to catch secure field mismatch
2025-06-12 23:00:09 +02:00
eaac4a69fb Alerting: Empty endpoints to manage alertmanager configurations (#106546) 2025-06-11 13:45:02 +02:00
a4fa8ab891 Alerting: Empty endpoint to load alertmanager config with mimirtool (#106266) 2025-06-10 11:35:57 +02:00
1df888c517 Alerting: Provisioning API returns 403 on quota exceeded for rule group PUT (#106409) 2025-06-09 11:12:22 +01:00
f7a52bc04e Alerting: Fix group-level labels and query_offset in the import API (#106379)
What is this feature?

Fixes a bug when group-level query_offset and labels parameters are ignored and not saved

Why do we need this feature?

In the import API Prometheus YAML rule definitions are supported:

groups:
  - name: group-1
    interval: 1m
    query_offset: 10m
    labels:
      severity: "warning"
    rules:
      - alert: Alert 0 > 0
        expr: vector(0) > 0

But applying group-level labels and query_offset is broken and they are not saved right now because during the conversion of the API model to PrometheusRuleGroup they aren't saved to the new structure.
2025-06-06 11:21:39 +02:00
941162ca79 Alerting: Optimize prometheus api permission checks (#106299)
* Alerting: Optimize prometheus api permission checks

This improves the performance of the Prometheus API by performing the permission checks for rule read permission in a folder upfront, rather than checking permissions for each rule group individually. This reduces the number of permission checks and should speed up the API response time.

* refactor vars

---------

Co-authored-by: Konrad Lalik <konradlalik@gmail.com>
2025-06-05 09:43:06 -04:00
da88e5912f Alerting: Evaluate all imported from Prometheus rules sequentially (#106295)
What is this feature?

Makes all alert rules imported from a Prometheus YAML or Prometheus-compatible data source evaluate sequentially.

Why do we need this feature?

Currently only alert rules [imported via the API](https://grafana.com/docs/grafana-cloud/alerting-and-irm/alerting/alerting-rules/alerting-migration/migration-api/) are evaluated sequentially, because only they have the original alert rule definition in YAML. But alert rules can be imported [in the UI, and from a YAML file](https://grafana.com/docs/grafana-cloud/alerting-and-irm/alerting/alerting-rules/alerting-migration/), and they won't be evaluated sequentially which can lead to issues with recording rules.
2025-06-05 12:08:44 +02:00
33298550b4 Update Alerting module (#106272)
* set kind in TemplateDefinition
2025-06-04 16:05:05 -04:00
e256f2d5e2 Alerting: Enable recording rules by default (#105603) 2025-06-02 10:56:05 +02:00
b51d70aad9 Alerting: Fix swagger generation (#106106) 2025-05-28 10:15:11 +02:00
36c31ce841 NGAlert: Revert change to use math/rand/v2 in tests (#105661) 2025-05-20 14:47:57 +02:00
c58ac15031 Alerting: Remove grafanaManagedRecordingRules feature flag (#105569) 2025-05-19 12:15:49 +02:00
2cddaf0781 RBAC: Remove dashboard and folder guardians (#104646)
* replace usage of folder guardians with access control evaluators

* remove NewByFolderUID guardian

* bring up to date

* fix test

* more test fixes, and don't fetch the folder before evaluating lib element access

* change what error is returned

* fix alerting test

* try to fix linter errors

* replace the use of newByFolder guardian with direct access control evaluator checks

* remove newByFolder guardian

* get rid of dashboard and folder guardians

* undo unwanted change

* undo unwanted change

* undo unwanted change

* update code owners
2025-05-19 09:48:16 +03:00
4b426238bd Dependencies: Bump github.com/openfga/openfga from v1.8.6 to v1.8.12 (#105193)
* Dependencies: Bump github.com/openfga/openfga from v1.8.6 to v1.8.12

* Linter: Replace x/exp/rand with math/rand/v2

* NGAlert: Fix test after linter fixes
2025-05-14 11:09:00 +03:00
9fe523b9e6 Alerting: API to pause all alert rules in a folder (#104674) 2025-05-13 17:04:01 +02:00
c17b019ab1 Alerting: Support simplified routing receivers in Prometheus conversion API (#105135)
Adds ability to set notifications settings using the Prometheus conversion API.

The API now supports a new optional header: X-Grafana-Alerting-Notification-Settings which can be used to specify notification settings.

The value of the header is the AlertRuleNotificationSettings structure in JSON:
mimirtool rules load alerts.yaml --extra-headers 'X-Grafana-Alerting-Notification-Settings: {"receiver": "my-webhook", "group_by": ["cluster", "pod"]}'
2025-05-12 22:07:02 +02:00
0ceea29787 Alerting: Remove alertingSimplifiedRouting feature toggle (#104980)
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
2025-05-09 16:30:56 +03:00
3e2296acd3 Alerting: Support for active time intervals in notification policies (#104252)
* add active_time_intervals to route model

* update k8s compat layer

* update notification policies service to validate active time intervals

* update integration tests

* update openapi

* add active time interval to model

* update route generator to include active time interval

* Update storage list and rename methods to handle active intervals

* update api model

* update provisioning and export models

* update ui to allow active timing config

* update i18n

* fix snapshots for ui tests

* run prettier

* Alerting: Active time intervals UI naming (#104402)

* update naming in UI

* update naming in the edit page title

* update translations

* update alerting module

---------

Signed-off-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
Co-authored-by: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com>
Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>
2025-05-07 19:19:33 -04:00
9f07e49cdd Alerting: Add extended definition to prometheus alert rules api (#103320)
* Alerting: Add extended definition to prometheus alert rules api

This adds `isPaused` and `notificationSettings` to the paginated rules api to enable the paginated view of GMA rules.

refactor: make alert rule status and state retrieval extensible

This lets us get status from other sources than the local ruler.

* update swagger spec

* add safety checks in test
2025-04-23 21:14:09 +01:00
5ddcac8678 Alerting: Add back time interval items to the API spec (#104306) 2025-04-22 14:57:04 -04:00
3a054d5e00 Alerting: Add FiredAt field to State (#104046)
* Add FiredAt field to the State

* Update featuretoggle files

* Fix lint errors

* Fix test compilation

* Remove random print line + formatting

* Address PR comments
2025-04-22 12:16:38 +01:00
163a8d5f0c NGAlert: Fix flaky test (#104070)
Fix flaky test

Co-authored-by: Marco de Abreu <18629099+marcoabreu@users.noreply.github.com>
2025-04-15 20:56:42 +01:00
54d4b7842b Alerting: Fix flaky tests (#104017)
Alerting: fix flaky tests

Some test conditions introduced in #103403 are flaky because they rely on random behavior of the generator.

Sometimes rules are generated with an updated by (which warrants the lookup of the users). This makes it so those tests which are checking the user lookup always have rules with updated by.
2025-04-15 08:15:29 +03:00
a5288db624 Alerting: Remove the POST endpoint for the internal Grafana Alertmanager config (#103819)
* Remove POST config for Grafana Alertmanager

* Delete auth + test for removed path

* Alerting: Remove check for `alertingApiServer` toggle in UI (#103805)

* Remove check for alertingApiServer in UI

* Update tests to no longer care about alertingApiServer

* Add contact points handlers now that we use alertingApiServer all the time

* Fix test broken from removing camelCase for UIDs

---------

Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
2025-04-11 17:38:53 -04:00
9e933882ed Alerting: Webhook Improvements - Templateable Payloads (#103818)
* Template editor syntax highlighting when preview is json-like

* Add new template editor language examples, snippets, and functions

* Use updated NewTemplate function

* Add new fields to webhook notifier

- CustomPayload
- ExtraHeaders

* Documentation

* Update grafana/alerting to in-progress PR (needs updating after merge)

* Fix integration test

* Remove docs reference to .Extra template context

No longer exists, was part of a previous iteration

* make update-workspace

* Update grafana/alerting to actual merged commit
2025-04-11 12:22:51 -04:00
9f9c4b3da3 Alerting: Template preview enhancements (#103817)
API Changes:

- Fixes validation in template CRUD API to be closer to how the running 
  alertmanager will use the template. Should remove some incorrect 
  validation errors.

- Adds some missing default placeholder labels to receiver testing that 
  are used during template testing but missing during receiver testing


Template Preview:

- Replaced basic preview with a readonly CodeEditor for better whitespace 
  and alignment clarity (also adds support for future syntax highlighting 
  in template previews for upcoming webhook payload templates)

Template Selector (Receiver Form):

- Refactored to use same components as Template editor for preview.
- Fixed preview to work with multi-definition templates
- Fixed copy to correctly copy the template contents instead of 
  {{ template "<name>" . }}.

Template Editor:

- Fixed detection of when to display functions vs snippets in multi-line 
  expressions
2025-04-11 09:27:19 -04:00
0a8dccc19a Alerting: New alert list filter improvements (#103107)
* Move filtering code to generators for performance reasons

Discarding rules and groups early in the iterable chain limits the number of promises we need to wait for which improves performance significantly

* Add error handling for generators

* Add support for data source filter for GMA rules

* search WIP fix

* Fix datasource filter

* Move filtering back to filtered rules hook, use paged groups for improved performance

* Add queriedDatasources field to grafana managed rules and update filtering logic to rely on it

- Introduced a new field `queriedDatasources` in the AlertingRule struct to track data sources used in rules.
- Updated the Prometheus API to populate `queriedDatasources` when creating alerting rules.
- Modified filtering logic in the ruleFilter function to utilize the new `queriedDatasources` field for improved data source matching.
- Adjusted related tests to reflect changes in rule structure and filtering behavior.

* Add FilterView performance logging

* Improve GMA Prometheus types, rename queried datasources property

* Use custom generator helpers for flattening and filtering rule groups

* Fix lint errors, add missing translations

* Revert test condition

* Refactor api prom changes

* Fix lint errors

* Update backend tests

* Refactor rule list components to improve error handling and data source management

- Enhanced error handling in FilterViewResults by logging errors before returning an empty iterable.
- Simplified conditional rendering in GrafanaRuleLoader for better readability.
- Updated data source handling in PaginatedDataSourceLoader and PaginatedGrafanaLoader to use new individual rule group generator.
- Renamed toPageless function to toIndividualRuleGroups for clarity in prometheusGroupsGenerator.
- Improved filtering logic in useFilteredRulesIterator to utilize a dedicated function for data source type validation.
- Added isRulesDataSourceType utility function for better data source type checks.
- Removed commented-out code in PromRuleDTOBase for cleaner interface definition.

* Fix abort controller on FilterView

* Improve generators filtering

* fix abort controller

* refactor cancelSearch

* make states exclusive

* Load full page in one loadResultPage call

* Update tests, update translations

* Refactor filter status into separate component

* hoist hook

* Use the new function for supported rules source type

---------

Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
2025-04-11 10:02:34 +02:00
032299011a Alerting: Relax permissions for access a rule (#103664)
This makes it so that it is:
- No longer required to have datasource permissions to delete a rule.
- No longer required to have datasource permissions to update non-query related fields of a rule.
2025-04-11 00:58:37 +01:00
fd6fd91115 Prometheus: Add support for cloud partners Prometheus data sources (#103482)
* wip

* Add prom flavor support for data source variables and export/import dashboards (#103321)

* add dashboard and data source var selection

* use match plugin id instead

* use updated matchpluginid

* formatting

* cleanup

* regex anchor

* update error msg

* Alerting: Clean up prometheus-flavored types and functions (#103703)

* clean up types and utility functions for dealing with
prometheus-flavored data sources

* Refactor alerting datasource types to use constants as source of truth

* Alerting: Clean up prometheus-flavored types and functions on the bac… (#103716)

Alerting: Clean up prometheus-flavored types and functions on the backend

* add matchPluginId tests

* Update matchPluginId func to bidirectional (#103746)

* update matchpluginid func to bidirectional

* lint

* formatting

* use actual isSupportedExternalRulesSourceType in test

* add tests in datasource_srv

* betterer

* remove type assertion

* remove unnecessary case

* use satisifies to not have to convert tuple to an array of string

* add prometheus_flavor test

---------

Co-authored-by: Andrew Hackmann <5140848+bossinc@users.noreply.github.com>
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
Co-authored-by: Alexander Akhmetov <me@alx.cx>
2025-04-10 12:49:11 -07:00
757be6365a CI: Bump golangci-lint to 2.0.2 (#103572) 2025-04-10 14:42:23 +02:00
97897b796e Alerting: Do not export MissingSeriesEvalsToResolve if it is not set (#103736) 2025-04-09 19:14:28 +02:00
babe188e31 Alerting: Fix path for cortex-style Prometheus namespaces conversion endpoint (#103655) 2025-04-09 10:40:22 +02:00
9bc4fbe900 alerting: batch user service calls (#103403)
* update alerting endpoints to batch requests to the user service via ListByIdOrUID
2025-04-07 07:33:15 -04:00
cf5da1d366 Alerting: Fix swagger in pkg/services/ngalert/api/tooling (#103500) 2025-04-07 12:38:07 +02:00
bdbe94abc8 Alerting: Remove alertingConversionAPI feature flag (#103380) 2025-04-05 09:27:02 +01:00
d8c5c2d3b8 K8s: Folders: Modify GetChildren to return only Folder References (#103072)
* Return FolderReference instead of Folder on GetChildren

Signed-off-by: Maicon Costa <maiconscosta@gmail.com>

---------

Signed-off-by: Maicon Costa <maiconscosta@gmail.com>
2025-04-02 01:30:17 -03:00
68d8810ecb Alerting: API to convert submitted Prometheus rules to GMA (#102231)
* placeholder commit

* Complete function in api_convert_prometheus.go

* MVP before extensive testing

* Cleanup

* Updated tests

* cleanup

* Fix random logs and lint

* Remove comment

* Fix errors after rebase

* Update test

* Update swagger

* swagger

* Refactor to accept groups in body

* Fix auth tests and some cleanup

* Some cleanup before refactoring

* Remove unnecessary fields

* Also refactor RouteConvertPrometheusPostRuleGroup

* Remove unused code

* Rebase + cleanup

* Update authorization_test

* address comments

* Regen swagger files

* Remove namespace and group filters

* Final comments
2025-03-27 15:30:11 +00:00
d0d7078953 App Platform: Remove mutable globals (#102962)
* App Platform: Remove mutable globals

* chore: clarify why this exists

* fix: support multi-tenant mode

* refactor: call builder providers directly

* CI: Force re-build
2025-03-27 15:46:09 +01:00
88d23fe5be Alerting: Remove transitional notifications API endpoints (#102713)
* Remove transitional notifications API endpoints

* Fix openapi spec

* Fix path test

* Remove API tests related to removed endpoints
2025-03-26 12:26:50 -04:00