Skip to content

Commit f0f501b

Browse files
committed
Add query options Inreval to that may be used by interval/range vars
1 parent 6c311f0 commit f0f501b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

observability-lib/grafana/panels.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package grafana
22

33
import (
4+
"time"
5+
46
"github.com/grafana/grafana-foundation-sdk/go/alerting"
57
"github.com/grafana/grafana-foundation-sdk/go/bargauge"
68
"github.com/grafana/grafana-foundation-sdk/go/cog"
@@ -29,6 +31,7 @@ const (
2931
type Query struct {
3032
Expr string
3133
Legend string
34+
Interval string // i.e. 30s, 2m, a lower limit for the interval that will be sent to datasource and used by $__interval/range variables
3235
Instant bool
3336
Min float64
3437
Format prometheus.PromQueryFormat
@@ -41,6 +44,10 @@ func newQuery(query Query) *prometheus.DataqueryBuilder {
4144
LegendFormat(query.Legend).
4245
Format(query.Format)
4346

47+
if isValidDuration(query.Interval) {
48+
res.Interval(query.Interval)
49+
}
50+
4451
if query.Instant {
4552
res.Instant()
4653
}
@@ -51,6 +58,11 @@ func newQuery(query Query) *prometheus.DataqueryBuilder {
5158
return res
5259
}
5360

61+
func isValidDuration(s string) bool {
62+
_, err := time.ParseDuration(s)
63+
return err == nil
64+
}
65+
5466
type LegendOptions struct {
5567
Placement common.LegendPlacement
5668
DisplayMode common.LegendDisplayMode

0 commit comments

Comments
 (0)