Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade Prometheus version to latest main #435

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.20
1.21
16 changes: 5 additions & 11 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import (
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/util/annotations"
"github.com/prometheus/prometheus/util/stats"
v1 "github.com/prometheus/prometheus/web/api/v1"

engstorage "github.com/thanos-io/promql-engine/storage"
promstorage "github.com/thanos-io/promql-engine/storage/prometheus"

"github.com/thanos-io/promql-engine/execution"
"github.com/thanos-io/promql-engine/execution/function"
Expand All @@ -33,6 +29,8 @@ import (
"github.com/thanos-io/promql-engine/extlabels"
"github.com/thanos-io/promql-engine/logicalplan"
"github.com/thanos-io/promql-engine/query"
engstorage "github.com/thanos-io/promql-engine/storage"
promstorage "github.com/thanos-io/promql-engine/storage/prometheus"
)

type QueryType int
Expand Down Expand Up @@ -69,7 +67,7 @@ type Opts struct {
EnableXFunctions bool

// FallbackEngine
Engine v1.QueryEngine
Engine promql.QueryEngine

// EnableAnalysis enables query analysis.
EnableAnalysis bool
Expand Down Expand Up @@ -154,7 +152,7 @@ func NewWithScanners(opts Opts, scanners engstorage.Scanners) *Engine {
),
}

var engine v1.QueryEngine
var engine promql.QueryEngine
if opts.Engine == nil {
engine = promql.NewEngine(opts.EngineOpts)
} else {
Expand Down Expand Up @@ -190,7 +188,7 @@ var (
)

type Engine struct {
prom v1.QueryEngine
prom promql.QueryEngine
functions map[string]*parser.Function
scanners engstorage.Scanners

Expand All @@ -208,10 +206,6 @@ type Engine struct {
noStepSubqueryIntervalFn func(time.Duration) time.Duration
}

func (e *Engine) SetQueryLogger(l promql.QueryLogger) {
e.prom.SetQueryLogger(l)
}

func (e *Engine) NewInstantQuery(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, qs string, ts time.Time) (promql.Query, error) {
expr, err := parser.NewParser(qs, parser.WithFunctions(e.functions)).ParseExpr()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2463,7 +2463,7 @@ func TestRateVsXRate(t *testing.T) {
queryTime: time.Unix(25, 0),
expected: []promql.Sample{
createSample(defaultQueryTime.UnixMilli(), 0.022, labels.FromStrings("path", "/foo")),
createSample(defaultQueryTime.UnixMilli(), 0.12, labels.FromStrings("path", "/bar")),
createSample(defaultQueryTime.UnixMilli(), 0.11000000000000001, labels.FromStrings("path", "/bar")),
},
},
{
Expand All @@ -2485,7 +2485,7 @@ func TestRateVsXRate(t *testing.T) {
queryTime: time.Unix(24, 0),
expected: []promql.Sample{
createSample(24000, 0.0265, labels.FromStrings("path", "/foo")),
createSample(24000, 0.116, labels.FromStrings("path", "/bar")),
createSample(24000, 0.106, labels.FromStrings("path", "/bar")),
},
},
{
Expand All @@ -2506,8 +2506,8 @@ func TestRateVsXRate(t *testing.T) {
query: "rate(http_requests[50s])",
queryTime: time.Unix(26, 0),
expected: []promql.Sample{
createSample(26000, 0.02279999999, labels.FromStrings("path", "/foo")),
createSample(26000, 0.124, labels.FromStrings("path", "/bar")),
createSample(26000, 0.022799999999999997, labels.FromStrings("path", "/foo")),
createSample(26000, 0.11399999999999999, labels.FromStrings("path", "/bar")),
},
},
{
Expand Down
35 changes: 19 additions & 16 deletions execution/scan/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ var rangeVectorFuncs = map[string]FunctionCall{
if len(f.Samples) == 0 {
return 0., nil, false
}
if f.Samples[0].V.H != nil {
return 0, f.Samples[len(f.Samples)-1].V.H.Copy(), true
}
return f.Samples[len(f.Samples)-1].V.F, nil, true
},
"present_over_time": func(f FunctionArgs) (float64, *histogram.FloatHistogram, bool) {
Expand Down Expand Up @@ -258,6 +261,16 @@ func extrapolatedRate(samples []ringbuffer.Sample[Value], isCounter, isRate bool
sampledInterval := float64(samples[len(samples)-1].T-samples[0].T) / 1000
averageDurationBetweenSamples := sampledInterval / float64(len(samples)-1)

// If the first/last samples are close to the boundaries of the range,
// extrapolate the result. This is as we expect that another sample
// will exist given the spacing between samples we've seen thus far,
// with an allowance for noise.
extrapolationThreshold := averageDurationBetweenSamples * 1.1
extrapolateToInterval := sampledInterval

if durationToStart >= extrapolationThreshold {
durationToStart = averageDurationBetweenSamples / 2
}
if isCounter && resultValue > 0 && samples[0].V.F >= 0 {
// Counters cannot be negative. If we have any slope at
// all (i.e. resultValue went up), we can extrapolate
Expand All @@ -266,29 +279,19 @@ func extrapolatedRate(samples []ringbuffer.Sample[Value], isCounter, isRate bool
// take the zero point as the start of the series,
// thereby avoiding extrapolation to negative counter
// values.
// TODO(beorn7): Do this for histograms, too.
durationToZero := sampledInterval * (samples[0].V.F / resultValue)
if durationToZero < durationToStart {
durationToStart = durationToZero
}
}
extrapolateToInterval += durationToStart

// If the first/last Samples are close to the boundaries of the range,
// extrapolate the result. This is as we expect that another sample
// will exist given the spacing between Samples we've seen thus far,
// with an allowance for noise.
extrapolationThreshold := averageDurationBetweenSamples * 1.1
extrapolateToInterval := sampledInterval

if durationToStart < extrapolationThreshold {
extrapolateToInterval += durationToStart
} else {
extrapolateToInterval += averageDurationBetweenSamples / 2
}
if durationToEnd < extrapolationThreshold {
extrapolateToInterval += durationToEnd
} else {
extrapolateToInterval += averageDurationBetweenSamples / 2
if durationToEnd >= extrapolationThreshold {
durationToEnd = averageDurationBetweenSamples / 2
}
extrapolateToInterval += durationToEnd

factor := extrapolateToInterval / sampledInterval
if isRate {
factor /= float64(selectRange / 1000)
Expand Down
75 changes: 24 additions & 51 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,102 +1,75 @@
module github.com/thanos-io/promql-engine

go 1.20
go 1.21

require (
github.com/cespare/xxhash/v2 v2.2.0
github.com/cortexproject/promqlsmith v0.0.0-20240103062231-e3aada49136f
github.com/efficientgo/core v1.0.0-rc.2
github.com/go-kit/log v0.2.1
github.com/google/go-cmp v0.6.0
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/common v0.46.0
github.com/prometheus/prometheus v0.49.2-0.20240125131847-c3b8ef1694ff
github.com/stretchr/testify v1.8.4
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/common v0.49.1-0.20240306132007-4199f18c3e92
github.com/prometheus/prometheus v0.51.1-0.20240325140356-78c0fd2f4d75
github.com/stretchr/testify v1.9.0
github.com/zhangyunhao116/umap v0.0.0-20221211160557-cb7705fafa39
go.uber.org/goleak v1.3.0
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
gonum.org/v1/gonum v0.12.0
)

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 // indirect
github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go v1.50.0 // indirect
github.com/aws/aws-sdk-go v1.50.32 // indirect
github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dennwc/varint v1.0.0 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.21.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/strfmt v0.22.0 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/alertmanager v0.26.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
go.mongodb.org/mongo-driver v1.13.1 // indirect
go.opentelemetry.io/collector/featuregate v1.0.1 // indirect
go.opentelemetry.io/collector/pdata v1.0.1 // indirect
go.opentelemetry.io/collector/semconv v0.93.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apimachinery v0.28.6 // indirect
k8s.io/client-go v0.28.6 // indirect
k8s.io/apimachinery v0.29.3 // indirect
k8s.io/client-go v0.29.3 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
)
Expand Down