diff --git a/promql/functions.go b/promql/functions.go index 366c68c8c37..aa41b0ffe36 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -1388,35 +1388,48 @@ func init() { fmt.Println("Successfully replaced rate & friends with xrate & friends (and removed xrate & friends function keys).") case "x", "X": - copyParserFunction("delta", "orig_delta") - copyParserFunction("increase", "orig_increase") - copyParserFunction("rate", "orig_rate") - repointFunction("delta", "xdelta", "orig_delta") - repointFunction("increase", "xincrease", "orig_increase") - repointFunction("rate", "xrate", "orig_rate") + // copyParserFunction("delta", "orig_delta") + // copyParserFunction("increase", "orig_increase") + // copyParserFunction("rate", "orig_rate") + repointParserFunctions("delta", "xdelta") + repointParserFunctions("increase", "xincrease") + repointParserFunctions("rate", "xrate") + repointFunction("delta", "xdelta" /*, "orig_delta" */) + repointFunction("increase", "xincrease" /*, "orig_increase" */) + repointFunction("rate", "xrate" /*, "orig_rate" */) fmt.Println("Successfully replaced rate/increase/delta with xrate/xincrease/xdelta (and left the latter names available as well, and original functions callable as orig_rate/orig_increase/orig_delta).") case "2", "y", "Y": - copyParserFunction("delta", "orig_delta") - copyParserFunction("increase", "orig_increase") - copyParserFunction("rate", "orig_rate") - repointFunction("delta", "ydelta", "orig_delta") - repointFunction("increase", "yincrease", "orig_increase") - repointFunction("rate", "yrate", "orig_rate") - - fmt.Println("Successfully replaced rate/increase/delta with yrate/yincrease/ydelta (and left the latter names available as well, and original functions callable as orig_rate/orig_increase/orig_delta).") + // copyParserFunction("delta", "orig_delta") + // copyParserFunction("increase", "orig_increase") + // copyParserFunction("rate", "orig_rate") + repointParserFunctions("delta", "ydelta") + repointParserFunctions("increase", "yincrease") + repointParserFunctions("rate", "yrate") + repointFunction("delta", "ydelta" /*, "orig_delta" */) + repointFunction("increase", "yincrease" /*, "orig_increase" */) + repointFunction("rate", "yrate" /*, "orig_rate" */) + + fmt.Println("Successfully replaced rate/increase/delta with yrate/yincrease/ydelta (and left the latter names available as well).") } } +/* func copyParserFunction(fromName, toName string) { - fromFunction := *parser.Functions[fromName] - fromFunction.Name = toName - parser.Functions[toName] = &fromFunction + functionCopy := *parser.Functions[fromName] + functionCopy.Name = toName + parser.Functions[toName] = &functionCopy } +*/ -func repointFunction(name, newName, origName string) { - FunctionCalls[origName] = FunctionCalls[name] +func repointParserFunctions(name, newName string) { + parser.Functions[name] = parser.Functions[newName] + parser.Functions[name].Name = newName // TODO: This line feels redundant since the Name should already be newName. Hoping we can drop it. -Colin +} + +func repointFunction(name, newName string /*, origName string */) { + // FunctionCalls[origName] = FunctionCalls[name] FunctionCalls[name] = FunctionCalls[newName] }