Skip to content

Commit

Permalink
fix: set some defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Duologic committed Feb 16, 2024
1 parent fc8f523 commit 058e91e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 74 deletions.
150 changes: 77 additions & 73 deletions dashboards/apiserver.libsonnet
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion dashboards/defaults.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
refresh: kubernetesMixin._config.grafanaK8s.refresh,
tags: kubernetesMixin._config.grafanaK8s.dashboardTags,

rows: [
[if 'rows' in super then 'rows']: [
row {
panels: [
panel {
Expand Down

0 comments on commit 058e91e

Please sign in to comment.