File: rollup.go

package info (click to toggle)
golang-github-victoriametrics-metricsql 0.49.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 272 kB
  • sloc: makefile: 2
file content (107 lines) | stat: -rw-r--r-- 3,397 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package metricsql

import (
	"strings"
)

var rollupFuncs = map[string]bool{
	"absent_over_time":        true,
	"aggr_over_time":          true,
	"ascent_over_time":        true,
	"avg_over_time":           true,
	"changes":                 true,
	"changes_prometheus":      true,
	"count_eq_over_time":      true,
	"count_gt_over_time":      true,
	"count_le_over_time":      true,
	"count_ne_over_time":      true,
	"count_over_time":         true,
	"decreases_over_time":     true,
	"default_rollup":          true,
	"delta":                   true,
	"delta_prometheus":        true,
	"deriv":                   true,
	"deriv_fast":              true,
	"descent_over_time":       true,
	"distinct_over_time":      true,
	"duration_over_time":      true,
	"first_over_time":         true,
	"geomean_over_time":       true,
	"histogram_over_time":     true,
	"hoeffding_bound_lower":   true,
	"hoeffding_bound_upper":   true,
	"holt_winters":            true,
	"idelta":                  true,
	"ideriv":                  true,
	"increase":                true,
	"increase_prometheus":     true,
	"increase_pure":           true,
	"increases_over_time":     true,
	"integrate":               true,
	"irate":                   true,
	"lag":                     true,
	"last_over_time":          true,
	"lifetime":                true,
	"max_over_time":           true,
	"min_over_time":           true,
	"mode_over_time":          true,
	"predict_linear":          true,
	"present_over_time":       true,
	"quantile_over_time":      true,
	"quantiles_over_time":     true,
	"range_over_time":         true,
	"rate":                    true,
	"rate_over_sum":           true,
	"resets":                  true,
	"rollup":                  true,
	"rollup_candlestick":      true,
	"rollup_delta":            true,
	"rollup_deriv":            true,
	"rollup_increase":         true,
	"rollup_rate":             true,
	"rollup_scrape_interval":  true,
	"scrape_interval":         true,
	"share_gt_over_time":      true,
	"share_le_over_time":      true,
	"stale_samples_over_time": true,
	"stddev_over_time":        true,
	"stdvar_over_time":        true,
	"sum_over_time":           true,
	"sum2_over_time":          true,
	"tfirst_over_time":        true,
	// `timestamp` function must return timestamp for the last datapoint on the current window
	// in order to properly handle offset and timestamps unaligned to the current step.
	// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/415 for details.
	"timestamp":              true,
	"timestamp_with_name":    true,
	"tlast_change_over_time": true,
	"tlast_over_time":        true,
	"tmax_over_time":         true,
	"tmin_over_time":         true,
	"zscore_over_time":       true,
}

// IsRollupFunc returns whether funcName is known rollup function.
func IsRollupFunc(funcName string) bool {
	s := strings.ToLower(funcName)
	return rollupFuncs[s]
}

// GetRollupArgIdx returns the argument index for the given fe, which accepts the rollup argument.
//
// -1 is returned if fe isn't a rollup function.
func GetRollupArgIdx(fe *FuncExpr) int {
	funcName := strings.ToLower(fe.Name)
	if !rollupFuncs[funcName] {
		return -1
	}
	switch funcName {
	case "quantile_over_time", "aggr_over_time",
		"hoeffding_bound_lower", "hoeffding_bound_upper":
		return 1
	case "quantiles_over_time":
		return len(fe.Args) - 1
	default:
		return 0
	}
}