Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(observability-lib): can specify tooltip on timeseries panels and enable by default #982

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading