Skip to content

Commit fa62eff

Browse files
committed
Extend grafana interval validation; fix row.Collapsed option usage
1 parent 876eeb2 commit fa62eff

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

observability-lib/grafana/builder.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ func (b *Builder) AddVars(items ...cog.Builder[dashboard.VariableModel]) {
8080
func (b *Builder) AddRow(title string, options ...RowOptions) {
8181
row := dashboard.NewRowBuilder(title)
8282
for _, o := range options {
83-
if o.Collapsed {
84-
row.Collapsed(true)
85-
}
83+
row.Collapsed(o.Collapsed)
8684
}
8785
b.dashboardBuilder.WithRow(row)
8886
}

observability-lib/grafana/panels.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package grafana
22

33
import (
4-
"time"
4+
"regexp"
5+
"strconv"
56

67
"github.com/grafana/grafana-foundation-sdk/go/alerting"
78
"github.com/grafana/grafana-foundation-sdk/go/bargauge"
@@ -58,9 +59,14 @@ func newQuery(query Query) *prometheus.DataqueryBuilder {
5859
return res
5960
}
6061

61-
func isValidDuration(s string) bool {
62-
_, err := time.ParseDuration(s)
63-
return err == nil
62+
func isValidDuration(interval string) bool {
63+
var grafanaDurationRegexp = regexp.MustCompile(`^(\d+)(ms|[smhdwMy])$`) // ms, s, m, h, d, w, M, y
64+
m := grafanaDurationRegexp.FindStringSubmatch(interval)
65+
if m == nil {
66+
return false
67+
}
68+
n, _ := strconv.ParseInt(m[1], 10, 64)
69+
return n > 0
6470
}
6571

6672
type LegendOptions struct {

0 commit comments

Comments
 (0)