Prometheus: Support 1ms resolution intervals (#44707)

* Prometheus: Support 1ms resolution in time ranges

* UI: Support 1ms resolution in time ranges
This commit is contained in:
Dan Keder
2022-06-29 07:39:50 +02:00
committed by GitHub
parent d32ec75661
commit 9595fd6b66
11 changed files with 188 additions and 16 deletions
+8 -6
View File
@@ -15,12 +15,13 @@ type DateFormats struct {
}
type DateFormatIntervals struct {
Second string `json:"second"`
Minute string `json:"minute"`
Hour string `json:"hour"`
Day string `json:"day"`
Month string `json:"month"`
Year string `json:"year"`
Millisecond string `json:"millisecond"`
Second string `json:"second"`
Minute string `json:"minute"`
Hour string `json:"hour"`
Day string `json:"day"`
Month string `json:"month"`
Year string `json:"year"`
}
const localBrowser = "browser"
@@ -42,6 +43,7 @@ func valueAsTimezone(section *ini.Section, keyName string) (string, error) {
func (cfg *Cfg) readDateFormats() {
dateFormats := cfg.Raw.Section("date_formats")
cfg.DateFormats.FullDate = valueAsString(dateFormats, "full_date", "YYYY-MM-DD HH:mm:ss")
cfg.DateFormats.Interval.Millisecond = valueAsString(dateFormats, "interval_millisecond", "HH:mm:ss.SSS")
cfg.DateFormats.Interval.Second = valueAsString(dateFormats, "interval_second", "HH:mm:ss")
cfg.DateFormats.Interval.Minute = valueAsString(dateFormats, "interval_minute", "HH:mm")
cfg.DateFormats.Interval.Hour = valueAsString(dateFormats, "interval_hour", "MM-DD HH:mm")
@@ -104,7 +104,7 @@ func TestTimeSeriesQuery(t *testing.T) {
t.Run("appends graph_period to the query", func(t *testing.T) {
query := &cloudMonitoringTimeSeriesQuery{}
assert.Equal(t, query.appendGraphPeriod(&backend.QueryDataRequest{Queries: []backend.DataQuery{{}}}), " | graph_period 10ms")
assert.Equal(t, query.appendGraphPeriod(&backend.QueryDataRequest{Queries: []backend.DataQuery{{}}}), " | graph_period 1ms")
})
t.Run("skips graph_period if disabled", func(t *testing.T) {
+3
View File
@@ -159,6 +159,9 @@ func FormatDuration(inter time.Duration) string {
//nolint: gocyclo
func roundInterval(interval time.Duration) time.Duration {
switch {
// 0.01s
case interval <= 10*time.Millisecond:
return time.Millisecond * 1 // 0.001s
// 0.015s
case interval <= 15*time.Millisecond:
return time.Millisecond * 10 // 0.01s
+2
View File
@@ -70,6 +70,8 @@ func TestRoundInterval(t *testing.T) {
interval time.Duration
expected time.Duration
}{
{"10ms", time.Millisecond * 10, time.Millisecond * 1},
{"15ms", time.Millisecond * 15, time.Millisecond * 10},
{"30ms", time.Millisecond * 30, time.Millisecond * 20},
{"45ms", time.Millisecond * 45, time.Millisecond * 50},
}
@@ -630,7 +630,9 @@ func newDataFrame(name string, typ string, fields ...*data.Field) *data.Frame {
}
func alignTimeRange(t time.Time, step time.Duration, offset int64) time.Time {
return time.Unix(int64(math.Floor((float64(t.Unix()+offset)/step.Seconds()))*step.Seconds()-float64(offset)), 0)
offsetNano := float64(offset * 1e9)
stepNano := float64(step.Nanoseconds())
return time.Unix(0, int64(math.Floor((float64(t.UnixNano())+offsetNano)/stepNano)*stepNano-offsetNano))
}
func isVariableInterval(interval string) bool {