2020-02-03 16:21:46 +00:00
|
|
|
// Copyright 2015 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-02-03 16:23:44 +00:00
|
|
|
package parser
|
2020-02-03 16:21:46 +00:00
|
|
|
|
|
|
|
// Function represents a function of the expression language and is
|
|
|
|
// used by function nodes.
|
|
|
|
type Function struct {
|
2023-11-07 22:37:37 +00:00
|
|
|
Name string
|
|
|
|
ArgTypes []ValueType
|
|
|
|
Variadic int
|
|
|
|
ReturnType ValueType
|
|
|
|
Experimental bool
|
2020-02-03 16:21:46 +00:00
|
|
|
}
|
|
|
|
|
2023-11-07 22:37:37 +00:00
|
|
|
// EnableExperimentalFunctions controls whether experimentalFunctions are enabled.
|
|
|
|
var EnableExperimentalFunctions bool
|
|
|
|
|
2020-02-03 16:21:46 +00:00
|
|
|
// Functions is a list of all functions supported by PromQL, including their types.
|
|
|
|
var Functions = map[string]*Function{
|
|
|
|
"abs": {
|
|
|
|
Name: "abs",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"absent": {
|
|
|
|
Name: "absent",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"absent_over_time": {
|
|
|
|
Name: "absent_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 00:04:00 +00:00
|
|
|
"acos": {
|
|
|
|
Name: "acos",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-25 10:48:08 +00:00
|
|
|
"acosh": {
|
|
|
|
Name: "acosh",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 00:04:00 +00:00
|
|
|
"asin": {
|
|
|
|
Name: "asin",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-25 10:48:08 +00:00
|
|
|
"asinh": {
|
|
|
|
Name: "asinh",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 00:04:00 +00:00
|
|
|
"atan": {
|
|
|
|
Name: "atan",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-25 10:48:08 +00:00
|
|
|
"atanh": {
|
|
|
|
Name: "atanh",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"avg_over_time": {
|
|
|
|
Name: "avg_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"ceil": {
|
|
|
|
Name: "ceil",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"changes": {
|
|
|
|
Name: "changes",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-02-20 15:34:52 +00:00
|
|
|
"clamp": {
|
|
|
|
Name: "clamp",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector, ValueTypeScalar, ValueTypeScalar},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"clamp_max": {
|
|
|
|
Name: "clamp_max",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector, ValueTypeScalar},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"clamp_min": {
|
|
|
|
Name: "clamp_min",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector, ValueTypeScalar},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 00:04:00 +00:00
|
|
|
"cos": {
|
|
|
|
Name: "cos",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 14:54:52 +00:00
|
|
|
"cosh": {
|
|
|
|
Name: "cosh",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"count_over_time": {
|
|
|
|
Name: "count_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"days_in_month": {
|
|
|
|
Name: "days_in_month",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
Variadic: 1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"day_of_month": {
|
|
|
|
Name: "day_of_month",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
Variadic: 1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"day_of_week": {
|
|
|
|
Name: "day_of_week",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
Variadic: 1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2022-05-20 10:24:19 +00:00
|
|
|
"day_of_year": {
|
|
|
|
Name: "day_of_year",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
Variadic: 1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 00:04:00 +00:00
|
|
|
"deg": {
|
|
|
|
Name: "deg",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"delta": {
|
|
|
|
Name: "delta",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"deriv": {
|
|
|
|
Name: "deriv",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"exp": {
|
|
|
|
Name: "exp",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"floor": {
|
|
|
|
Name: "floor",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2024-02-01 17:28:42 +00:00
|
|
|
"histogram_avg": {
|
|
|
|
Name: "histogram_avg",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2022-06-28 14:43:58 +00:00
|
|
|
"histogram_count": {
|
|
|
|
Name: "histogram_count",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"histogram_sum": {
|
|
|
|
Name: "histogram_sum",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2023-08-24 19:02:14 +00:00
|
|
|
"histogram_stddev": {
|
|
|
|
Name: "histogram_stddev",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"histogram_stdvar": {
|
|
|
|
Name: "histogram_stdvar",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2022-06-16 18:44:12 +00:00
|
|
|
"histogram_fraction": {
|
|
|
|
Name: "histogram_fraction",
|
|
|
|
ArgTypes: []ValueType{ValueTypeScalar, ValueTypeScalar, ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"histogram_quantile": {
|
|
|
|
Name: "histogram_quantile",
|
|
|
|
ArgTypes: []ValueType{ValueTypeScalar, ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2024-09-18 09:20:17 +00:00
|
|
|
"double_exponential_smoothing": {
|
|
|
|
Name: "double_exponential_smoothing",
|
2024-09-16 15:45:32 +00:00
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix, ValueTypeScalar, ValueTypeScalar},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
Experimental: true,
|
2020-02-03 16:21:46 +00:00
|
|
|
},
|
|
|
|
"hour": {
|
|
|
|
Name: "hour",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
Variadic: 1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"idelta": {
|
|
|
|
Name: "idelta",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"increase": {
|
|
|
|
Name: "increase",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"irate": {
|
|
|
|
Name: "irate",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"label_replace": {
|
|
|
|
Name: "label_replace",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector, ValueTypeString, ValueTypeString, ValueTypeString, ValueTypeString},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"label_join": {
|
|
|
|
Name: "label_join",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector, ValueTypeString, ValueTypeString, ValueTypeString},
|
|
|
|
Variadic: -1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-02-20 15:34:52 +00:00
|
|
|
"last_over_time": {
|
|
|
|
Name: "last_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"ln": {
|
|
|
|
Name: "ln",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"log10": {
|
|
|
|
Name: "log10",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"log2": {
|
|
|
|
Name: "log2",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2023-11-30 17:22:58 +00:00
|
|
|
"mad_over_time": {
|
2023-11-30 17:55:01 +00:00
|
|
|
Name: "mad_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
Experimental: true,
|
2023-11-30 17:22:58 +00:00
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"max_over_time": {
|
|
|
|
Name: "max_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"min_over_time": {
|
|
|
|
Name: "min_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"minute": {
|
|
|
|
Name: "minute",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
Variadic: 1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"month": {
|
|
|
|
Name: "month",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
Variadic: 1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 00:04:00 +00:00
|
|
|
"pi": {
|
|
|
|
Name: "pi",
|
|
|
|
ArgTypes: []ValueType{},
|
2021-08-24 12:41:46 +00:00
|
|
|
ReturnType: ValueTypeScalar,
|
2021-08-24 00:04:00 +00:00
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"predict_linear": {
|
|
|
|
Name: "predict_linear",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix, ValueTypeScalar},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 00:04:00 +00:00
|
|
|
"present_over_time": {
|
|
|
|
Name: "present_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"quantile_over_time": {
|
|
|
|
Name: "quantile_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeScalar, ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 00:04:00 +00:00
|
|
|
"rad": {
|
|
|
|
Name: "rad",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"rate": {
|
|
|
|
Name: "rate",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"resets": {
|
|
|
|
Name: "resets",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"round": {
|
|
|
|
Name: "round",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector, ValueTypeScalar},
|
|
|
|
Variadic: 1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"scalar": {
|
|
|
|
Name: "scalar",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeScalar,
|
|
|
|
},
|
2021-02-20 15:34:52 +00:00
|
|
|
"sgn": {
|
|
|
|
Name: "sgn",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 00:04:00 +00:00
|
|
|
"sin": {
|
|
|
|
Name: "sin",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 14:54:52 +00:00
|
|
|
"sinh": {
|
|
|
|
Name: "sinh",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"sort": {
|
|
|
|
Name: "sort",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"sort_desc": {
|
|
|
|
Name: "sort_desc",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2023-11-22 11:06:48 +00:00
|
|
|
"sort_by_label": {
|
2023-11-28 14:10:12 +00:00
|
|
|
Name: "sort_by_label",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector, ValueTypeString},
|
|
|
|
Variadic: -1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
Experimental: true,
|
2023-11-22 11:06:48 +00:00
|
|
|
},
|
|
|
|
"sort_by_label_desc": {
|
2023-11-28 14:10:12 +00:00
|
|
|
Name: "sort_by_label_desc",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector, ValueTypeString},
|
|
|
|
Variadic: -1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
Experimental: true,
|
2023-11-22 11:06:48 +00:00
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"sqrt": {
|
|
|
|
Name: "sqrt",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"stddev_over_time": {
|
|
|
|
Name: "stddev_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"stdvar_over_time": {
|
|
|
|
Name: "stdvar_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"sum_over_time": {
|
|
|
|
Name: "sum_over_time",
|
|
|
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 00:04:00 +00:00
|
|
|
"tan": {
|
|
|
|
Name: "tan",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2021-08-24 14:54:52 +00:00
|
|
|
"tanh": {
|
|
|
|
Name: "tanh",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
2020-02-03 16:21:46 +00:00
|
|
|
"time": {
|
|
|
|
Name: "time",
|
|
|
|
ArgTypes: []ValueType{},
|
|
|
|
ReturnType: ValueTypeScalar,
|
|
|
|
},
|
|
|
|
"timestamp": {
|
|
|
|
Name: "timestamp",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"vector": {
|
|
|
|
Name: "vector",
|
|
|
|
ArgTypes: []ValueType{ValueTypeScalar},
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
"year": {
|
|
|
|
Name: "year",
|
|
|
|
ArgTypes: []ValueType{ValueTypeVector},
|
|
|
|
Variadic: 1,
|
|
|
|
ReturnType: ValueTypeVector,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// getFunction returns a predefined Function object for the given name.
|
2023-03-22 09:02:10 +00:00
|
|
|
func getFunction(name string, functions map[string]*Function) (*Function, bool) {
|
|
|
|
function, ok := functions[name]
|
2020-02-03 16:21:46 +00:00
|
|
|
return function, ok
|
|
|
|
}
|