diff --git a/observability-lib/grafana/panels.go b/observability-lib/grafana/panels.go index 9869a2317..804d17efb 100644 --- a/observability-lib/grafana/panels.go +++ b/observability-lib/grafana/panels.go @@ -88,6 +88,37 @@ func newTransform(options *TransformOptions) dashboard.DataTransformerConfig { } } +type ToolTipOptions struct { + Mode common.TooltipDisplayMode + Sort common.SortOrder + MaxWidth *float64 + MaxHeight *float64 +} + +func newToolTip(options *ToolTipOptions) *common.VizTooltipOptionsBuilder { + if options.Mode == "" { + options.Mode = common.TooltipDisplayModeSingle + } + + if options.Sort == "" { + options.Sort = common.SortOrderNone + } + + builder := common.NewVizTooltipOptionsBuilder(). + Mode(options.Mode). + Sort(options.Sort) + + if options.MaxWidth != nil { + builder.MaxWidth(*options.MaxWidth) + } + + if options.MaxWidth != nil { + builder.MaxHeight(*options.MaxHeight) + } + + return builder +} + type PanelOptions struct { Datasource string Title string @@ -230,6 +261,7 @@ type TimeSeriesPanelOptions struct { FillOpacity float64 ScaleDistribution common.ScaleDistribution LegendOptions *LegendOptions + ToolTipOptions *ToolTipOptions ThresholdStyle common.GraphThresholdsStyleMode } @@ -244,6 +276,10 @@ func NewTimeSeriesPanel(options *TimeSeriesPanelOptions) *Panel { options.LegendOptions = &LegendOptions{} } + if options.ToolTipOptions == nil { + options.ToolTipOptions = &ToolTipOptions{} + } + newPanel := timeseries.NewPanelBuilder(). Datasource(datasourceRef(options.Datasource)). Title(options.Title). @@ -257,7 +293,8 @@ func NewTimeSeriesPanel(options *TimeSeriesPanelOptions) *Panel { Legend(newLegend(options.LegendOptions)). ScaleDistribution(common.NewScaleDistributionConfigBuilder(). Type(options.ScaleDistribution), - ) + ). + Tooltip(newToolTip(options.ToolTipOptions)) if options.Min != nil { newPanel.Min(*options.Min)