Loki: Implement step editor (#69648)
* Loki: Implement step editor * Update to keep value * Remove console.log * Remove white space * Update public/app/plugins/datasource/loki/querybuilder/components/LokiQueryBuilderOptions.tsx Co-authored-by: Matias Chomicki <matyax@gmail.com> * Import trim * Update using of step in split queries * Add tests * Add tests * Remove step interpolation --------- Co-authored-by: Matias Chomicki <matyax@gmail.com>
This commit is contained in:
co-authored by
Matias Chomicki
parent
66d2214c3b
commit
82c125d450
+15
-6
@@ -3,6 +3,8 @@ package loki
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/tsdb/intervalv2"
|
||||
)
|
||||
|
||||
// round the duration to the nearest millisecond larger-or-equal-to the duration
|
||||
@@ -20,12 +22,19 @@ func durationMax(d1 time.Duration, d2 time.Duration) time.Duration {
|
||||
}
|
||||
}
|
||||
|
||||
func calculateStep(baseInterval time.Duration, timeRange time.Duration, resolution int64) time.Duration {
|
||||
step := time.Duration(baseInterval.Nanoseconds() * resolution)
|
||||
func calculateStep(interval time.Duration, timeRange time.Duration, resolution int64, queryStep *string) (time.Duration, error) {
|
||||
// If we don't have step from query we calculate it from interval, time range and resolution
|
||||
if queryStep == nil || *queryStep == "" {
|
||||
step := time.Duration(interval.Nanoseconds() * resolution)
|
||||
safeStep := timeRange / 11000
|
||||
chosenStep := durationMax(step, safeStep)
|
||||
return ceilMs(chosenStep), nil
|
||||
}
|
||||
|
||||
safeStep := timeRange / 11000
|
||||
step, err := intervalv2.ParseIntervalStringToTimeDuration(*queryStep)
|
||||
if err != nil {
|
||||
return step, err
|
||||
}
|
||||
|
||||
chosenStep := durationMax(step, safeStep)
|
||||
|
||||
return ceilMs(chosenStep)
|
||||
return time.Duration(step.Nanoseconds() * resolution), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user