Skip to content

Commit 32d0780

Browse files
committed
go.mod: upgrade Prometheus
Upgrade the Prometheus library and the corresponding code. Signed-off-by: Giedrius Statkevičius <[email protected]>
1 parent 088c133 commit 32d0780

File tree

8 files changed

+627
-266
lines changed

8 files changed

+627
-266
lines changed

engine/engine.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,11 @@ loop:
655655
})
656656
}
657657
}
658+
659+
_, keepHistograms := q.resultSort.(keepHistogramsSorter)
660+
if !keepHistograms {
661+
vector = filterFloats(vector)
662+
}
658663
sort.Slice(vector, q.resultSort.comparer(&vector))
659664
if vector.ContainsSameLabelset() {
660665
return newErrResult(ret, extlabels.ErrDuplicateLabelSet)

engine/engine_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,11 @@ sum by (grpc_method, grpc_code) (
18031803
http_requests_total{pod="nginx-4", series="2"} 5+2.4x50
18041804
http_requests_total{pod="nginx-5", series="2"} 8.4+2.3x50
18051805
http_requests_total{pod="nginx-6", series="2"} 2.3+2.3x50`,
1806-
query: `topk(1e+120, http_requests_total)`,
1806+
query: `
1807+
topk(
1808+
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
1809+
http_requests_total
1810+
)`,
18071811
start: time.Unix(0, 0),
18081812
end: time.Unix(3000, 0),
18091813
step: 2 * time.Second,

engine/sort.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const (
1919
sortOrderDesc sortOrder = true
2020
)
2121

22+
type keepHistogramsSorter interface {
23+
keepHistograms()
24+
}
25+
2226
type resultSorter interface {
2327
comparer(samples *promql.Vector) func(i, j int) bool
2428
}
@@ -43,6 +47,10 @@ type aggregateResultSort struct {
4347
type noSortResultSort struct {
4448
}
4549

50+
func (a aggregateResultSort) keepHistograms() {}
51+
52+
func (s noSortResultSort) keepHistograms() {}
53+
4654
func extractSortingLabels(f *parser.Call) []string {
4755
args := f.Args[1:]
4856

@@ -104,6 +112,17 @@ func valueCompare(order sortOrder, l, r float64) bool {
104112
return l > r
105113
}
106114

115+
// filterFloats filters out histogram samples from the vector in-place.
116+
func filterFloats(v promql.Vector) promql.Vector {
117+
floats := v[:0]
118+
for _, s := range v {
119+
if s.H == nil {
120+
floats = append(floats, s)
121+
}
122+
}
123+
return floats
124+
}
125+
107126
func (s sortFuncResultSort) comparer(samples *promql.Vector) func(i, j int) bool {
108127
return func(i, j int) bool {
109128
return valueCompare(s.sortOrder, (*samples)[i].F, (*samples)[j].F)

execution/aggregate/count_values.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import (
1111
"sync"
1212
"time"
1313

14+
"github.com/efficientgo/core/errors"
15+
prommodel "github.com/prometheus/common/model"
16+
"github.com/prometheus/prometheus/model/labels"
17+
1418
"github.com/thanos-io/promql-engine/execution/model"
1519
"github.com/thanos-io/promql-engine/execution/telemetry"
1620
"github.com/thanos-io/promql-engine/query"
17-
18-
"github.com/prometheus/prometheus/model/labels"
1921
)
2022

2123
type countValuesOperator struct {
@@ -116,6 +118,10 @@ func (c *countValuesOperator) Next(ctx context.Context) ([]model.StepVector, err
116118
}
117119

118120
func (c *countValuesOperator) initSeriesOnce(ctx context.Context) error {
121+
if !prommodel.LabelName(c.param).IsValid() {
122+
return errors.Newf("invalid label name %q", c.param)
123+
}
124+
119125
nextSeries, err := c.next.Series(ctx)
120126
if err != nil {
121127
return err

execution/binary/vector.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ func (o *vectorOperator) execBinaryUnless(lhs, rhs model.StepVector) (model.Step
308308
return step, nil
309309
}
310310

311-
func (o *vectorOperator) computeBinaryPairing(hval, lval float64, hlhs, hrhs *histogram.FloatHistogram, annos *annotations.Annotations) (float64, *histogram.FloatHistogram, bool, error) {
311+
func (o *vectorOperator) computeBinaryPairing(ctx context.Context, hval, lval float64, hlhs, hrhs *histogram.FloatHistogram, annos *annotations.Annotations) (float64, *histogram.FloatHistogram, bool, error) {
312312
// operand is not commutative so we need to address potential swapping
313313
if o.matching.Card == parser.CardOneToMany {
314-
v, h, keep, err := vectorElemBinop(o.opType, lval, hval, hlhs, hrhs, annos)
314+
v, h, keep, err := vectorElemBinop(ctx, o.opType, lval, hval, hlhs, hrhs, annos)
315315
return v, h, keep, err
316316
}
317-
v, h, keep, err := vectorElemBinop(o.opType, hval, lval, hlhs, hrhs, annos)
317+
v, h, keep, err := vectorElemBinop(ctx, o.opType, hval, lval, hlhs, hrhs, annos)
318318
return v, h, keep, err
319319
}
320320

@@ -380,9 +380,9 @@ func (o *vectorOperator) execBinaryArithmetic(ctx context.Context, lhs, rhs mode
380380
jp.bts = ts
381381

382382
if jp.histogramVal != nil {
383-
_, h, keep, err = o.computeBinaryPairing(0, 0, hcs.Histograms[i], jp.histogramVal, &annos)
383+
_, h, keep, err = o.computeBinaryPairing(ctx, 0, 0, hcs.Histograms[i], jp.histogramVal, &annos)
384384
} else {
385-
_, h, keep, err = o.computeBinaryPairing(0, jp.val, hcs.Histograms[i], nil, &annos)
385+
_, h, keep, err = o.computeBinaryPairing(ctx, 0, jp.val, hcs.Histograms[i], nil, &annos)
386386
}
387387
if countWarnings, countInfo := annos.CountWarningsAndInfo(); countWarnings > 0 || countInfo > 0 {
388388
warnings.MergeToContext(annos, ctx)
@@ -423,7 +423,7 @@ func (o *vectorOperator) execBinaryArithmetic(ctx context.Context, lhs, rhs mode
423423
var val float64
424424

425425
if jp.histogramVal != nil {
426-
_, h, _, err = o.computeBinaryPairing(hcs.Samples[i], 0, nil, jp.histogramVal, &annos)
426+
_, h, _, err = o.computeBinaryPairing(ctx, hcs.Samples[i], 0, nil, jp.histogramVal, &annos)
427427
if countWarnings, countInfo := annos.CountWarningsAndInfo(); countWarnings > 0 || countInfo > 0 {
428428
warnings.MergeToContext(annos, ctx)
429429
continue
@@ -433,7 +433,7 @@ func (o *vectorOperator) execBinaryArithmetic(ctx context.Context, lhs, rhs mode
433433
}
434434
step.AppendHistogram(o.pool, jp.sid, h)
435435
} else {
436-
val, _, keep, err = o.computeBinaryPairing(hcs.Samples[i], jp.val, nil, nil, &annos)
436+
val, _, keep, err = o.computeBinaryPairing(ctx, hcs.Samples[i], jp.val, nil, nil, &annos)
437437
if countWarnings, countInfo := annos.CountWarningsAndInfo(); countWarnings > 0 || countInfo > 0 {
438438
warnings.MergeToContext(annos, ctx)
439439
continue
@@ -626,7 +626,7 @@ func signatureFunc(on bool, names ...string) func(labels.Labels) uint64 {
626626
// Lifted from: https://github.com/prometheus/prometheus/blob/v3.1.0/promql/engine.go#L2797.
627627
// nolint: unparam
628628
// vectorElemBinop evaluates a binary operation between two Vector elements.
629-
func vectorElemBinop(op parser.ItemType, lhs, rhs float64, hlhs, hrhs *histogram.FloatHistogram, annos *annotations.Annotations) (float64, *histogram.FloatHistogram, bool, error) {
629+
func vectorElemBinop(ctx context.Context, op parser.ItemType, lhs, rhs float64, hlhs, hrhs *histogram.FloatHistogram, annos *annotations.Annotations) (float64, *histogram.FloatHistogram, bool, error) {
630630
opName := parser.ItemTypeStr[op]
631631

632632
switch {
@@ -689,12 +689,26 @@ func vectorElemBinop(op parser.ItemType, lhs, rhs float64, hlhs, hrhs *histogram
689689
case parser.ADD:
690690
res, err := hlhs.Copy().Add(hrhs)
691691
if err != nil {
692+
if errors.Is(err, histogram.ErrHistogramsIncompatibleSchema) {
693+
warnings.AddToContext(annotations.NewMixedExponentialCustomHistogramsWarning("", posrange.PositionRange{}), ctx)
694+
return 0, nil, false, nil
695+
} else if errors.Is(err, histogram.ErrHistogramsIncompatibleBounds) {
696+
warnings.AddToContext(annotations.NewIncompatibleCustomBucketsHistogramsWarning("", posrange.PositionRange{}), ctx)
697+
return 0, nil, false, nil
698+
}
692699
return 0, nil, false, err
693700
}
694701
return 0, res.Compact(0), true, nil
695702
case parser.SUB:
696703
res, err := hlhs.Copy().Sub(hrhs)
697704
if err != nil {
705+
if errors.Is(err, histogram.ErrHistogramsIncompatibleSchema) {
706+
warnings.AddToContext(annotations.NewMixedExponentialCustomHistogramsWarning("", posrange.PositionRange{}), ctx)
707+
return 0, nil, false, nil
708+
} else if errors.Is(err, histogram.ErrHistogramsIncompatibleBounds) {
709+
warnings.AddToContext(annotations.NewIncompatibleCustomBucketsHistogramsWarning("", posrange.PositionRange{}), ctx)
710+
return 0, nil, false, nil
711+
}
698712
return 0, nil, false, err
699713
}
700714
return 0, res.Compact(0), true, nil

go.mod

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@ require (
88
github.com/efficientgo/core v1.0.0-rc.2
99
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb
1010
github.com/google/go-cmp v0.7.0
11-
github.com/prometheus/client_golang v1.20.5
12-
github.com/prometheus/common v0.61.0
13-
github.com/prometheus/prometheus v0.301.0
11+
github.com/prometheus/client_golang v1.21.0-rc.0
12+
github.com/prometheus/common v0.63.0
13+
github.com/prometheus/prometheus v0.303.1
1414
github.com/stretchr/testify v1.10.0
1515
github.com/zhangyunhao116/umap v0.0.0-20221211160557-cb7705fafa39
1616
go.uber.org/goleak v1.3.0
17-
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
17+
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8
1818
golang.org/x/tools v0.33.0
1919
gonum.org/v1/gonum v0.15.1
2020
)
2121

2222
require (
23-
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
24-
github.com/prometheus/sigv4 v0.1.0 // indirect
23+
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
24+
github.com/prometheus/sigv4 v0.1.2 // indirect
2525
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
2626
)
2727

2828
require (
29-
cloud.google.com/go/auth v0.13.0 // indirect
30-
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
29+
cloud.google.com/go/auth v0.15.0 // indirect
30+
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
3131
cloud.google.com/go/compute/metadata v0.6.0 // indirect
32-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 // indirect
33-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 // indirect
32+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 // indirect
33+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2 // indirect
3434
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
35-
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
35+
github.com/AzureAD/microsoft-authentication-library-for-go v1.3.3 // indirect
3636
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect
37-
github.com/aws/aws-sdk-go v1.55.5 // indirect
37+
github.com/aws/aws-sdk-go v1.55.6 // indirect
3838
github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 // indirect
3939
github.com/beorn7/perks v1.0.1 // indirect
4040
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
@@ -46,44 +46,44 @@ require (
4646
github.com/gogo/protobuf v1.3.2 // indirect
4747
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
4848
github.com/golang/snappy v0.0.4 // indirect
49-
github.com/google/s2a-go v0.1.8 // indirect
49+
github.com/google/s2a-go v0.1.9 // indirect
5050
github.com/google/uuid v1.6.0 // indirect
51-
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
51+
github.com/googleapis/enterprise-certificate-proxy v0.3.5 // indirect
5252
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
5353
github.com/jmespath/go-jmespath v0.4.0 // indirect
5454
github.com/jpillora/backoff v1.0.0 // indirect
55-
github.com/klauspost/compress v1.17.11 // indirect
55+
github.com/klauspost/compress v1.18.0 // indirect
5656
github.com/kylelemons/godebug v1.1.0 // indirect
5757
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5858
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
59-
github.com/oklog/ulid v1.3.1 // indirect
59+
github.com/oklog/ulid/v2 v2.1.0 // indirect
6060
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
6161
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
6262
github.com/prometheus/client_model v0.6.1 // indirect
6363
github.com/prometheus/procfs v0.15.1 // indirect
64-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
65-
go.opentelemetry.io/otel v1.33.0 // indirect
66-
go.opentelemetry.io/otel/metric v1.33.0 // indirect
67-
go.opentelemetry.io/otel/trace v1.33.0 // indirect
64+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
65+
go.opentelemetry.io/otel v1.35.0 // indirect
66+
go.opentelemetry.io/otel/metric v1.35.0 // indirect
67+
go.opentelemetry.io/otel/trace v1.35.0 // indirect
6868
go.uber.org/atomic v1.11.0 // indirect
6969
golang.org/x/crypto v0.38.0 // indirect
7070
golang.org/x/mod v0.24.0 // indirect
7171
golang.org/x/net v0.40.0 // indirect
72-
golang.org/x/oauth2 v0.24.0 // indirect
72+
golang.org/x/oauth2 v0.27.0 // indirect
7373
golang.org/x/sync v0.14.0 // indirect
7474
golang.org/x/sys v0.33.0 // indirect
7575
golang.org/x/text v0.25.0 // indirect
76-
golang.org/x/time v0.8.0 // indirect
77-
google.golang.org/api v0.213.0 // indirect
78-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
79-
google.golang.org/grpc v1.69.0 // indirect
80-
google.golang.org/protobuf v1.36.0 // indirect
76+
golang.org/x/time v0.10.0 // indirect
77+
google.golang.org/api v0.224.0 // indirect
78+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250227231956-55c901821b1e // indirect
79+
google.golang.org/grpc v1.71.0 // indirect
80+
google.golang.org/protobuf v1.36.5 // indirect
8181
gopkg.in/yaml.v2 v2.4.0 // indirect
8282
gopkg.in/yaml.v3 v3.0.1 // indirect
83-
k8s.io/apimachinery v0.31.3 // indirect
84-
k8s.io/client-go v0.31.3 // indirect
83+
k8s.io/apimachinery v0.32.2 // indirect
84+
k8s.io/client-go v0.32.2 // indirect
8585
k8s.io/klog/v2 v2.130.1 // indirect
86-
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
86+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
8787
)
8888

8989
exclude (

0 commit comments

Comments
 (0)