mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 17:52:30 +08:00
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:
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
|
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
|
||||||
"github.com/prometheus/prometheus/model/labels"
|
"github.com/prometheus/prometheus/model/labels"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/apis/scope/v0alpha1"
|
|
||||||
"github.com/grafana/grafana/pkg/promlib/intervalv2"
|
"github.com/grafana/grafana/pkg/promlib/intervalv2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,7 +62,25 @@ type PrometheusQueryProperties struct {
|
|||||||
LegendFormat string `json:"legendFormat,omitempty"`
|
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
|
// Internal interval and range variables
|
||||||
@ -136,7 +153,7 @@ type Query struct {
|
|||||||
RangeQuery bool
|
RangeQuery bool
|
||||||
ExemplarQuery bool
|
ExemplarQuery bool
|
||||||
UtcOffsetSec int64
|
UtcOffsetSec int64
|
||||||
Scope *v0alpha1.ScopeSpec
|
Scope *ScopeSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
type Scope struct {
|
type Scope struct {
|
||||||
|
@ -3,12 +3,11 @@ package models
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/apis/scope/v0alpha1"
|
|
||||||
"github.com/prometheus/prometheus/model/labels"
|
"github.com/prometheus/prometheus/model/labels"
|
||||||
"github.com/prometheus/prometheus/promql/parser"
|
"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)
|
expr, err := parser.ParseExpr(rawExpr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -59,7 +58,7 @@ func ApplyQueryScope(rawExpr string, scope v0alpha1.ScopeSpec) (string, error) {
|
|||||||
return expr.String(), nil
|
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))
|
matchers := make([]*labels.Matcher, 0, len(filters))
|
||||||
for _, f := range filters {
|
for _, f := range filters {
|
||||||
var mt labels.MatchType
|
var mt labels.MatchType
|
||||||
|
Reference in New Issue
Block a user