From 058e91e1f686b2ed100511ba9ccd95f17e22ccdc Mon Sep 17 00:00:00 2001 From: Duologic Date: Fri, 16 Feb 2024 20:02:57 +0100 Subject: [PATCH] fix: set some defaults --- dashboards/apiserver.libsonnet | 150 +++++++++++++++++---------------- dashboards/defaults.libsonnet | 2 +- 2 files changed, 78 insertions(+), 74 deletions(-) diff --git a/dashboards/apiserver.libsonnet b/dashboards/apiserver.libsonnet index 09eea9d38..64ebce6e3 100644 --- a/dashboards/apiserver.libsonnet +++ b/dashboards/apiserver.libsonnet @@ -1,82 +1,87 @@ local g = import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet'; local var = g.dashboard.variable; local stat = g.panel.stat; -local timeSeries = g.panel.timeSeries; -local override = timeSeries.standardOptions.override; - -local withGrafonnetLibDefaults(includeObsoleteFields=true) = - g.dashboard.withEditable(false) - + g.dashboard.time.withFrom('now-6h') - + g.dashboard.time.withTo('now') - + g.dashboard.withTimezone('browser'); - -local mystatpanel(title, description, query) = - stat.new(title) - + stat.panelOptions.withDescription(description) - + stat.panelOptions.withGridPos(w=6) - + stat.standardOptions.withUnit('percentunit') - + stat.standardOptions.withDecimals(3) - + stat.queryOptions.withTargets([ - g.query.prometheus.new( - '${datasource}', - query, - ), - ]); - -local myrequestspanel(title, description, query) = - timeSeries.new(title) - + timeSeries.panelOptions.withDescription(description) - + timeSeries.panelOptions.withGridPos(w=6) - + timeSeries.standardOptions.withUnit('reqps') - + timeSeries.fieldConfig.defaults.custom.withFillOpacity(100) - + timeSeries.fieldConfig.defaults.custom.stacking.withMode('normal') - + timeSeries.standardOptions.withOverrides([ - override.byRegexp.new('/2../i') + override.byRegexp.withProperty('color', '#56A64B'), - override.byRegexp.new('/3../i') + override.byRegexp.withProperty('color', '#F2CC0C'), - override.byRegexp.new('/4../i') + override.byRegexp.withProperty('color', '#3274D9'), - override.byRegexp.new('/5../i') + override.byRegexp.withProperty('color', '#E02F44'), - ]) - + timeSeries.queryOptions.withTargets([ - g.query.prometheus.new( - '${datasource}', - query - ) - + g.query.prometheus.withLegendFormat('{{ code }}'), - ]); - -local myerrorpanel(title, description, query) = - timeSeries.new(title) - + timeSeries.panelOptions.withDescription(description) - + timeSeries.panelOptions.withGridPos(w=6) - + timeSeries.standardOptions.withUnit('percentunit') - + timeSeries.standardOptions.withMin(0) - + timeSeries.queryOptions.withTargets([ - g.query.prometheus.new( - '${datasource}', - query - ) - + g.query.prometheus.withLegendFormat('{{ resource }}'), - ]); - -local mydurationpanel(title, description, query) = - timeSeries.new(title) - + timeSeries.panelOptions.withDescription(description) - + timeSeries.panelOptions.withGridPos(w=6) - + timeSeries.standardOptions.withUnit('s') - + timeSeries.queryOptions.withTargets([ - g.query.prometheus.new( - '${datasource}', - query - ) - + g.query.prometheus.withLegendFormat('{{ resource }}'), - ]); - +local ts = g.panel.timeSeries; +local override = ts.standardOptions.override; { _config+:: { kubeApiserverSelector: 'job="kube-apiserver"', }, + local timeSeries = + g.panel.timeSeries { + new(title): + ts.new(title) + + ts.options.legend.withShowLegend() + + ts.options.legend.withAsTable() + + ts.options.legend.withPlacement('right') + + ts.options.tooltip.withMode('single') + + ts.queryOptions.withInterval($._config.grafanaK8s.minimumTimeInterval), + }, + + local mystatpanel(title, description, query) = + stat.new(title) + + stat.panelOptions.withDescription(description) + + stat.panelOptions.withGridPos(w=6) + + stat.standardOptions.withUnit('percentunit') + + stat.standardOptions.withDecimals(3) + + stat.queryOptions.withInterval($._config.grafanaK8s.minimumTimeInterval) + + stat.queryOptions.withTargets([ + g.query.prometheus.new( + '${datasource}', + query, + ), + ]), + + local myrequestspanel(title, description, query) = + timeSeries.new(title) + + timeSeries.panelOptions.withDescription(description) + + timeSeries.panelOptions.withGridPos(w=6) + + timeSeries.standardOptions.withUnit('reqps') + + timeSeries.fieldConfig.defaults.custom.withFillOpacity(100) + + timeSeries.fieldConfig.defaults.custom.stacking.withMode('normal') + + timeSeries.standardOptions.withOverrides([ + override.byRegexp.new('/2../i') + override.byRegexp.withProperty('color', '#56A64B'), + override.byRegexp.new('/3../i') + override.byRegexp.withProperty('color', '#F2CC0C'), + override.byRegexp.new('/4../i') + override.byRegexp.withProperty('color', '#3274D9'), + override.byRegexp.new('/5../i') + override.byRegexp.withProperty('color', '#E02F44'), + ]) + + timeSeries.queryOptions.withTargets([ + g.query.prometheus.new( + '${datasource}', + query + ) + + g.query.prometheus.withLegendFormat('{{ code }}'), + ]), + + local myerrorpanel(title, description, query) = + timeSeries.new(title) + + timeSeries.panelOptions.withDescription(description) + + timeSeries.panelOptions.withGridPos(w=6) + + timeSeries.standardOptions.withUnit('percentunit') + + timeSeries.standardOptions.withMin(0) + + timeSeries.queryOptions.withTargets([ + g.query.prometheus.new( + '${datasource}', + query + ) + + g.query.prometheus.withLegendFormat('{{ resource }}'), + ]), + + local mydurationpanel(title, description, query) = + timeSeries.new(title) + + timeSeries.panelOptions.withDescription(description) + + timeSeries.panelOptions.withGridPos(w=6) + + timeSeries.standardOptions.withUnit('s') + + timeSeries.queryOptions.withTargets([ + g.query.prometheus.new( + '${datasource}', + query + ) + + g.query.prometheus.withLegendFormat('{{ resource }}'), + ]), + grafanaDashboards+:: { 'apiserver.json': local panels = { @@ -303,10 +308,9 @@ local mydurationpanel(title, description, query) = }; g.dashboard.new('%(dashboardNamePrefix)sAPI server' % $._config.grafanaK8s) - + withGrafonnetLibDefaults(includeObsoleteFields=true) + + g.dashboard.withEditable(false) + g.dashboard.time.withFrom('now-1h') - + g.dashboard.withUid($._config.grafanaDashboardIDs['apiserver.json']) - + g.dashboard.withTags($._config.grafanaK8s.dashboardTags) + + g.dashboard.time.withTo('now') + g.dashboard.withVariables([ variables.datasource, variables.cluster, diff --git a/dashboards/defaults.libsonnet b/dashboards/defaults.libsonnet index f2322381d..38d2c4a3b 100644 --- a/dashboards/defaults.libsonnet +++ b/dashboards/defaults.libsonnet @@ -11,7 +11,7 @@ refresh: kubernetesMixin._config.grafanaK8s.refresh, tags: kubernetesMixin._config.grafanaK8s.dashboardTags, - rows: [ + [if 'rows' in super then 'rows']: [ row { panels: [ panel {