| 16 | } |
| 17 | |
| 18 | func buildFunctions(enableHoltWinters bool) map[string]*promqlparser.Function { |
| 19 | fns := make(map[string]*promqlparser.Function, len(promqlparser.Functions)) |
| 20 | maps.Copy(fns, promqlparser.Functions) |
| 21 | maps.Copy(fns, parse.XFunctions) |
| 22 | |
| 23 | // The holt_winters function was renamed to double_exponential_smoothing and marked experimental in Prometheus v3. |
| 24 | // Register holt_winters as an alias to maintain backward compatibility. |
| 25 | if enableHoltWinters { |
| 26 | if des, ok := fns["double_exponential_smoothing"]; ok { |
| 27 | holtWinters := *des |
| 28 | holtWinters.Experimental = false |
| 29 | holtWinters.Name = "holt_winters" |
| 30 | fns["holt_winters"] = &holtWinters |
| 31 | |
| 32 | // Also register in global Prometheus parser for engine execution |
| 33 | promqlparser.Functions["holt_winters"] = &holtWinters |
| 34 | promql.FunctionCalls["holt_winters"] = promql.FunctionCalls["double_exponential_smoothing"] |
| 35 | } |
| 36 | } else { |
| 37 | delete(promqlparser.Functions, "holt_winters") |
| 38 | delete(promql.FunctionCalls, "holt_winters") |
| 39 | } |
| 40 | |
| 41 | return fns |
| 42 | } |
| 43 | |
| 44 | func ParseExpr(qs string) (promqlparser.Expr, error) { |
| 45 | return promqlparser.NewParser(qs, promqlparser.WithFunctions(functions)).ParseExpr() |