Skip to content

Commit

Permalink
cloud cost dashboard: reference datasource variable
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Oct 4, 2024
1 parent 14d14d9 commit 8ee6a74
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 34 deletions.
17 changes: 0 additions & 17 deletions grafana-dashboards/common.jsonnet

This file was deleted.

39 changes: 39 additions & 0 deletions grafana-dashboards/common.libsonnet
Original file line number Diff line number Diff line change
@@ -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)
,
},
}
41 changes: 24 additions & 17 deletions grafana-dashboards/cost-attribution.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand All @@ -41,6 +47,7 @@ local totalDailyCosts =
}
]);


local totalDailyCostsPerHub =
ts.new('Total daily costs per hub')
+ ts.panelOptions.withDescription(
Expand Down Expand Up @@ -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",
Expand All @@ -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')
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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(
[
Expand Down

0 comments on commit 8ee6a74

Please sign in to comment.