[v11.0.x] Scopes: Add Filtering for ScopeDashoardBinding and Update Prometheus for ScopeFilterOperator Changes (#86326)

Scopes: Add Filtering for ScopeDashoardBinding and Update Prometheus for ScopeFilterOperator Changes (#85284)

(cherry picked from commit 136f8e6f0c)

Co-authored-by: Kyle Brandt <kyle@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-04-16 14:46:21 +01:00
committed by GitHub
co-authored by Kyle Brandt
parent 41d7cba970
commit 67c976366e
6 changed files with 61 additions and 21 deletions
+14 -3
View File
@@ -80,11 +80,22 @@ type ScopeSpec struct {
// ScopeFilter is a hand copy of the ScopeFilter struct from pkg/apis/scope/v0alpha1/types.go
// to avoid import (temp fix)
type ScopeFilter struct {
Key string `json:"key"`
Value string `json:"value"`
Operator string `json:"operator"`
Key string `json:"key"`
Value string `json:"value"`
Operator FilterOperator `json:"operator"`
}
// FilterOperator is a hand copy of the ScopeFilter struct from pkg/apis/scope/v0alpha1/types.go
type FilterOperator string
// Hand copy of enum from pkg/apis/scope/v0alpha1/types.go
const (
FilterOperatorEquals FilterOperator = "equals"
FilterOperatorNotEquals FilterOperator = "not-equals"
FilterOperatorRegexMatch FilterOperator = "regex-match"
FilterOperatorRegexNotMatch FilterOperator = "regex-not-match"
)
// Internal interval and range variables
const (
varInterval = "$__interval"
+4 -4
View File
@@ -63,13 +63,13 @@ func scopeFiltersToMatchers(filters []ScopeFilter) ([]*labels.Matcher, error) {
for _, f := range filters {
var mt labels.MatchType
switch f.Operator {
case "=":
case FilterOperatorEquals:
mt = labels.MatchEqual
case "!=":
case FilterOperatorNotEquals:
mt = labels.MatchNotEqual
case "=~":
case FilterOperatorRegexMatch:
mt = labels.MatchRegexp
case "!~":
case FilterOperatorRegexNotMatch:
mt = labels.MatchNotRegexp
default:
return nil, fmt.Errorf("unknown operator %q", f.Operator)