Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions promql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down