Skip to content

Commit f04b59e

Browse files
authored
feat(observability-lib): add SortBy and SortDesc to LegendOptions (#1799)
* feat(observability-lib): add SortBy and SortDesc to LegendOptions Expose the underlying Grafana SDK's VizLegendOptions sorting fields to allow legend tables to be sorted by a specific calculation field (e.g., "Last *", "Max") in ascending or descending order. This enables dashboards to surface the most important series at the top of the legend table, improving readability for error rate panels. * refactor: simplify SortDesc handling per review feedback Only set SortDesc when SortBy is specified, and pass the value directly rather than hardcoding true. * fix: address review comments - Fix comment examples to match actual Grafana format ("Last *", "Max") - Only set SortDesc when true to avoid unnecessary explicit false values
1 parent 86b1030 commit f04b59e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

observability-lib/grafana/panels.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ type LegendOptions struct {
5555
Placement common.LegendPlacement
5656
DisplayMode common.LegendDisplayMode
5757
Calcs []string
58+
SortBy string // Sort legend by this field (e.g., "Last *", "Max", "Mean")
59+
SortDesc bool // Sort in descending order
5860
}
5961

6062
func newLegend(options *LegendOptions) *common.VizLegendOptionsBuilder {
@@ -77,6 +79,13 @@ func newLegend(options *LegendOptions) *common.VizLegendOptionsBuilder {
7779

7880
builder.DisplayMode(options.DisplayMode)
7981

82+
if options.SortBy != "" {
83+
builder.SortBy(options.SortBy)
84+
if options.SortDesc {
85+
builder.SortDesc(true)
86+
}
87+
}
88+
8089
return builder
8190
}
8291

0 commit comments

Comments
 (0)