mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
{app/vmselect,docs}: support share_eq_over_time#4441 (#4725)
https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4441 Co-authored-by: wangm <wangmm@tuya.com>
This commit is contained in:
parent
9abf8535ac
commit
3f6efab6ae
4 changed files with 43 additions and 0 deletions
|
@ -5826,6 +5826,17 @@ func TestExecSuccess(t *testing.T) {
|
||||||
resultExpected := []netstorage.Result{r}
|
resultExpected := []netstorage.Result{r}
|
||||||
f(q, resultExpected)
|
f(q, resultExpected)
|
||||||
})
|
})
|
||||||
|
t.Run(`share_eq_over_time`, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
q := `share_eq_over_time(round(5*rand(0))[200s:10s], 1)`
|
||||||
|
r := netstorage.Result{
|
||||||
|
MetricName: metricNameExpected,
|
||||||
|
Values: []float64{0.1, 0.2, 0.25, 0.1, 0.3, 0.3},
|
||||||
|
Timestamps: timestampsExpected,
|
||||||
|
}
|
||||||
|
resultExpected := []netstorage.Result{r}
|
||||||
|
f(q, resultExpected)
|
||||||
|
})
|
||||||
t.Run(`count_gt_over_time`, func(t *testing.T) {
|
t.Run(`count_gt_over_time`, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
q := `count_gt_over_time(rand(0)[200s:10s], 0.7)`
|
q := `count_gt_over_time(rand(0)[200s:10s], 0.7)`
|
||||||
|
|
|
@ -78,6 +78,7 @@ var rollupFuncs = map[string]newRollupFunc{
|
||||||
"scrape_interval": newRollupFuncOneArg(rollupScrapeInterval),
|
"scrape_interval": newRollupFuncOneArg(rollupScrapeInterval),
|
||||||
"share_gt_over_time": newRollupShareGT,
|
"share_gt_over_time": newRollupShareGT,
|
||||||
"share_le_over_time": newRollupShareLE,
|
"share_le_over_time": newRollupShareLE,
|
||||||
|
"share_eq_over_time": newRollupShareEQ,
|
||||||
"stale_samples_over_time": newRollupFuncOneArg(rollupStaleSamples),
|
"stale_samples_over_time": newRollupFuncOneArg(rollupStaleSamples),
|
||||||
"stddev_over_time": newRollupFuncOneArg(rollupStddev),
|
"stddev_over_time": newRollupFuncOneArg(rollupStddev),
|
||||||
"stdvar_over_time": newRollupFuncOneArg(rollupStdvar),
|
"stdvar_over_time": newRollupFuncOneArg(rollupStdvar),
|
||||||
|
@ -1106,6 +1107,10 @@ func countFilterGT(values []float64, gt float64) int {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newRollupShareEQ(args []interface{}) (rollupFunc, error) {
|
||||||
|
return newRollupShareFilter(args, countFilterEQ)
|
||||||
|
}
|
||||||
|
|
||||||
func countFilterEQ(values []float64, eq float64) int {
|
func countFilterEQ(values []float64, eq float64) int {
|
||||||
n := 0
|
n := 0
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
|
|
|
@ -261,6 +261,25 @@ func TestRollupShareGTOverTime(t *testing.T) {
|
||||||
f(1000, 0)
|
f(1000, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRollupShareEQOverTime(t *testing.T) {
|
||||||
|
f := func(eq, vExpected float64) {
|
||||||
|
t.Helper()
|
||||||
|
eqs := []*timeseries{{
|
||||||
|
Values: []float64{eq},
|
||||||
|
Timestamps: []int64{123},
|
||||||
|
}}
|
||||||
|
var me metricsql.MetricExpr
|
||||||
|
args := []interface{}{&metricsql.RollupExpr{Expr: &me}, eqs}
|
||||||
|
testRollupFunc(t, "share_eq_over_time", args, &me, vExpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
f(-123, 0)
|
||||||
|
f(34, 0.3333333333333333)
|
||||||
|
f(44, 0.16666666666666666)
|
||||||
|
f(123, 0.08333333333333333)
|
||||||
|
f(1000, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func TestRollupCountLEOverTime(t *testing.T) {
|
func TestRollupCountLEOverTime(t *testing.T) {
|
||||||
f := func(le, vExpected float64) {
|
f := func(le, vExpected float64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
|
@ -744,6 +744,14 @@ Metric names are stripped from the resulting rollups. Add [keep_metric_names](#k
|
||||||
|
|
||||||
See also [share_gt_over_time](#share_gt_over_time).
|
See also [share_gt_over_time](#share_gt_over_time).
|
||||||
|
|
||||||
|
#### share_eq_over_time
|
||||||
|
|
||||||
|
`share_eq_over_time(series_selector[d], eq)` is a [rollup function](#rollup-functions), which returns share (in the range `[0...1]`) of raw samples
|
||||||
|
on the given lookbehind window `d`, which are equal to `eq`. It is calculated independently per each time series returned
|
||||||
|
from the given [series_selector](https://docs.victoriametrics.com/keyConcepts.html#filtering).
|
||||||
|
|
||||||
|
Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names.
|
||||||
|
|
||||||
#### stale_samples_over_time
|
#### stale_samples_over_time
|
||||||
|
|
||||||
`stale_samples_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the number
|
`stale_samples_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the number
|
||||||
|
|
Loading…
Reference in a new issue