mirror of https://github.com/prometheus/prometheus
Merge pull request #138 from prometheus/julius-fix-aliasing
Correct delta()/rate() intervals and temporal aliasing.pull/145/head
commit
62f33f1fc2
|
@ -100,6 +100,24 @@ func deltaImpl(timestamp time.Time, view *viewAdapter, args []Node) interface{}
|
||||||
lastValue = currentValue
|
lastValue = currentValue
|
||||||
}
|
}
|
||||||
resultValue := lastValue - samples.Values[0].Value + counterCorrection
|
resultValue := lastValue - samples.Values[0].Value + counterCorrection
|
||||||
|
|
||||||
|
targetInterval := args[0].(*MatrixLiteral).interval
|
||||||
|
sampledInterval := samples.Values[len(samples.Values)-1].Timestamp.Sub(samples.Values[0].Timestamp)
|
||||||
|
if sampledInterval == 0 {
|
||||||
|
// Only found one sample. Cannot compute a rate from this.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Correct for differences in target vs. actual delta interval.
|
||||||
|
//
|
||||||
|
// Above, we didn't actually calculate the delta for the specified target
|
||||||
|
// interval, but for an interval between the first and last found samples
|
||||||
|
// under the target interval, which will usually have less time between
|
||||||
|
// them. Depending on how many samples are found under a target interval,
|
||||||
|
// the delta results are distorted and temporal aliasing occurs (ugly
|
||||||
|
// bumps). This effect is corrected for below.
|
||||||
|
intervalCorrection := model.SampleValue(targetInterval) / model.SampleValue(sampledInterval)
|
||||||
|
resultValue *= intervalCorrection
|
||||||
|
|
||||||
resultSample := model.Sample{
|
resultSample := model.Sample{
|
||||||
Metric: samples.Metric,
|
Metric: samples.Metric,
|
||||||
Value: resultValue,
|
Value: resultValue,
|
||||||
|
|
|
@ -226,6 +226,12 @@ var expressionTests = []struct {
|
||||||
},
|
},
|
||||||
fullRanges: 0,
|
fullRanges: 0,
|
||||||
intervalRanges: 8,
|
intervalRanges: 8,
|
||||||
|
}, {
|
||||||
|
// Deltas should be adjusted for target interval vs. samples under target interval.
|
||||||
|
expr: "delta(http_requests{group='canary',instance='1',job='app-server'}[18m], 1)",
|
||||||
|
output: []string{"http_requests{group='canary',instance='1',job='app-server'} => 288 @[%v]"},
|
||||||
|
fullRanges: 1,
|
||||||
|
intervalRanges: 0,
|
||||||
}, {
|
}, {
|
||||||
// Empty expressions shouldn't parse.
|
// Empty expressions shouldn't parse.
|
||||||
expr: "",
|
expr: "",
|
||||||
|
|
Loading…
Reference in New Issue