examples,jsonnet: expose kubernetes-grafana API to fix grafana examples

Signed-off-by: paulfantom <pawel@krupa.net.pl>
This commit is contained in:
paulfantom
2021-02-02 10:00:08 +01:00
parent 8588e30bd0
commit ab3dff2016
4 changed files with 52 additions and 42 deletions

View File

@@ -6,34 +6,36 @@ local template = grafana.template;
local graphPanel = grafana.graphPanel; local graphPanel = grafana.graphPanel;
local kp = (import 'kube-prometheus/main.libsonnet') + { local kp = (import 'kube-prometheus/main.libsonnet') + {
_config+:: { values+:: {
namespace: 'monitoring', common+:: {
}, namespace: 'monitoring',
grafana+:: { },
dashboards+:: { grafana+: {
'my-dashboard.json': dashboards+:: {
dashboard.new('My Dashboard') 'my-dashboard.json':
.addTemplate( dashboard.new('My Dashboard')
{ .addTemplate(
current: { {
text: 'Prometheus', current: {
value: 'Prometheus', text: 'Prometheus',
value: 'Prometheus',
},
hide: 0,
label: null,
name: 'datasource',
options: [],
query: 'prometheus',
refresh: 1,
regex: '',
type: 'datasource',
}, },
hide: 0, )
label: null, .addRow(
name: 'datasource', row.new()
options: [], .addPanel(graphPanel.new('My Panel', span=6, datasource='$datasource')
query: 'prometheus', .addTarget(prometheus.target('vector(1)')))
refresh: 1, ),
regex: '', },
type: 'datasource',
},
)
.addRow(
row.new()
.addPanel(graphPanel.new('My Panel', span=6, datasource='$datasource')
.addTarget(prometheus.target('vector(1)')))
),
}, },
}, },
}; };

View File

@@ -1,10 +1,12 @@
local kp = (import 'kube-prometheus/main.libsonnet') + { local kp = (import 'kube-prometheus/main.libsonnet') + {
_config+:: { values+:: {
namespace: 'monitoring', common+:: {
}, namespace: 'monitoring',
grafana+:: { },
rawDashboards+:: { grafana+: {
'my-dashboard.json': (importstr 'example-grafana-dashboard.json'), rawDashboards+:: {
'my-dashboard.json': (importstr 'example-grafana-dashboard.json'),
},
}, },
}, },
}; };

View File

@@ -1,13 +1,12 @@
local kp = (import 'kube-prometheus/main.libsonnet') + { local kp = (import 'kube-prometheus/main.libsonnet') + {
_config+:: { values+:: {
namespace: 'monitoring', common+:: {
}, namespace: 'monitoring',
grafanaDashboards+:: { // monitoring-mixin compatibility },
'my-dashboard.json': (import 'example-grafana-dashboard.json'), grafana+: {
}, dashboards+:: { // use this method to import your dashboards to Grafana
grafana+:: { 'my-dashboard.json': (import 'example-grafana-dashboard.json'),
dashboards+:: { // use this method to import your dashboards to Grafana },
'my-dashboard.json': (import 'example-grafana-dashboard.json'),
}, },
}, },
}; };

View File

@@ -22,6 +22,10 @@ local defaults = {
}, },
prometheusName: error 'must provide prometheus name', prometheusName: error 'must provide prometheus name',
dashboards: {}, dashboards: {},
// TODO(paulfantom): expose those to have a stable API. After kubernetes-grafana refactor those could probably be removed.
rawDashboards: {},
folderDashboards: {},
containers: [],
}; };
function(params) { function(params) {
@@ -47,6 +51,9 @@ function(params) {
labels: g.config.commonLabels, labels: g.config.commonLabels,
dashboards: g.config.dashboards, dashboards: g.config.dashboards,
resources: g.config.resources, resources: g.config.resources,
rawDashboards: g.config.rawDashboards,
folderDashboards: g.config.folderDashboards,
containers: g.config.containers,
}, },
}, },
}, },