From 8ee6a748eeef025c9380add3de274323cbbe8920 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Fri, 4 Oct 2024 22:19:00 +0200 Subject: [PATCH] cloud cost dashboard: reference datasource variable --- grafana-dashboards/common.jsonnet | 17 --------- grafana-dashboards/common.libsonnet | 39 ++++++++++++++++++++ grafana-dashboards/cost-attribution.jsonnet | 41 ++++++++++++--------- 3 files changed, 63 insertions(+), 34 deletions(-) delete mode 100644 grafana-dashboards/common.jsonnet create mode 100644 grafana-dashboards/common.libsonnet diff --git a/grafana-dashboards/common.jsonnet b/grafana-dashboards/common.jsonnet deleted file mode 100644 index 18f6d1431..000000000 --- a/grafana-dashboards/common.jsonnet +++ /dev/null @@ -1,17 +0,0 @@ -local grafonnet = import 'github.com/grafana/grafonnet/gen/grafonnet-v11.1.0/main.libsonnet'; -local var = grafonnet.dashboard.variable; - -{ - // grafonnet ref: https://grafana.github.io/grafonnet/API/dashboard/variable.html - variables: { - datasource: - var.datasource.new('datasource', 'yesoreyeram-infinity-datasource') - + var.datasource.generalOptions.showOnDashboard.withNothing() - , - newhub: - var.query.new('hub') - + var.query.withDatasourceFromVariable(self.datasource) - + var.query.selectionOptions.withIncludeAll(value=true) - , - }, -} diff --git a/grafana-dashboards/common.libsonnet b/grafana-dashboards/common.libsonnet new file mode 100644 index 000000000..430dbd7c0 --- /dev/null +++ b/grafana-dashboards/common.libsonnet @@ -0,0 +1,39 @@ +local grafonnet = import 'github.com/grafana/grafonnet/gen/grafonnet-v11.1.0/main.libsonnet'; +local var = grafonnet.dashboard.variable; + +{ + // grafonnet ref: https://grafana.github.io/grafonnet/API/dashboard/variable.html + variables: { + infinity_datasource: + var.datasource.new('infinity_datasource', 'yesoreyeram-infinity-datasource') + + var.datasource.generalOptions.showOnDashboard.withNothing() + , + hub: + var.query.new( + 'hub', + { + query: "", + queryType: "infinity", + infinityQuery: { + columns: [], + filters: [], + format: "table", + parser: "backend", + refId: "variable", + root_selector: "", + source: "url", + type: "json", + url: "http://aws-ce-grafana-backend.support.svc.cluster.local/hub-names?from=${__from:date}&to=${__to:date}", + url_options: { + data: "", + method: "GET" + } + }, + } + ) + + var.query.withDatasourceFromVariable(self.infinity_datasource) + + var.query.generalOptions.showOnDashboard.withNothing() + + var.query.selectionOptions.withIncludeAll(value=true) + , + }, +} diff --git a/grafana-dashboards/cost-attribution.jsonnet b/grafana-dashboards/cost-attribution.jsonnet index a0d6d2e91..dc63d43c2 100644 --- a/grafana-dashboards/cost-attribution.jsonnet +++ b/grafana-dashboards/cost-attribution.jsonnet @@ -4,6 +4,9 @@ local dashboard = grafonnet.dashboard; local ts = grafonnet.panel.timeSeries; local var = grafonnet.dashboard.variable; +local common = import './common.libsonnet'; + + local totalDailyCosts = ts.new('Total daily costs') + ts.panelOptions.withDescription( @@ -30,7 +33,10 @@ local totalDailyCosts = + ts.standardOptions.withUnit('currencyUSD') + ts.queryOptions.withTargets([ { - datasource: { type: 'yesoreyeram-infinity-datasource', uid: 'fdsrfvebctptsf' }, + datasource: { + type: 'yesoreyeram-infinity-datasource', + uid: '${infinity_datasource}', + }, url: "http://aws-ce-grafana-backend.support.svc.cluster.local/total-costs?from=${__from:date}&to=${__to:date}", format: "table", refId: "A", @@ -41,6 +47,7 @@ local totalDailyCosts = } ]); + local totalDailyCostsPerHub = ts.new('Total daily costs per hub') + ts.panelOptions.withDescription( @@ -75,7 +82,10 @@ local totalDailyCostsPerHub = + ts.standardOptions.withUnit('currencyUSD') + ts.queryOptions.withTargets([ { - datasource: { type: 'yesoreyeram-infinity-datasource', uid: 'fdsrfvebctptsf' }, + datasource: { + type: 'yesoreyeram-infinity-datasource', + uid: '${infinity_datasource}', + }, url: "http://aws-ce-grafana-backend.support.svc.cluster.local/total-costs-per-hub?from=${__from:date}&to=${__to:date}", format: "timeseries", refId: "A", @@ -87,18 +97,6 @@ local totalDailyCostsPerHub = } ]); -local hubQueryVar = - - var.query.new('hub') - + var.query.queryTypes.withLabelValues( - 'Hub', - ) - + var.query.withDatasource( - type= 'yesoreyeram-infinity-datasource', - uid='fdsrfvebctptsf', - ) - + var.query.selectionOptions.withIncludeAll(); - local totalDailyCostsPerComponent = ts.new('Total daily costs per component') @@ -134,7 +132,10 @@ local totalDailyCostsPerComponent = + ts.standardOptions.withUnit('currencyUSD') + ts.queryOptions.withTargets([ { - datasource: { type: 'yesoreyeram-infinity-datasource', uid: 'fdsrfvebctptsf' }, + datasource: { + type: 'yesoreyeram-infinity-datasource', + uid: '${infinity_datasource}', + }, url: "http://aws-ce-grafana-backend.support.svc.cluster.local/total-costs-per-component?from=${__from:date}&to=${__to:date}", format: "timeseries", refId: "A", @@ -181,7 +182,10 @@ local totalDailyCostsPerComponentAndHub = + ts.standardOptions.withUnit('currencyUSD') + ts.queryOptions.withTargets([ { - datasource: { type: 'yesoreyeram-infinity-datasource', uid: 'fdsrfvebctptsf' }, + datasource: { + type: 'yesoreyeram-infinity-datasource', + uid: '${infinity_datasource}', + }, url: "http://aws-ce-grafana-backend.support.svc.cluster.local/total-costs-per-component?from=${__from:date}&to=${__to:date}&hub=${hub}", format: "timeseries", refId: "A", @@ -198,7 +202,10 @@ dashboard.new('Cloud cost attribution') + dashboard.withUid('cloud-cost-attribution') + dashboard.withEditable(true) + dashboard.time.withFrom('now-30d') -+ dashboard.withVariables(hubQueryVar) ++ dashboard.withVariables([ + common.variables.hub, + common.variables.infinity_datasource, + ]) + dashboard.withPanels( grafonnet.util.grid.makeGrid( [