Skip to content

Commit 2682263

Browse files
committed
feat: support grafana-polystat-plugin
1 parent 8fe3630 commit 2682263

File tree

4 files changed

+629
-0
lines changed

4 files changed

+629
-0
lines changed

observability-lib/grafana/builder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"github.com/grafana/grafana-foundation-sdk/go/cog/plugins"
99
"github.com/grafana/grafana-foundation-sdk/go/common"
1010
"github.com/grafana/grafana-foundation-sdk/go/dashboard"
11+
1112
"github.com/smartcontractkit/chainlink-common/observability-lib/grafana/businessvariable"
13+
"github.com/smartcontractkit/chainlink-common/observability-lib/grafana/polystat"
1214
)
1315

1416
type Builder struct {
@@ -35,6 +37,7 @@ type BuilderOptions struct {
3537
func NewBuilder(options *BuilderOptions) *Builder {
3638
plugins.RegisterDefaultPlugins()
3739
cog.NewRuntime().RegisterPanelcfgVariant(businessvariable.VariantConfig())
40+
cog.NewRuntime().RegisterPanelcfgVariant(polystat.VariantConfig())
3841

3942
builder := &Builder{}
4043

@@ -113,6 +116,9 @@ func (b *Builder) AddPanel(panel ...*Panel) {
113116
} else if item.businessVariablePanelBuilder != nil {
114117
item.businessVariablePanelBuilder.Id(panelID)
115118
b.dashboardBuilder.WithPanel(item.businessVariablePanelBuilder)
119+
} else if item.polystatPanelBuilder != nil {
120+
item.polystatPanelBuilder.Id(panelID)
121+
b.dashboardBuilder.WithPanel(item.polystatPanelBuilder)
116122
}
117123
if item.alertBuilders != nil && len(item.alertBuilders) > 0 {
118124
b.AddAlert(item.alertBuilders...)

observability-lib/grafana/panels.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import (
1515
"github.com/grafana/grafana-foundation-sdk/go/table"
1616
"github.com/grafana/grafana-foundation-sdk/go/text"
1717
"github.com/grafana/grafana-foundation-sdk/go/timeseries"
18+
1819
"github.com/smartcontractkit/chainlink-common/observability-lib/grafana/businessvariable"
20+
"github.com/smartcontractkit/chainlink-common/observability-lib/grafana/polystat"
1921
)
2022

2123
type QueryType string
@@ -180,6 +182,7 @@ type Panel struct {
180182
textPanelBuilder *text.PanelBuilder
181183
histogramPanelBuilder *histogram.PanelBuilder
182184
businessVariablePanelBuilder *businessvariable.PanelBuilder
185+
polystatPanelBuilder *polystat.PanelBuilder
183186
alertBuilders []*alerting.RuleBuilder
184187
}
185188

@@ -1092,3 +1095,130 @@ func NewBusinessVariablePanel(options *BusinessVariablePanelOptions) *Panel {
10921095
businessVariablePanelBuilder: newPanel,
10931096
}
10941097
}
1098+
1099+
type PolystatPanelOptions struct {
1100+
*PanelOptions
1101+
Queries []Query
1102+
OperatorName polystat.OperatorName
1103+
PolygonGlobalFillColor string
1104+
PolygonSize polystat.PolygonSize
1105+
Columns *int
1106+
Rows *int
1107+
DisplayLimit *int
1108+
DefaultClickThrough string
1109+
DefaultClickThroughNewTab bool
1110+
DefaultClickThroughSanitize bool
1111+
AnimationSpeed *int
1112+
Radius string
1113+
TooltipDisplayMode string
1114+
TooltipPrimarySortBy polystat.SortByField
1115+
TooltipPrimarySortDirection polystat.SortByDirection
1116+
TooltipSecondarySortBy polystat.SortByField
1117+
TooltipSecondarySortDirection polystat.SortByDirection
1118+
GlobalUnitFormat string
1119+
GlobalDecimals *int
1120+
GlobalDisplayMode string
1121+
GlobalDisplayTextTriggeredEmpty string
1122+
GlobalThresholds []polystat.Threshold
1123+
}
1124+
1125+
func NewPolystatPanel(options *PolystatPanelOptions) *Panel {
1126+
setDefaults(options.PanelOptions)
1127+
1128+
newPanel := polystat.NewPanelBuilder().
1129+
Datasource(datasourceRef(options.Datasource)).
1130+
Title(*options.Title).
1131+
Description(options.Description).
1132+
Transparent(options.Transparent).
1133+
Span(options.Span).
1134+
Height(options.Height).
1135+
OperatorName(options.OperatorName)
1136+
1137+
if options.PolygonGlobalFillColor != "" {
1138+
newPanel.PolygonGlobalFillColor(options.PolygonGlobalFillColor)
1139+
}
1140+
1141+
if options.PolygonSize != 0 {
1142+
newPanel.PolygonSize(options.PolygonSize)
1143+
}
1144+
1145+
if options.Columns != nil {
1146+
newPanel.Columns(*options.Columns)
1147+
}
1148+
1149+
if options.Rows != nil {
1150+
newPanel.Rows(*options.Rows)
1151+
}
1152+
1153+
if options.DisplayLimit != nil {
1154+
newPanel.DisplayLimit(*options.DisplayLimit)
1155+
}
1156+
1157+
if options.DefaultClickThrough != "" {
1158+
newPanel.DefaultClickThrough(options.DefaultClickThrough)
1159+
}
1160+
1161+
if options.DefaultClickThroughNewTab {
1162+
newPanel.DefaultClickThroughNewTab(options.DefaultClickThroughNewTab)
1163+
}
1164+
1165+
if options.DefaultClickThroughSanitize {
1166+
newPanel.DefaultClickThroughSanitize(options.DefaultClickThroughSanitize)
1167+
}
1168+
1169+
if options.AnimationSpeed != nil {
1170+
newPanel.AnimationSpeed(*options.AnimationSpeed)
1171+
}
1172+
1173+
if options.Radius != "" {
1174+
newPanel.Radius(options.Radius)
1175+
}
1176+
1177+
if options.TooltipDisplayMode != "" {
1178+
newPanel.TooltipDisplayMode(options.TooltipDisplayMode)
1179+
}
1180+
1181+
if options.TooltipPrimarySortBy != "" {
1182+
newPanel.TooltipPrimarySortBy(options.TooltipPrimarySortBy)
1183+
}
1184+
1185+
if options.TooltipPrimarySortDirection != "" {
1186+
newPanel.TooltipPrimarySortDirection(options.TooltipPrimarySortDirection)
1187+
}
1188+
1189+
if options.TooltipSecondarySortBy != "" {
1190+
newPanel.TooltipSecondarySortBy(options.TooltipSecondarySortBy)
1191+
}
1192+
1193+
if options.TooltipSecondarySortDirection != "" {
1194+
newPanel.TooltipSecondarySortDirection(options.TooltipSecondarySortDirection)
1195+
}
1196+
1197+
if options.GlobalUnitFormat != "" {
1198+
newPanel.GlobalUnitFormat(options.GlobalUnitFormat)
1199+
}
1200+
1201+
if options.GlobalDecimals != nil {
1202+
newPanel.GlobalDecimals(*options.GlobalDecimals)
1203+
}
1204+
1205+
if options.GlobalDisplayMode != "" {
1206+
newPanel.GlobalDisplayMode(options.GlobalDisplayMode)
1207+
}
1208+
1209+
if options.GlobalDisplayTextTriggeredEmpty != "" {
1210+
newPanel.GlobalDisplayTextTriggeredEmpty(options.GlobalDisplayTextTriggeredEmpty)
1211+
}
1212+
1213+
if len(options.GlobalThresholds) > 0 {
1214+
newPanel.GlobalThresholds(options.GlobalThresholds)
1215+
}
1216+
1217+
for _, query := range options.Queries {
1218+
newPanel.WithTarget(newQuery(query))
1219+
}
1220+
1221+
return &Panel{
1222+
polystatPanelBuilder: newPanel,
1223+
}
1224+
}

0 commit comments

Comments
 (0)