Skip to content

Commit

Permalink
feat(observability-lib): can specify tooltip on timeseries panels and…
Browse files Browse the repository at this point in the history
… enable by default (#982)
  • Loading branch information
Atrax1 authored Jan 8, 2025
1 parent db7919d commit 47a52b1
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion observability-lib/grafana/panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.MaxHeight != nil {
builder.MaxHeight(*options.MaxHeight)
}

return builder
}

type PanelOptions struct {
Datasource string
Title string
Expand Down Expand Up @@ -230,6 +261,7 @@ type TimeSeriesPanelOptions struct {
FillOpacity float64
ScaleDistribution common.ScaleDistribution
LegendOptions *LegendOptions
ToolTipOptions *ToolTipOptions
ThresholdStyle common.GraphThresholdsStyleMode
}

Expand All @@ -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).
Expand All @@ -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)
Expand Down

0 comments on commit 47a52b1

Please sign in to comment.