Browse Source

Remove `NewPossibleNonCounterInfo` and minimise creating empty annotations (#13012)

* Remove NewPossibleNonCounterInfo until it can be made more efficient, and avoid creating empty annotations as much as possible

Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
pull/13028/head
zenador 1 year ago committed by GitHub
parent
commit
80e977aae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      CHANGELOG.md
  2. 2
      promql/engine.go
  3. 14
      promql/functions.go
  4. 3
      tsdb/db_test.go
  5. 3
      util/annotations/annotations.go

4
CHANGELOG.md

@ -1,5 +1,9 @@
# Changelog # Changelog
## unreleased
* [ENHANCEMENT] PromQL: Reduce inefficiency introduced by warnings/annotations, and temporarily remove NewPossibleNonCounterInfo. #13012
## 2.48.0-rc.0 / 2023-10-10 ## 2.48.0-rc.0 / 2023-10-10
* [CHANGE] Remote-write: respect Retry-After header on 5xx errors. #12677 * [CHANGE] Remote-write: respect Retry-After header on 5xx errors. #12677

2
promql/engine.go

@ -2535,7 +2535,7 @@ type groupedAggregation struct {
func (ev *evaluator) aggregation(e *parser.AggregateExpr, grouping []string, param interface{}, vec Vector, seriesHelper []EvalSeriesHelper, enh *EvalNodeHelper) (Vector, annotations.Annotations) { func (ev *evaluator) aggregation(e *parser.AggregateExpr, grouping []string, param interface{}, vec Vector, seriesHelper []EvalSeriesHelper, enh *EvalNodeHelper) (Vector, annotations.Annotations) {
op := e.Op op := e.Op
without := e.Without without := e.Without
annos := annotations.Annotations{} var annos annotations.Annotations
result := map[uint64]*groupedAggregation{} result := map[uint64]*groupedAggregation{}
orderedResult := []*groupedAggregation{} orderedResult := []*groupedAggregation{}
var k int64 var k int64

14
promql/functions.go

@ -77,7 +77,7 @@ func extrapolatedRate(vals []parser.Value, args parser.Expressions, enh *EvalNod
resultHistogram *histogram.FloatHistogram resultHistogram *histogram.FloatHistogram
firstT, lastT int64 firstT, lastT int64
numSamplesMinusOne int numSamplesMinusOne int
annos = annotations.Annotations{} annos annotations.Annotations
) )
// We need either at least two Histograms and no Floats, or at least two // We need either at least two Histograms and no Floats, or at least two
@ -88,14 +88,6 @@ func extrapolatedRate(vals []parser.Value, args parser.Expressions, enh *EvalNod
return enh.Out, annos.Add(annotations.NewMixedFloatsHistogramsWarning(metricName, args[0].PositionRange())) return enh.Out, annos.Add(annotations.NewMixedFloatsHistogramsWarning(metricName, args[0].PositionRange()))
} }
if isCounter && metricName != "" && len(samples.Floats) > 0 &&
!strings.HasSuffix(metricName, "_total") &&
!strings.HasSuffix(metricName, "_sum") &&
!strings.HasSuffix(metricName, "_count") &&
!strings.HasSuffix(metricName, "_bucket") {
annos.Add(annotations.NewPossibleNonCounterInfo(metricName, args[0].PositionRange()))
}
switch { switch {
case len(samples.Histograms) > 1: case len(samples.Histograms) > 1:
numSamplesMinusOne = len(samples.Histograms) - 1 numSamplesMinusOne = len(samples.Histograms) - 1
@ -642,7 +634,7 @@ func funcQuantileOverTime(vals []parser.Value, args parser.Expressions, enh *Eva
return enh.Out, nil return enh.Out, nil
} }
annos := annotations.Annotations{} var annos annotations.Annotations
if math.IsNaN(q) || q < 0 || q > 1 { if math.IsNaN(q) || q < 0 || q > 1 {
annos.Add(annotations.NewInvalidQuantileWarning(q, args[0].PositionRange())) annos.Add(annotations.NewInvalidQuantileWarning(q, args[0].PositionRange()))
} }
@ -1105,7 +1097,7 @@ func funcHistogramFraction(vals []parser.Value, args parser.Expressions, enh *Ev
func funcHistogramQuantile(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) (Vector, annotations.Annotations) { func funcHistogramQuantile(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) (Vector, annotations.Annotations) {
q := vals[0].(Vector)[0].F q := vals[0].(Vector)[0].F
inVec := vals[1].(Vector) inVec := vals[1].(Vector)
annos := annotations.Annotations{} var annos annotations.Annotations
if math.IsNaN(q) || q < 0 || q > 1 { if math.IsNaN(q) || q < 0 || q > 1 {
annos.Add(annotations.NewInvalidQuantileWarning(q, args[0].PositionRange())) annos.Add(annotations.NewInvalidQuantileWarning(q, args[0].PositionRange()))

3
tsdb/db_test.go

@ -1933,7 +1933,8 @@ func TestQuerierWithBoundaryChunks(t *testing.T) {
// The requested interval covers 2 blocks, so the querier's label values for blockID should give us 2 values, one from each block. // The requested interval covers 2 blocks, so the querier's label values for blockID should give us 2 values, one from each block.
b, ws, err := q.LabelValues(ctx, "blockID") b, ws, err := q.LabelValues(ctx, "blockID")
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, annotations.Annotations{}, ws) var nilAnnotations annotations.Annotations
require.Equal(t, nilAnnotations, ws)
require.Equal(t, []string{"1", "2"}, b) require.Equal(t, []string{"1", "2"}, b)
} }

3
util/annotations/annotations.go

@ -50,6 +50,9 @@ func (a *Annotations) Add(err error) Annotations {
// the first in-place, and returns the merged first Annotation for convenience. // the first in-place, and returns the merged first Annotation for convenience.
func (a *Annotations) Merge(aa Annotations) Annotations { func (a *Annotations) Merge(aa Annotations) Annotations {
if *a == nil { if *a == nil {
if aa == nil {
return nil
}
*a = Annotations{} *a = Annotations{}
} }
for key, val := range aa { for key, val := range aa {

Loading…
Cancel
Save