File tree Expand file tree Collapse file tree
observability-lib/grafana Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package grafana
22
33import (
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 (
2931type 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+
5466type LegendOptions struct {
5567 Placement common.LegendPlacement
5668 DisplayMode common.LegendDisplayMode
You can’t perform that action at this time.
0 commit comments