mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
037fd9cc8c
* loki: alerting: adjust step-calculation to be the same as in frontend * loki: simplified test * lint fix
32 lines
747 B
Go
32 lines
747 B
Go
package loki
|
|
|
|
import (
|
|
"math"
|
|
"time"
|
|
)
|
|
|
|
// round the duration to the nearest millisecond larger-or-equal-to the duration
|
|
func ceilMs(duration time.Duration) time.Duration {
|
|
floatMs := float64(duration.Nanoseconds()) / 1000.0 / 1000.0
|
|
ceilMs := math.Ceil(floatMs)
|
|
return time.Duration(ceilMs) * time.Millisecond
|
|
}
|
|
|
|
func durationMax(d1 time.Duration, d2 time.Duration) time.Duration {
|
|
if d1.Nanoseconds() >= d2.Nanoseconds() {
|
|
return d1
|
|
} else {
|
|
return d2
|
|
}
|
|
}
|
|
|
|
func calculateStep(baseInterval time.Duration, timeRange time.Duration, resolution int64) time.Duration {
|
|
step := time.Duration(baseInterval.Nanoseconds() * resolution)
|
|
|
|
safeStep := timeRange / 11000
|
|
|
|
chosenStep := durationMax(step, safeStep)
|
|
|
|
return ceilMs(chosenStep)
|
|
}
|