Prometheus: remove scope dependency (#84991)

* Prometheus: remove scope dependency
temp workaround

* depguard

* comment

* remove rules since they need a newer version of golangci-lint

---------

Co-authored-by: ismail simsek <ismailsimsek09@gmail.com>
This commit is contained in:
Kyle Brandt
2024-03-22 11:52:42 -04:00
committed by GitHub
parent 2f7fd729ef
commit 86a2a1a19b
2 changed files with 22 additions and 6 deletions

View File

@ -11,7 +11,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
"github.com/prometheus/prometheus/model/labels"
"github.com/grafana/grafana/pkg/apis/scope/v0alpha1"
"github.com/grafana/grafana/pkg/promlib/intervalv2"
)
@ -63,7 +62,25 @@ type PrometheusQueryProperties struct {
LegendFormat string `json:"legendFormat,omitempty"`
// ???
Scope *v0alpha1.ScopeSpec `json:"scope,omitempty"`
Scope *ScopeSpec `json:"scope,omitempty"`
}
// ScopeSpec is a hand copy of the ScopeSpec struct from pkg/apis/scope/v0alpha1/types.go
// to avoid import (temp fix)
type ScopeSpec struct {
Title string `json:"title"`
Type string `json:"type"`
Description string `json:"description"`
Category string `json:"category"`
Filters []ScopeFilter `json:"filters"`
}
// 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"`
}
// Internal interval and range variables
@ -136,7 +153,7 @@ type Query struct {
RangeQuery bool
ExemplarQuery bool
UtcOffsetSec int64
Scope *v0alpha1.ScopeSpec
Scope *ScopeSpec
}
type Scope struct {

View File

@ -3,12 +3,11 @@ package models
import (
"fmt"
"github.com/grafana/grafana/pkg/apis/scope/v0alpha1"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql/parser"
)
func ApplyQueryScope(rawExpr string, scope v0alpha1.ScopeSpec) (string, error) {
func ApplyQueryScope(rawExpr string, scope ScopeSpec) (string, error) {
expr, err := parser.ParseExpr(rawExpr)
if err != nil {
return "", err
@ -59,7 +58,7 @@ func ApplyQueryScope(rawExpr string, scope v0alpha1.ScopeSpec) (string, error) {
return expr.String(), nil
}
func scopeFiltersToMatchers(filters []v0alpha1.ScopeFilter) ([]*labels.Matcher, error) {
func scopeFiltersToMatchers(filters []ScopeFilter) ([]*labels.Matcher, error) {
matchers := make([]*labels.Matcher, 0, len(filters))
for _, f := range filters {
var mt labels.MatchType