Alerting: Add rule_matcher filter to Prometheus rules API (#115297)
**What is this feature?** Add `rule_matcher` filter to the Prometheus-compatible list rules API: `/api/prometheus/grafana/api/v1/rules`. It allows to filter rules by static labels (not by alert instance labels). **Special notes:** - Equality (`=`) and inequality (`!=`) matchers are pushed down to the database. Regex matchers (`=~`, `!~`) are applied in-memory at the API layer. - SQLite: Uses GLOB pattern matching - MySQL / PostgreSQL: Use JSON functions to compare label values --------- Co-authored-by: Konrad Lalik <konradlalik@gmail.com>
This commit is contained in:
co-authored by
Konrad Lalik
parent
c7c1dd4ead
commit
c0295d06a3
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
|
||||
"github.com/prometheus/alertmanager/pkg/labels"
|
||||
prommodels "github.com/prometheus/common/model"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
@@ -1012,6 +1013,10 @@ type ListAlertRulesQuery struct {
|
||||
SearchRuleGroup string
|
||||
|
||||
HasPrometheusRuleDefinition *bool
|
||||
|
||||
// LabelMatchers filters rules by their labels.
|
||||
// Only equality and inequality matchers are supported, no regex operators.
|
||||
LabelMatchers labels.Matchers
|
||||
}
|
||||
|
||||
type ListAlertRulesExtendedQuery struct {
|
||||
|
||||
Reference in New Issue
Block a user