Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
summarize(): in !alignToFrom case, return output in canonical format
Browse files Browse the repository at this point in the history
See #1811 for more details
Before, it was common for output to contain an extraneous point that
lies before 'from' (and wouldn't be rendered by Grafana in graph
panels), which made the output invalid.

This would result in trouble when

* combining such a series with another series
  (#1811)
* or when needing normalization
  (#1845)

This effectively slightly changes the output format, but is more robust.
  • Loading branch information
Dieterbe committed Jun 15, 2020
1 parent f9b0ce5 commit e413585
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions expr/func_summarize.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func summarizeValues(serie models.Series, aggFunc batch.AggFunc, interval, start

numPoints := len(serie.Datapoints)

// graphite-compatible bit

for ts, i := start, 0; i < numPoints && ts < end; ts += interval {
s := i
for ; i < numPoints && serie.Datapoints[i].Ts < ts+interval; i++ {
Expand All @@ -111,5 +113,11 @@ func summarizeValues(serie models.Series, aggFunc batch.AggFunc, interval, start
out = append(out, aggPoint)
}

// MT specific bit: if !s.alignToFrom we want the output to be canonical
// only thing needed is strip out the first point if its TS < from
if len(out) != 0 && out[0].Ts < serie.QueryFrom {
out = out[1:]
}

return out
}

0 comments on commit e413585

Please sign in to comment.