Skip to content

Commit

Permalink
Refactored withOverrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Ygnas committed Oct 9, 2023
1 parent bc30b01 commit 97559d1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 160 deletions.
34 changes: 11 additions & 23 deletions src/dashboards/gatewayclasses.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ gwapi.dashboard('GatewayClasses', 'gatewayapigatewayclass', [
gwapi.stat('Total', 3, 2, 0, 1, 'Total number of GatewayClasses across all clusters', 'count(gatewayapi_gatewayclass_info)'),
gwapi.stat('Accepted', 3, 2, 2, 1, 'Total GatewayClasses with an Accepted state of True', 'count(gatewayapi_gatewayclass_status{type="Accepted"} > 0)'),
gwapi.table('GatewayClasses', 6, 10, 4, 1, 'gatewayapi_gatewayclass_created')
+ g.panel.table.standardOptions.withOverrides([
g.panel.table.fieldOverride.byName.new('Created At')
+ g.panel.table.fieldOverride.byName.withProperty(
'unit',
'dateTimeAsIso'
),
+ var.withOverrides([
var.overrideNameWithProp('Created At', 'unit', 'dateTimeAsIso')
])
+ g.panel.table.queryOptions.withTransformations([
g.panel.table.transformation.withId('filterFieldsByName')
Expand Down Expand Up @@ -60,19 +56,15 @@ gwapi.dashboard('GatewayClasses', 'gatewayapigatewayclass', [
}),
]),
gwapi.table('Gateways (by GatewayClass)', 6, 10, 14, 1, 'gatewayapi_gateway_info')
+ g.panel.table.standardOptions.withOverrides([
g.panel.table.fieldOverride.byName.new('Name')
+ g.panel.table.fieldOverride.byName.withProperty(
'links',
[{
+ var.withOverrides([
var.overrideName('Name')
+ var.overrideProp('links', [
{
title: 'Gateway Details',
url: '/d/gatewayapigateways/gateway-api-state-gateways?var-gateway=${__value.text}',
}]
)
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.displayMode',
'color-text',
),
}
])
+ var.overrideProp('custom.displayMode', 'color-text')
])
+ g.panel.table.queryOptions.withTransformations([
g.panel.table.transformation.withId('filterFieldsByName')
Expand Down Expand Up @@ -108,12 +100,8 @@ gwapi.dashboard('GatewayClasses', 'gatewayapigatewayclass', [
}),
]),
gwapi.table('Supported Features (by GatewayClass)', 6, 20, 4, 7, 'gatewayapi_gatewayclass_status_supported_features{name="$gatewayclass"}')
+ g.panel.table.standardOptions.withOverrides([
g.panel.table.fieldOverride.byName.new('name')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
333
),
+ var.withOverrides([
var.overrideNameWithProp('name', 'custom.width', 333)
])
+ g.panel.table.queryOptions.withTransformations([
g.panel.table.transformation.withId('filterFieldsByName')
Expand Down
177 changes: 40 additions & 137 deletions src/dashboards/gateways.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,14 @@ gwapi.dashboard('Gateways', 'gatewayapigateways', [
gwapi.stat('Total', 3, 2, 0, 1, 'Total number of Gateways across all namespaces', 'count(gatewayapi_gateway_info{name=~"$gateway"})'),
gwapi.stat('Unhealthy', 3, 2, 2, 1, 'Number of Gateways not in an Accepted and Programmed state', 'count((gatewayapi_gateway_status{name=~"$gateway",type="Accepted"} == 0) or (gatewayapi_gateway_status{name=~"$gateway",type="Programmed"} == 0)) or vector(0)'),
gwapi.table('Gateways', 6, 10, 4, 1, 'gatewayapi_gateway_created{name=~"$gateway"} * on(name, namespace, instance) group_right gatewayapi_gateway_info{name=~"$gateway"}')
+ g.panel.table.standardOptions.withOverrides([
g.panel.table.fieldOverride.byName.new('Created At')
+ g.panel.table.fieldOverride.byName.withProperty(
'unit',
'dateTimeAsIso'
),
g.panel.table.fieldOverride.byName.new('Kind')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'108'
),
g.panel.table.fieldOverride.byName.new('Version')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'98'
),
g.panel.table.fieldOverride.byName.new('Name')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'125'
),
])
+ var.withOverrides(
[
var.overrideNameWithProp('Created At', 'unit', 'dateTimeAsIso'),
var.overrideNameWithProp('Kind', 'custom.width', '108'),
var.overrideNameWithProp('Version', 'custom.width', '98'),
var.overrideNameWithProp('Name', 'custom.width', '125'),
],
)
+ g.panel.table.queryOptions.withTransformations([
g.panel.table.transformation.withId('filterFieldsByName')
+ g.panel.table.transformation.withOptions({
Expand Down Expand Up @@ -78,48 +64,18 @@ gwapi.dashboard('Gateways', 'gatewayapigateways', [
}),
]),
gwapi.table('Gateway Listeners', 6, 10, 14, 1, 'gatewayapi_gateway_listener_info{name=~"$gateway"}')
+ g.panel.table.standardOptions.withOverrides([
g.panel.table.fieldOverride.byName.new('Created At')
+ g.panel.table.fieldOverride.byName.withProperty(
'unit',
'dateTimeAsIso'
),
g.panel.table.fieldOverride.byName.new('Kind')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'108'
),
g.panel.table.fieldOverride.byName.new('Version')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'94'
),
g.panel.table.fieldOverride.byName.new('Listener Name')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'112'
),
g.panel.table.fieldOverride.byName.new('Hostname')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'163'
),
g.panel.table.fieldOverride.byName.new('Port')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'59'
),
g.panel.table.fieldOverride.byName.new('Protocol')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'77'
),
g.panel.table.fieldOverride.byName.new('Name')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'91'
),
])
+ var.withOverrides(
[
var.overrideNameWithProp('Created At', 'unit', 'dateTimeAsIso'),
var.overrideNameWithProp('Kind', 'custom.width', '108'),
var.overrideNameWithProp('Version', 'custom.width', '94'),
var.overrideNameWithProp('Listener Name', 'custom.width', '112'),
var.overrideNameWithProp('Hostname', 'custom.width', '163'),
var.overrideNameWithProp('Port', 'custom.width', '59'),
var.overrideNameWithProp('Protocol', 'custom.width', '77'),
var.overrideNameWithProp('Name', 'custom.width', '91'),
],
)
+ g.panel.table.queryOptions.withTransformations([
g.panel.table.transformation.withId('filterFieldsByName')
+ g.panel.table.transformation.withOptions({
Expand Down Expand Up @@ -174,48 +130,18 @@ gwapi.dashboard('Gateways', 'gatewayapigateways', [
gwapi.stat('Listeners', 3, 2, 0, 7, 'Total number of listeners across all Gateways', 'count(gatewayapi_gateway_listener_info{name=~"$gateway"})'),
gwapi.stat('Att. Routes', 3, 2, 2, 7, 'Total number of attached routes across all listeners', 'sum(gatewayapi_gateway_status_listener_attached_routes{name=~"$gateway"})'),
gwapi.table('Gateway Status Addresses', 6, 10, 4, 7, 'gatewayapi_gateway_status_address_info{name=~"$gateway"}')
+ g.panel.table.standardOptions.withOverrides([
g.panel.table.fieldOverride.byName.new('Created At')
+ g.panel.table.fieldOverride.byName.withProperty(
'unit',
'dateTimeAsIso'
),
g.panel.table.fieldOverride.byName.new('Kind')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'108'
),
g.panel.table.fieldOverride.byName.new('Version')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'94'
),
g.panel.table.fieldOverride.byName.new('Listener Name')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'119'
),
g.panel.table.fieldOverride.byName.new('Hostname')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'163'
),
g.panel.table.fieldOverride.byName.new('Port')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'59'
),
g.panel.table.fieldOverride.byName.new('Protocol')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'104'
),
g.panel.table.fieldOverride.byName.new('Name')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'136'
),
])
+ var.withOverrides(
[
var.overrideNameWithProp('Created At', 'unit', 'dateTimeAsIso'),
var.overrideNameWithProp('Kind', 'custom.width', '108'),
var.overrideNameWithProp('Version', 'custom.width', '94'),
var.overrideNameWithProp('Listener Name', 'custom.width', '119'),
var.overrideNameWithProp('Hostname', 'custom.width', '163'),
var.overrideNameWithProp('Port', 'custom.width', '59'),
var.overrideNameWithProp('Protocol', 'custom.width', '104'),
var.overrideNameWithProp('Name', 'custom.width', '136'),
],
)
+ g.panel.table.queryOptions.withTransformations([
g.panel.table.transformation.withId('filterFieldsByName')
+ g.panel.table.transformation.withOptions({
Expand Down Expand Up @@ -264,37 +190,14 @@ gwapi.dashboard('Gateways', 'gatewayapigateways', [
}),
]),
gwapi.table('Gateway Listener Status - Attached Routes', 6, 10, 14, 7, 'gatewayapi_gateway_status_listener_attached_routes{name=~"$gateway"}')
+ g.panel.table.standardOptions.withOverrides([
g.panel.table.fieldOverride.byName.new('Created At')
+ g.panel.table.fieldOverride.byName.withProperty(
'unit',
'dateTimeAsIso'
),
g.panel.table.fieldOverride.byName.new('Kind')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'113'
),
g.panel.table.fieldOverride.byName.new('Version')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'88'
),
g.panel.table.fieldOverride.byName.new('Name')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'167'
),
g.panel.table.fieldOverride.byName.new('Listener Name')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'167'
),
g.panel.table.fieldOverride.byName.new('# Attached Routes')
+ g.panel.table.fieldOverride.byName.withProperty(
'custom.width',
'137'
),
+ var.withOverrides(
[
var.overrideNameWithProp('Created At', 'unit', 'dateTimeAsIso'),
var.overrideNameWithProp('Kind', 'custom.width', '113'),
var.overrideNameWithProp('Version', 'custom.width', '88'),
var.overrideNameWithProp('Name', 'custom.width', '167'),
var.overrideNameWithProp('Listener Name', 'custom.width', '167'),
var.overrideNameWithProp('# Attached Routes', 'custom.width', '137'),
])
+ g.panel.table.queryOptions.withTransformations([
g.panel.table.transformation.withId('filterFieldsByName')
Expand Down
16 changes: 16 additions & 0 deletions src/dashboards/lib/gwapi/variables.libsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local g = import '../g.libsonnet';
local var = g.dashboard.variable;
local table = g.panel.table;

{
datasource:
Expand Down Expand Up @@ -30,4 +31,19 @@ local var = g.dashboard.variable;
+ var.query.selectionOptions.withIncludeAll(true)
+ var.query.selectionOptions.withMulti(true)
+ var.query.generalOptions.withLabel(label),

withOverrides(fieldOverride):
table.standardOptions.withOverrides(
fieldOverride
),

overrideNameWithProp(name, id, value):
table.fieldOverride.byName.new(name)
+ table.fieldOverride.byName.withProperty(id, value),

overrideName(name):
table.fieldOverride.byName.new(name),

overrideProp(id, value):
table.fieldOverride.byName.withProperty(id, value),
}

0 comments on commit 97559d1

Please sign in to comment.