Prometheus: (Experimental) Inject label matchers into queries (also change drone to fix ARM rpm build and Update Swagger) (#81396)

- Feature Toggle is `promQLScope`.
 - Query property is:

"scope": {
  "matchers": "{job=~\".*\"}"
 }

Misc:
 - Also updates drone GO version to address ARM bug https://github.com/golang/go/issues/58425
 - Also updates Swagger defs that were causing builds to fail

---------

Co-authored-by: Kevin Minehart <kmineh0151@gmail.com>
This commit is contained in:
Kyle Brandt
2024-01-29 22:22:17 +02:00
committed by GitHub
co-authored by Kevin Minehart
parent c2b64c6739
commit 43d0664340
19 changed files with 187 additions and 52 deletions
+20 -1
View File
@@ -2,12 +2,15 @@ package models
import (
"encoding/json"
"fmt"
"math"
"strconv"
"strings"
"time"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql/parser"
"github.com/grafana/grafana/pkg/tsdb/intervalv2"
"github.com/grafana/grafana/pkg/tsdb/prometheus/kinds/dataquery"
@@ -75,9 +78,14 @@ type Query struct {
RangeQuery bool
ExemplarQuery bool
UtcOffsetSec int64
Scope Scope
}
func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator intervalv2.Calculator, fromAlert bool) (*Query, error) {
type Scope struct {
Matchers []*labels.Matcher
}
func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator intervalv2.Calculator, fromAlert bool, enableScope bool) (*Query, error) {
model := &QueryModel{}
if err := json.Unmarshal(query.JSON, model); err != nil {
return nil, err
@@ -99,6 +107,17 @@ func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator
dsScrapeInterval,
timeRange,
)
var matchers []*labels.Matcher
if enableScope && model.Scope != nil && model.Scope.Matchers != "" {
matchers, err = parser.ParseMetricSelector(model.Scope.Matchers)
if err != nil {
return nil, fmt.Errorf("failed to parse metric selector %v in scope", model.Scope.Matchers)
}
expr, err = ApplyQueryScope(expr, matchers)
if err != nil {
return nil, err
}
}
var rangeQuery, instantQuery bool
if model.Instant == nil {
instantQuery = false