Scopes: Adapt for new API (#87841)

* Implement changes for new Scopes API

* Update from linkID to linkId

* Fixes

* Fix tests

* prom/scopes: change query model to recieve []ScopeSpec

* Move to basic backend service

---------

Co-authored-by: Kyle Brandt <kyle@grafana.com>
This commit is contained in:
Bogdan Matei
2024-05-15 16:28:09 +03:00
committed by GitHub
co-authored by Kyle Brandt
parent 6c1e9a9717
commit 6127dfd322
14 changed files with 665 additions and 331 deletions
+4 -8
View File
@@ -12,7 +12,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
sdkapi "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1"
"github.com/prometheus/prometheus/model/labels"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
@@ -67,7 +66,7 @@ type PrometheusQueryProperties struct {
LegendFormat string `json:"legendFormat,omitempty"`
// A set of filters applied to apply to the query
Scope *ScopeSpec `json:"scope,omitempty"`
Scopes []ScopeSpec `json:"scopes,omitempty"`
// Additional Ad-hoc filters that take precedence over Scope on conflict.
AdhocFilters []ScopeFilter `json:"adhocFilters,omitempty"`
@@ -167,11 +166,8 @@ type Query struct {
RangeQuery bool
ExemplarQuery bool
UtcOffsetSec int64
Scope *ScopeSpec
}
type Scope struct {
Matchers []*labels.Matcher
Scopes []ScopeSpec
}
// This internal query struct is just like QueryModel, except it does not include:
@@ -214,8 +210,8 @@ func Parse(span trace.Span, query backend.DataQuery, dsScrapeInterval string, in
if enableScope {
var scopeFilters []ScopeFilter
if model.Scope != nil {
scopeFilters = model.Scope.Filters
for _, scope := range model.Scopes {
scopeFilters = append(scopeFilters, scope.Filters...)
}
if len(scopeFilters) > 0 {
+49 -45
View File
@@ -162,55 +162,59 @@
},
"additionalProperties": false
},
"scope": {
"scopes": {
"description": "A set of filters applied to apply to the query",
"type": "object",
"required": [
"title",
"type",
"description",
"category",
"filters"
],
"properties": {
"category": {
"type": "string"
},
"description": {
"type": "string"
},
"filters": {
"type": "array",
"items": {
"description": "ScopeFilter is a hand copy of the ScopeFilter struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix)",
"type": "object",
"required": [
"key",
"value",
"operator"
],
"properties": {
"key": {
"type": "string"
"type": "array",
"items": {
"description": "ScopeSpec is a hand copy of the ScopeSpec struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix)",
"type": "object",
"required": [
"title",
"type",
"description",
"category",
"filters"
],
"properties": {
"category": {
"type": "string"
},
"description": {
"type": "string"
},
"filters": {
"type": "array",
"items": {
"description": "ScopeFilter is a hand copy of the ScopeFilter struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix)",
"type": "object",
"required": [
"key",
"value",
"operator"
],
"properties": {
"key": {
"type": "string"
},
"operator": {
"type": "string"
},
"value": {
"type": "string"
}
},
"operator": {
"type": "string"
},
"value": {
"type": "string"
}
},
"additionalProperties": false
"additionalProperties": false
}
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
},
"additionalProperties": false
"additionalProperties": false
}
},
"timeRange": {
"description": "TimeRange represents the query range\nNOTE: unlike generic /ds/query, we can now send explicit time values in each query\nNOTE: the values for timeRange are not saved in a dashboard, they are constructed on the fly",
+49 -45
View File
@@ -172,55 +172,59 @@
},
"additionalProperties": false
},
"scope": {
"scopes": {
"description": "A set of filters applied to apply to the query",
"type": "object",
"required": [
"title",
"type",
"description",
"category",
"filters"
],
"properties": {
"category": {
"type": "string"
},
"description": {
"type": "string"
},
"filters": {
"type": "array",
"items": {
"description": "ScopeFilter is a hand copy of the ScopeFilter struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix)",
"type": "object",
"required": [
"key",
"value",
"operator"
],
"properties": {
"key": {
"type": "string"
"type": "array",
"items": {
"description": "ScopeSpec is a hand copy of the ScopeSpec struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix)",
"type": "object",
"required": [
"title",
"type",
"description",
"category",
"filters"
],
"properties": {
"category": {
"type": "string"
},
"description": {
"type": "string"
},
"filters": {
"type": "array",
"items": {
"description": "ScopeFilter is a hand copy of the ScopeFilter struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix)",
"type": "object",
"required": [
"key",
"value",
"operator"
],
"properties": {
"key": {
"type": "string"
},
"operator": {
"type": "string"
},
"value": {
"type": "string"
}
},
"operator": {
"type": "string"
},
"value": {
"type": "string"
}
},
"additionalProperties": false
"additionalProperties": false
}
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
},
"additionalProperties": false
"additionalProperties": false
}
},
"timeRange": {
"description": "TimeRange represents the query range\nNOTE: unlike generic /ds/query, we can now send explicit time values in each query\nNOTE: the values for timeRange are not saved in a dashboard, they are constructed on the fly",
+50 -46
View File
@@ -8,7 +8,7 @@
{
"metadata": {
"name": "default",
"resourceVersion": "1713187448137",
"resourceVersion": "1715777575561",
"creationTimestamp": "2024-03-25T13:19:04Z"
},
"spec": {
@@ -85,55 +85,59 @@
"description": "Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series",
"type": "boolean"
},
"scope": {
"additionalProperties": false,
"scopes": {
"description": "A set of filters applied to apply to the query",
"properties": {
"category": {
"type": "string"
},
"description": {
"type": "string"
},
"filters": {
"items": {
"additionalProperties": false,
"description": "ScopeFilter is a hand copy of the ScopeFilter struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix)",
"properties": {
"key": {
"type": "string"
},
"operator": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"key",
"value",
"operator"
],
"type": "object"
"items": {
"additionalProperties": false,
"description": "ScopeSpec is a hand copy of the ScopeSpec struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix)",
"properties": {
"category": {
"type": "string"
},
"type": "array"
"description": {
"type": "string"
},
"filters": {
"items": {
"additionalProperties": false,
"description": "ScopeFilter is a hand copy of the ScopeFilter struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix)",
"properties": {
"key": {
"type": "string"
},
"operator": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"key",
"value",
"operator"
],
"type": "object"
},
"type": "array"
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
"required": [
"title",
"type",
"description",
"category",
"filters"
],
"type": "object"
},
"required": [
"title",
"type",
"description",
"category",
"filters"
],
"type": "object"
"type": "array"
}
},
"required": [