25 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
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
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
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
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
e256f2d5e2 Alerting: Enable recording rules by default (#105603) 2025-06-02 10:56:05 +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
757be6365a CI: Bump golangci-lint to 2.0.2 (#103572) 2025-04-10 14:42:23 +02: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
756b45402c Alerting: Add rule_query_offset setting for Prometheus rule conversion (#102500)
Adds a new configuration option to specify a time offset for rule evaluation, which gets applied and saved during the Prometheus -> Grafana conversion. For example:

[unified_alerting.prometheus_conversion]
rule_query_offset = 1m

Changing this option affects only the rules imported after the change. If query_offset is set at the group level, it takes precedence over this setting.

Default is set to 1m.
2025-03-20 15:31:21 +01:00
1d0a86252e Alerting: Add target datasource support to Prometheus conversion (#102307) 2025-03-18 09:53:50 +01:00
85b0b47efd Alerting: Allow disabling provenance in the Prometheus conversion API (#101573)
When creating Grafana-managed alerts from Prometheus rule definitions with mimirtool or cortextool, the rules are marked as "provisioned" and are not editable in the Grafana UI. This PR allows changing this by providing an extra header: --extra-header="X-Disable-Provenance=true".

When provenance is disabled, we do not keep the original rule definition in YAML, so it is impossible to read it back using the Prometheus conversion API (mimirtool/cortextool). This is intentional because if we did keep it and the rule was later changed in the UI, its Prometheus YAML definition would no longer reflect the latest version of the alert rule, as it would be unchanged.
2025-03-11 19:53:28 +01:00
48ea9b08a2 Alerting: Add recording rule target datasource support to Prometheus conversion API (#101799)
What is this feature?

Adds target datasource UID to the recording rules so that they write to the same datasource used for alerting rule queries after the import.

Why do we need this feature?

Target datasourse support was added in #101678, and under a feature flag grafanaManagedRecordingRulesDatasources (#101778).

This PR makes the importing process:
    Check if the import contains recording rules
    Verify both recording rules and the grafanaManagedRecordingRulesDatasources feature flag are enabled
    If either check fails, return an error
    If both checks pass, create recording rules with the provided datasource UID set as both the query and target datasource
2025-03-07 16:56:24 +01:00
d44728f4e5 Alerting: Metric to count imported from Prometheus rules (#100847) 2025-03-05 14:02:28 +01:00
c7c68322b1 Alerting: Allow specifying a folder for Prometheus rule import (#101406)
What is this feature?

Allows the creation of alert rules with mimirtool in a specified folder.

Why do we need this feature?

Currently, the APIs for mimirtool create namespaces and rule groups in the root folder without the ability to set a custom folder. For example, it could be a special "Imported" folder, etc.

This PR makes it possible with a special header: mimirtool ... --extra-headers="X-Grafana-Alerting-Folder-UID=123". If it's not present, the root folder is used, otherwise, the specified one is used.

mimirtool does not support nested folder structures, while Grafana allows folder nesting. To keep compatibility, we return only direct child folders of the working folder (as namespaces) with rule groups and rules that are directly in these child folders as if there are no nested folders.

For example, given this folder structure in Grafana:

```
	grafana/
	├── production/
	│   ├── service1/
	│   │   └── alerts/
	│   └── service2/
	└── testing/
	    └── service3/
```

If the working folder is "grafana":

    Only namespaces "production" and "testing" are returned
    Only rule groups directly within these folders are included

If the working folder is "production":
   -  Only namespaces "service1" and "service2" are returned
    Only rule groups directly within these folders are included
2025-03-03 17:59:01 +01:00
d947433d19 Alerting: API to delete rule groups using mimirtool (#100687)
* Alerting: API to delete rule groups using mimirtool
2025-02-27 13:04:47 +01:00
6eb335a8ce Alerting: API to read rule groups using mimirtool (#100674) 2025-02-25 15:49:08 +01:00
b641fd64f9 Alerting: API to create rule groups using mimirtool (#100558)
What is this feature?

Adds an API endpoint to create alert rules with mimirtool:

- POST /convert/prometheus/config/v1/rules/{NamespaceTitle} - Accepts a single rule group in a Prometheus YAML format and creates or updates a Grafana rule group from it.

The endpoint uses the conversion package from #100224.

Key parts

The API works similarly to the provisioning API. If the rule does not exist, it will be created, otherwise updated. Any rules not present in the new group will be deleted, ensuring the group is fully synchronized with the provided configuration.

Since the API works with namespace titles (folders), the handler automatically creates a folder in the root based on the provided title if it does not exist. It also requires a special header, X-Grafana-Alerting-Datasource-UID. This header specifies which datasource to use for the new rules.

If the rule group's evaluation interval is not specified, it uses the DefaultRuleEvaluationInterval from settings.
2025-02-25 11:26:36 +01:00
9593e51da7 Alerting: conversion API structure (#100258) 2025-02-12 08:13:21 +01:00