Skip to content

Commit

Permalink
migrate: add back unused functionality in libsonnet
Browse files Browse the repository at this point in the history
I think we could manage to get prometheus server cpu/metrics etc
presented with the same helper functions if we retain these things.
  • Loading branch information
consideRatio committed Apr 12, 2024
1 parent ddcb0e5 commit 9bcc61b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
7 changes: 2 additions & 5 deletions dashboards/jupyterhub.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ local jupyterhub = import 'jupyterhub.libsonnet';
local currentActiveUsers =
common.tsOptions
+ ts.new('Currently Active Users')
+ ts.panelOptions.withDescription(
|||
TODO
|||
)
+ ts.standardOptions.withDecimals(0)
+ ts.fieldConfig.defaults.custom.stacking.withMode('normal')
+ ts.queryOptions.withTargets([
Expand Down Expand Up @@ -278,10 +273,12 @@ local hubResponseCodes =
local allComponentsMemory = jupyterhub.memoryPanel(
'All JupyterHub Components',
component='singleuser-server',
multi=true,
);
local allComponentsCPU = jupyterhub.cpuPanel(
'All JupyterHub Components',
component='singleuser-server',
multi=true,
);

local hubDBUsage =
Expand Down
28 changes: 22 additions & 6 deletions dashboards/jupyterhub.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ local prometheus = grafonnet.query.prometheus;
* @param title The title of the timeseries panel.
* @param metric The metric to be observed.
* @param component The component to be measured (or excluded).
* Optional if `multi=true`, in which case it is an exclusion, otherwise required.
* @param multi (default `false`) If true, do a multi-component chart instead of single-component.
* The chart will have a legend table for each component.
*/
componentResourcePanel(title, metric, component)::
componentResourcePanel(title, metric, component, multi, namespace)::
ts.new(title)
// show legend as a table with current, avg, max values
//legend_hideZero=true,
// legend_values is required for any of the above to work
//legend_values=true,
//min=0,
+ ts.options.legend.withDisplayMode('table')
+ ts.options.legend.withCalcs(['min', 'mean', 'max'])
+ ts.queryOptions.withTargets([
Expand All @@ -94,11 +96,15 @@ local prometheus = grafonnet.query.prometheus;
|||,
[
metric,
self.onComponentLabel(component, cmp='!=', group_left='container, label_component'),
self.onComponentLabel(
component,
cmp=if multi then '!=' else '=', group_left='container, label_component',
namespace=namespace,
),
],
)
)
+ prometheus.withLegendFormat('{{ label_component }}'),
+ prometheus.withLegendFormat(if multi then '{{ label_component }}' else title),
]),

/**
Expand All @@ -108,11 +114,16 @@ local prometheus = grafonnet.query.prometheus;
*
* @param name The name of the resource. Used to create the title.
* @param component The component to be measured (or excluded).
* Optional if `multi=true`, in which case it is an exclusion, otherwise required.
* @param multi (default `false`) If true, do a multi-component chart instead of single-component.
* The chart will have a legend table for each component.
*/
memoryPanel(name, component)::
memoryPanel(name, component, multi=false, namespace='$hub')::
self.componentResourcePanel(
std.format('%s Memory (Working Set)', [name]),
component=component,
multi=multi,
namespace=namespace,
metric=|||
# exclude name="" because the same container can be reported
# with both no name and `name=k8s_...`,
Expand All @@ -130,11 +141,16 @@ local prometheus = grafonnet.query.prometheus;
*
* @param name The name of the resource. Used to create the title.
* @param component The component to be measured (or excluded).
* Optional if `multi=true`, in which case it is an exclusion, otherwise required.
* @param multi (default `false`) If true, do a multi-component chart instead of single-component.
* The chart will have a legend table for each component.
*/
cpuPanel(name, component)::
cpuPanel(name, component, multi=false, namespace='$hub')::
self.componentResourcePanel(
std.format('%s CPU', [name]),
component=component,
multi=multi,
namespace=namespace,
metric=|||
# exclude name="" because the same container can be reported
# with both no name and `name=k8s_...`,
Expand Down
15 changes: 15 additions & 0 deletions dashboards/support.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ local nfsServerReadLatency =
]);

// Support Metrics

// FIXME: Can we transition to using the function to generate the prometheus memory and cpu panels?
//
// Currently held back by hardcoded label selection on the label
// "component" and selection on a single label instead of optionally
// multiple.
//
//local prometheusMemory = jupyterhub.memoryPanel(
// 'Prometheus Memory (Working Set)',
// // app.kubernetes.io/component: server
// // app.kubernetes.io/name: prometheus
// component='singleuser-server',
// multi=false,
//);

local prometheusMemory =
common.tsOptions
+ ts.new('Prometheus Memory (Working Set)')
Expand Down

0 comments on commit 9bcc61b

Please sign in to comment.