Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

Commit f3568a4

Browse files
authored
Merge pull request #37 from talIguaz/dev-to-master
Dev --> master
2 parents 02ac9bc + 7458f3d commit f3568a4

File tree

5 files changed

+70
-44
lines changed

5 files changed

+70
-44
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ replace launchpad.net/gocheck => github.com/go-check/check v0.0.0-20180628173108
116116

117117
replace github.com/v3io/frames => github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452caecf15
118118

119-
replace github.com/v3io/v3io-tsdb => github.com/v3io/v3io-tsdb v0.9.0
119+
replace github.com/v3io/v3io-tsdb => github.com/v3io/v3io-tsdb v0.0.0-20190410160018-de081cf7a8519d2c67e31b6202046b1defa87559

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,8 @@ github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452ca
345345
github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452caecf15/go.mod h1:6aKW4Wl4A+gQhXH0JRCVOLgwvcrLyk+fqEpemuie094=
346346
github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2 h1:NJc63wM25iS+ci5z7LVwjWD4QM0QpTQw/fovKzatss0=
347347
github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2/go.mod h1:GXYcR9MxgfbE3BJdkXki5EclvtS8Nxu2RQNLA8hMMog=
348-
github.com/v3io/v3io-tsdb v0.0.0-20190408164746-6763082a23aac832739fd3dc9afba20445592ee9 h1:NAQhv+V0OhisAfNv2h+/Z6WWMk8uw+tTdfJR80JJEZU=
349-
github.com/v3io/v3io-tsdb v0.0.0-20190408164746-6763082a23aac832739fd3dc9afba20445592ee9/go.mod h1:5GOd2S8a0EtKkQAjp7Ke3o+oxZKdUMJFVEU+mk9ltdE=
350-
github.com/v3io/v3io-tsdb v0.9.0 h1:HcopU5LpwAipvQ7D7jBZ2nrMNKycygttKBjnRwNzwZA=
351-
github.com/v3io/v3io-tsdb v0.9.0/go.mod h1:5GOd2S8a0EtKkQAjp7Ke3o+oxZKdUMJFVEU+mk9ltdE=
348+
github.com/v3io/v3io-tsdb v0.0.0-20190410160018-de081cf7a8519d2c67e31b6202046b1defa87559 h1:FWaY/tEnAVMdD51p+iDxbWw54l+5nAZ5dTbKclOsQLo=
349+
github.com/v3io/v3io-tsdb v0.0.0-20190410160018-de081cf7a8519d2c67e31b6202046b1defa87559/go.mod h1:5GOd2S8a0EtKkQAjp7Ke3o+oxZKdUMJFVEU+mk9ltdE=
352350
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
353351
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
354352
github.com/valyala/fasthttp v1.0.0 h1:BwIoZQbBsTo3v2F5lz5Oy3TlTq4wLKTLV260EVTEWco=

promql/engine.go

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ var (
6060
// DefaultEvaluationInterval is the default evaluation interval of
6161
// a subquery in milliseconds.
6262
DefaultEvaluationInterval int64
63+
64+
supportedV3ioFunctions = map[string]bool{"max_over_time": true,
65+
"min_over_time": true,
66+
"avg_over_time": true,
67+
"sum_over_time": true,
68+
"count_over_time": true,
69+
"stddev_over_time": true,
70+
"stdvar_over_time": true}
71+
supportedV3ioAggregations = map[ItemType]bool{itemAvg: true,
72+
itemCount: true,
73+
itemSum: true,
74+
itemMin: true,
75+
itemMax: true,
76+
itemStddev: true,
77+
itemStdvar: true}
6378
)
6479

6580
// SetDefaultEvaluationInterval sets DefaultEvaluationInterval.
@@ -518,6 +533,8 @@ func (ng *Engine) cumulativeSubqueryOffset(path []Node) time.Duration {
518533

519534
func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *EvalStmt) (storage.Querier, storage.Warnings, error) {
520535
var maxOffset time.Duration
536+
var aggregationWindow int64
537+
521538
Inspect(s.Expr, func(node Node, path []Node) error {
522539
subqOffset := ng.cumulativeSubqueryOffset(path)
523540
switch n := node.(type) {
@@ -529,6 +546,7 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
529546
maxOffset = n.Offset + LookbackDelta + subqOffset
530547
}
531548
case *MatrixSelector:
549+
aggregationWindow = n.Range.Nanoseconds() / 1000000
532550
if maxOffset < n.Range+subqOffset {
533551
maxOffset = n.Range + subqOffset
534552
}
@@ -556,21 +574,19 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
556574
Step: durationToInt64Millis(s.Interval),
557575
}
558576

577+
querier.(*tsdb.V3ioPromQuerier).UseAggregates = isV3ioEligibleQueryExpr(s.Expr)
578+
559579
switch n := node.(type) {
560580
case *VectorSelector:
561581
params.Start = params.Start - durationMilliseconds(LookbackDelta)
562582
params.Func = extractFuncFromPath(path)
583+
params.AggregationWindow = aggregationWindow
563584
if n.Offset > 0 {
564585
offsetMilliseconds := durationMilliseconds(n.Offset)
565586
params.Start = params.Start - offsetMilliseconds
566587
params.End = params.End - offsetMilliseconds
567588
}
568589

569-
switch e := s.Expr.(type) {
570-
case *AggregateExpr:
571-
querier.(*tsdb.V3ioPromQuerier).UseAggregates = isV3ioEligibleQueryExpr(e)
572-
}
573-
574590
level.Debug(ng.logger).Log("msg", "Querying v3io vector selector",
575591
"useV3ioAggregations", querier.(*tsdb.V3ioPromQuerier).UseAggregates,
576592
"use3ioAggregationConfig", querier.(*tsdb.V3ioPromQuerier).UseAggregatesConfig)
@@ -587,6 +603,7 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
587603
// For all matrix queries we want to ensure that we have (end-start) + range selected
588604
// this way we have `range` data before the start time
589605
params.Start = params.Start - durationMilliseconds(n.Range)
606+
params.AggregationWindow = aggregationWindow
590607
if n.Offset > 0 {
591608
offsetMilliseconds := durationMilliseconds(n.Offset)
592609
params.Start = params.Start - offsetMilliseconds
@@ -977,6 +994,10 @@ func (ev *evaluator) eval(expr Expr) Value {
977994
otherInArgs := make([]Vector, len(e.Args))
978995
for i, e := range e.Args {
979996
if i != matrixArgIndex {
997+
if ev.useV3ioAggregations {
998+
return ev.emptyAggregation(e)
999+
}
1000+
9801001
otherArgs[i] = ev.eval(e).(Matrix)
9811002
otherInArgs[i] = Vector{Sample{}}
9821003
inArgs[i] = otherInArgs[i]
@@ -1906,33 +1927,34 @@ func (ev *evaluator) emptyAggregation(e Expr) Matrix {
19061927
}
19071928

19081929
func isV3ioEligibleAggregation(op ItemType) bool {
1909-
supportedV3ioAggregations := []ItemType{itemAvg, itemCount, itemSum, itemMin, itemMax, itemStddev, itemStdvar}
1910-
return containsItemType(op, supportedV3ioAggregations)
1930+
return supportedV3ioAggregations[op]
19111931
}
19121932

1913-
func isV3ioEligibleQueryExpr(e *AggregateExpr) bool {
1914-
if !isV3ioEligibleAggregation(e.Op) {
1915-
return false
1916-
}
1917-
if e.Without {
1918-
return false
1919-
}
1920-
// Currently only supports non-nested functions.
1921-
// Not supported - avg(max_over_time(cpu[10m])), Supported - avg(cpu)
1922-
if e, ok := e.Expr.(*Call); ok {
1923-
if e.Func != nil {
1924-
return false
1925-
}
1926-
}
1927-
return true
1933+
func isV3ioEligibleFunction(function string) bool {
1934+
return supportedV3ioFunctions[function]
19281935
}
19291936

1930-
func containsItemType(item ItemType, slice []ItemType) bool {
1931-
for _, curr := range slice {
1932-
if curr == item {
1933-
return true
1937+
func isV3ioEligibleQueryExpr(e Expr) bool {
1938+
switch expr := e.(type) {
1939+
case *AggregateExpr:
1940+
if !isV3ioEligibleAggregation(expr.Op) {
1941+
return false
1942+
}
1943+
if expr.Without {
1944+
return false
19341945
}
1946+
// Currently only supports non-nested functions.
1947+
// Not supported - avg(max_over_time(cpu[10m])), Supported - avg(cpu)
1948+
if e, ok := expr.Expr.(*Call); ok {
1949+
if e.Func != nil {
1950+
return false
1951+
}
1952+
}
1953+
return true
1954+
case *Call:
1955+
return isV3ioEligibleFunction(expr.Func.Name)
19351956
}
1957+
19361958
return false
19371959
}
19381960

storage/tsdb/promtsdb.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (promQuery *V3ioPromQuerier) UseV3ioAggregations() bool {
8686

8787
// Select returns a set of series that matches the given label matchers.
8888
func (promQuery *V3ioPromQuerier) Select(params *storage.SelectParams, oms ...*labels.Matcher) (storage.SeriesSet, storage.Warnings, error) {
89-
name, filter, functions := match2filter(oms, promQuery.logger)
89+
name, filter, function := match2filter(oms, promQuery.logger)
9090
noAggr := false
9191

9292
// if a nil params is passed we assume it's a metadata query, so we fetch only the different labelsets withtout data.
@@ -100,28 +100,34 @@ func (promQuery *V3ioPromQuerier) Select(params *storage.SelectParams, oms ...*l
100100
}
101101

102102
promQuery.logger.Debug("SelectParams: %+v", params)
103+
overTimeSuffix := "_over_time"
103104

104105
if params.Func != "" {
105106
// only pass xx_over_time functions (just the xx part)
106107
// TODO: support count/stdxx, require changes in Prometheus: promql/functions.go, not calc aggregate twice
107-
if strings.HasSuffix(params.Func, "_over_time") {
108-
f := params.Func[0:3]
109-
if params.Step == 0 && (f == "min" || f == "max" || f == "sum" || f == "avg") {
110-
functions = f
108+
if strings.HasSuffix(params.Func, overTimeSuffix) {
109+
if promQuery.UseAggregates && promQuery.UseAggregatesConfig {
110+
function = strings.TrimSuffix(params.Func, overTimeSuffix)
111111
} else {
112-
noAggr = true
112+
f := params.Func[0:3]
113+
if params.Step == 0 && (f == "min" || f == "max" || f == "sum" || f == "avg") {
114+
function = f
115+
} else {
116+
noAggr = true
117+
}
113118
}
114119
} else if promQuery.UseV3ioAggregations() {
115-
functions = fmt.Sprintf("%v_all", params.Func)
120+
function = fmt.Sprintf("%v_all", params.Func)
116121
}
117122
}
118123

119124
selectParams := &pquerier.SelectParams{Name: name,
120-
Functions: functions,
121-
Step: params.Step,
122-
Filter: filter,
123-
From: promQuery.mint,
124-
To: promQuery.maxt}
125+
Functions: function,
126+
Step: params.Step,
127+
Filter: filter,
128+
From: promQuery.mint,
129+
To: promQuery.maxt,
130+
AggregationWindow: params.AggregationWindow}
125131

126132
set, err := promQuery.v3ioQuerier.SelectProm(selectParams, noAggr)
127133
return &V3ioPromSeriesSet{s: set}, nil, err

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ github.com/v3io/frames
301301
github.com/v3io/frames/pb
302302
# github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2
303303
github.com/v3io/v3io-go-http
304-
# github.com/v3io/v3io-tsdb v0.9.0 => github.com/v3io/v3io-tsdb v0.9.0
304+
# github.com/v3io/v3io-tsdb v0.9.0 => github.com/v3io/v3io-tsdb v0.0.0-20190410160018-de081cf7a8519d2c67e31b6202046b1defa87559
305305
github.com/v3io/v3io-tsdb/pkg/aggregate
306306
github.com/v3io/v3io-tsdb/pkg/appender
307307
github.com/v3io/v3io-tsdb/pkg/config

0 commit comments

Comments
 (0)