From 9b2f9ef755857edbee5a8187ef1bf41aaa7cbc33 Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 10 Jan 2025 21:17:31 +0100 Subject: [PATCH] feat(observability-lib): can specify max data points on panels (#981) --- observability-lib/grafana/panels.go | 49 ++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/observability-lib/grafana/panels.go b/observability-lib/grafana/panels.go index 818b41cdb..2e4b20c6a 100644 --- a/observability-lib/grafana/panels.go +++ b/observability-lib/grafana/panels.go @@ -120,20 +120,21 @@ func newToolTip(options *ToolTipOptions) *common.VizTooltipOptionsBuilder { } type PanelOptions struct { - Datasource string - Title string - Description string - Span uint32 - Height uint32 - Decimals float64 - Unit string - NoValue string - Min *float64 - Max *float64 - Query []Query - Threshold *ThresholdOptions - Transform *TransformOptions - ColorScheme dashboard.FieldColorModeId + Datasource string + Title string + Description string + Span uint32 + Height uint32 + Decimals float64 + Unit string + NoValue string + Min *float64 + Max *float64 + MaxDataPoints *float64 + Query []Query + Threshold *ThresholdOptions + Transform *TransformOptions + ColorScheme dashboard.FieldColorModeId } type Panel struct { @@ -214,6 +215,10 @@ func NewStatPanel(options *StatPanelOptions) *Panel { Mappings(options.Mappings). ReduceOptions(common.NewReduceDataOptionsBuilder().Calcs([]string{"last"})) + if options.MaxDataPoints != nil { + newPanel.MaxDataPoints(*options.MaxDataPoints) + } + if options.Min != nil { newPanel.Min(*options.Min) } @@ -296,6 +301,10 @@ func NewTimeSeriesPanel(options *TimeSeriesPanelOptions) *Panel { ). Tooltip(newToolTip(options.ToolTipOptions)) + if options.MaxDataPoints != nil { + newPanel.MaxDataPoints(*options.MaxDataPoints) + } + if options.Min != nil { newPanel.Min(*options.Min) } @@ -363,6 +372,10 @@ func NewGaugePanel(options *GaugePanelOptions) *Panel { Calcs([]string{"lastNotNull"}).Values(false), ) + if options.MaxDataPoints != nil { + newPanel.MaxDataPoints(*options.MaxDataPoints) + } + if options.Min != nil { newPanel.Min(*options.Min) } @@ -405,6 +418,10 @@ func NewTablePanel(options *TablePanelOptions) *Panel { Unit(options.Unit). NoValue(options.NoValue) + if options.MaxDataPoints != nil { + newPanel.MaxDataPoints(*options.MaxDataPoints) + } + if options.Min != nil { newPanel.Min(*options.Min) } @@ -451,6 +468,10 @@ func NewLogPanel(options *LogPanelOptions) *Panel { NoValue(options.NoValue). PrettifyLogMessage(options.PrettifyJSON) + if options.MaxDataPoints != nil { + newPanel.MaxDataPoints(*options.MaxDataPoints) + } + if options.Min != nil { newPanel.Min(*options.Min) }