diff --git a/go.mod b/go.mod index f11d145a46a..6d5c5e0fd3e 100644 --- a/go.mod +++ b/go.mod @@ -284,7 +284,7 @@ require ( ) // Using a fork of Prometheus with Mimir-specific changes. -replace github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20241121154224-81e8a18ac508 +replace github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20241121154025-fd7e39a8798e // Replace memberlist with our fork which includes some fixes that haven't been // merged upstream yet: diff --git a/go.sum b/go.sum index e43bb6b48a1..58a48022f50 100644 --- a/go.sum +++ b/go.sum @@ -1278,8 +1278,8 @@ github.com/grafana/gomemcache v0.0.0-20241016125027-0a5bcc5aef40 h1:1TeKhyS+pvzO github.com/grafana/gomemcache v0.0.0-20241016125027-0a5bcc5aef40/go.mod h1:IGRj8oOoxwJbHBYl1+OhS9UjQR0dv6SQOep7HqmtyFU= github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe h1:yIXAAbLswn7VNWBIvM71O2QsgfgW9fRXZNR0DXe6pDU= github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= -github.com/grafana/mimir-prometheus v0.0.0-20241121154224-81e8a18ac508 h1:baOjet837B0Lz5ZQRTFIq1ZuhN1cZwajAEtkLR23JG4= -github.com/grafana/mimir-prometheus v0.0.0-20241121154224-81e8a18ac508/go.mod h1:5pZyo8JoQezsp5hvVLlWhXmWLFcjUCC0fFvmswy2cBA= +github.com/grafana/mimir-prometheus v0.0.0-20241121154025-fd7e39a8798e h1:WjcrK2YdNFRsB/7kbtZVmgNmZ7pf3TY9dWgEfHHkUHI= +github.com/grafana/mimir-prometheus v0.0.0-20241121154025-fd7e39a8798e/go.mod h1:5pZyo8JoQezsp5hvVLlWhXmWLFcjUCC0fFvmswy2cBA= github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956 h1:em1oddjXL8c1tL0iFdtVtPloq2hRPen2MJQKoAWpxu0= github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956/go.mod h1:qtI1ogk+2JhVPIXVc6q+NHziSmy2W5GbdQZFUHADCBU= github.com/grafana/prometheus-alertmanager v0.25.1-0.20240930132144-b5e64e81e8d3 h1:6D2gGAwyQBElSrp3E+9lSr7k8gLuP3Aiy20rweLWeBw= diff --git a/pkg/frontend/querymiddleware/astmapper/astmapper.go b/pkg/frontend/querymiddleware/astmapper/astmapper.go index a79aa986ef6..95136f0317a 100644 --- a/pkg/frontend/querymiddleware/astmapper/astmapper.go +++ b/pkg/frontend/querymiddleware/astmapper/astmapper.go @@ -8,8 +8,14 @@ package astmapper import ( "github.com/pkg/errors" "github.com/prometheus/prometheus/promql/parser" + + "github.com/grafana/mimir/pkg/util/promqlext" ) +func init() { + promqlext.ExtendPromQL() +} + // ASTMapper is the exported interface for mapping between multiple AST representations type ASTMapper interface { // Map the input expr and returns the mapped expr. diff --git a/pkg/mimir/promql.go b/pkg/mimir/promql.go new file mode 100644 index 00000000000..8780b824d52 --- /dev/null +++ b/pkg/mimir/promql.go @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +package mimir + +import "github.com/grafana/mimir/pkg/util/promqlext" + +func init() { + promqlext.ExtendPromQL() +} diff --git a/pkg/util/promqlext/promqlext.go b/pkg/util/promqlext/promqlext.go new file mode 100644 index 00000000000..6f32241d06f --- /dev/null +++ b/pkg/util/promqlext/promqlext.go @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +package promqlext + +import ( + "github.com/prometheus/prometheus/promql" + "github.com/prometheus/prometheus/promql/parser" +) + +// ExtendPromQL enriches PromQL with Mimir extensions. +func ExtendPromQL() { + // Keep an alias for users using holt_winters, even though dropped in Prometheus v3. + promql.FunctionCalls["holt_winters"] = promql.FunctionCalls["double_exponential_smoothing"] + parser.Functions["holt_winters"] = parser.Functions["double_exponential_smoothing"] + parser.Functions["holt_winters"].Experimental = false +} diff --git a/vendor/github.com/prometheus/prometheus/promql/functions.go b/vendor/github.com/prometheus/prometheus/promql/functions.go index ae119e79a12..f9af4fbe092 100644 --- a/vendor/github.com/prometheus/prometheus/promql/functions.go +++ b/vendor/github.com/prometheus/prometheus/promql/functions.go @@ -1671,50 +1671,48 @@ var FunctionCalls = map[string]FunctionCall{ "histogram_stddev": funcHistogramStdDev, "histogram_stdvar": funcHistogramStdVar, "double_exponential_smoothing": funcDoubleExponentialSmoothing, - // Keep an alias for Mimir users using holt_winters. - "holt_winters": funcDoubleExponentialSmoothing, - "hour": funcHour, - "idelta": funcIdelta, - "increase": funcIncrease, - "info": nil, - "irate": funcIrate, - "label_replace": nil, // evalLabelReplace not called via this map. - "label_join": nil, // evalLabelJoin not called via this map. - "ln": funcLn, - "log10": funcLog10, - "log2": funcLog2, - "last_over_time": funcLastOverTime, - "mad_over_time": funcMadOverTime, - "max_over_time": funcMaxOverTime, - "min_over_time": funcMinOverTime, - "minute": funcMinute, - "month": funcMonth, - "pi": funcPi, - "predict_linear": funcPredictLinear, - "present_over_time": funcPresentOverTime, - "quantile_over_time": funcQuantileOverTime, - "rad": funcRad, - "rate": funcRate, - "resets": funcResets, - "round": funcRound, - "scalar": funcScalar, - "sgn": funcSgn, - "sin": funcSin, - "sinh": funcSinh, - "sort": funcSort, - "sort_desc": funcSortDesc, - "sort_by_label": funcSortByLabel, - "sort_by_label_desc": funcSortByLabelDesc, - "sqrt": funcSqrt, - "stddev_over_time": funcStddevOverTime, - "stdvar_over_time": funcStdvarOverTime, - "sum_over_time": funcSumOverTime, - "tan": funcTan, - "tanh": funcTanh, - "time": funcTime, - "timestamp": funcTimestamp, - "vector": funcVector, - "year": funcYear, + "hour": funcHour, + "idelta": funcIdelta, + "increase": funcIncrease, + "info": nil, + "irate": funcIrate, + "label_replace": nil, // evalLabelReplace not called via this map. + "label_join": nil, // evalLabelJoin not called via this map. + "ln": funcLn, + "log10": funcLog10, + "log2": funcLog2, + "last_over_time": funcLastOverTime, + "mad_over_time": funcMadOverTime, + "max_over_time": funcMaxOverTime, + "min_over_time": funcMinOverTime, + "minute": funcMinute, + "month": funcMonth, + "pi": funcPi, + "predict_linear": funcPredictLinear, + "present_over_time": funcPresentOverTime, + "quantile_over_time": funcQuantileOverTime, + "rad": funcRad, + "rate": funcRate, + "resets": funcResets, + "round": funcRound, + "scalar": funcScalar, + "sgn": funcSgn, + "sin": funcSin, + "sinh": funcSinh, + "sort": funcSort, + "sort_desc": funcSortDesc, + "sort_by_label": funcSortByLabel, + "sort_by_label_desc": funcSortByLabelDesc, + "sqrt": funcSqrt, + "stddev_over_time": funcStddevOverTime, + "stdvar_over_time": funcStdvarOverTime, + "sum_over_time": funcSumOverTime, + "tan": funcTan, + "tanh": funcTanh, + "time": funcTime, + "timestamp": funcTimestamp, + "vector": funcVector, + "year": funcYear, } // AtModifierUnsafeFunctions are the functions whose result diff --git a/vendor/github.com/prometheus/prometheus/promql/parser/functions.go b/vendor/github.com/prometheus/prometheus/promql/parser/functions.go index eaf7b5aa749..aa65aca2755 100644 --- a/vendor/github.com/prometheus/prometheus/promql/parser/functions.go +++ b/vendor/github.com/prometheus/prometheus/promql/parser/functions.go @@ -208,12 +208,6 @@ var Functions = map[string]*Function{ ReturnType: ValueTypeVector, Experimental: true, }, - // Keep an alias for Mimir users using holt_winters. - "holt_winters": { - Name: "holt_winters", - ArgTypes: []ValueType{ValueTypeMatrix, ValueTypeScalar, ValueTypeScalar}, - ReturnType: ValueTypeVector, - }, "hour": { Name: "hour", ArgTypes: []ValueType{ValueTypeVector}, diff --git a/vendor/modules.txt b/vendor/modules.txt index b11fb7e5f22..f482784ecde 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1017,7 +1017,7 @@ github.com/prometheus/exporter-toolkit/web github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util -# github.com/prometheus/prometheus v1.99.0 => github.com/grafana/mimir-prometheus v0.0.0-20241121154224-81e8a18ac508 +# github.com/prometheus/prometheus v1.99.0 => github.com/grafana/mimir-prometheus v0.0.0-20241121154025-fd7e39a8798e ## explicit; go 1.22.0 github.com/prometheus/prometheus/config github.com/prometheus/prometheus/discovery @@ -1685,7 +1685,7 @@ sigs.k8s.io/kustomize/kyaml/yaml/walk sigs.k8s.io/yaml sigs.k8s.io/yaml/goyaml.v2 sigs.k8s.io/yaml/goyaml.v3 -# github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20241121154224-81e8a18ac508 +# github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20241121154025-fd7e39a8798e # github.com/hashicorp/memberlist => github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe # gopkg.in/yaml.v3 => github.com/colega/go-yaml-yaml v0.0.0-20220720105220-255a8d16d094 # github.com/grafana/regexp => github.com/grafana/regexp v0.0.0-20240531075221-3685f1377d7b