From 81e8a18ac508b0bb2af64b29587b26a8860a46a2 Mon Sep 17 00:00:00 2001
From: Arve Knudsen <arve.knudsen@gmail.com>
Date: Wed, 6 Nov 2024 16:21:25 +0100
Subject: [PATCH] PromQL: Add holt_winters alias

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
---
 promql/functions.go        | 86 +++++++++++++++++++-------------------
 promql/parser/functions.go |  6 +++
 2 files changed, 50 insertions(+), 42 deletions(-)

diff --git a/promql/functions.go b/promql/functions.go
index f9af4fbe0..ae119e79a 100644
--- a/promql/functions.go
+++ b/promql/functions.go
@@ -1671,48 +1671,50 @@ var FunctionCalls = map[string]FunctionCall{
 	"histogram_stddev":             funcHistogramStdDev,
 	"histogram_stdvar":             funcHistogramStdVar,
 	"double_exponential_smoothing": 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,
+	// 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,
 }
 
 // AtModifierUnsafeFunctions are the functions whose result
diff --git a/promql/parser/functions.go b/promql/parser/functions.go
index aa65aca27..eaf7b5aa7 100644
--- a/promql/parser/functions.go
+++ b/promql/parser/functions.go
@@ -208,6 +208,12 @@ 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},