Skip to content

Commit a058654

Browse files
authored
[CRE-1135] Add reduce options to grafana stats panel
1 parent b83c254 commit a058654

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

observability-lib/grafana/panels.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,15 @@ func setDefaults(options *PanelOptions) {
202202

203203
type StatPanelOptions struct {
204204
*PanelOptions
205-
TextSize float64
206-
ValueSize float64
207-
JustifyMode common.BigValueJustifyMode
208-
ColorMode common.BigValueColorMode
209-
GraphMode common.BigValueGraphMode
210-
TextMode common.BigValueTextMode
211-
Orientation common.VizOrientation
212-
Mappings []dashboard.ValueMapping
205+
TextSize float64
206+
ValueSize float64
207+
JustifyMode common.BigValueJustifyMode
208+
ColorMode common.BigValueColorMode
209+
GraphMode common.BigValueGraphMode
210+
TextMode common.BigValueTextMode
211+
Orientation common.VizOrientation
212+
Mappings []dashboard.ValueMapping
213+
ReduceOptions *common.ReduceDataOptionsBuilder
213214
}
214215

215216
func NewStatPanel(options *StatPanelOptions) *Panel {
@@ -231,6 +232,10 @@ func NewStatPanel(options *StatPanelOptions) *Panel {
231232
options.Orientation = common.VizOrientationAuto
232233
}
233234

235+
if options.ReduceOptions == nil {
236+
options.ReduceOptions = common.NewReduceDataOptionsBuilder().Calcs([]string{"last"})
237+
}
238+
234239
newPanel := stat.NewPanelBuilder().
235240
Datasource(datasourceRef(options.Datasource)).
236241
Title(*options.Title).
@@ -247,7 +252,7 @@ func NewStatPanel(options *StatPanelOptions) *Panel {
247252
Orientation(options.Orientation).
248253
JustifyMode(options.JustifyMode).
249254
Mappings(options.Mappings).
250-
ReduceOptions(common.NewReduceDataOptionsBuilder().Calcs([]string{"last"}))
255+
ReduceOptions(options.ReduceOptions)
251256

252257
if options.Interval != "" {
253258
newPanel.Interval(options.Interval)

0 commit comments

Comments
 (0)