Skip to content

Commit

Permalink
Merge pull request #4949 from consideRatio/pr/repeating-panel
Browse files Browse the repository at this point in the history
AWS cost attribution: iterate on the .jsonnet version of the dashboard
  • Loading branch information
consideRatio authored Oct 4, 2024
2 parents 3dc4f75 + 6832b90 commit 113074c
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 21 deletions.
37 changes: 37 additions & 0 deletions grafana-dashboards/common.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local grafonnet = import 'grafonnet/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: {
format: "table",
parser: "backend",
refId: "variable",
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.selectionOptions.withIncludeAll(value=true)
+ var.query.generalOptions.showOnDashboard.withNothing()
+ var.query.refresh.onTime()
,
},
}
80 changes: 59 additions & 21 deletions grafana-dashboards/cost-attribution.jsonnet
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env -S jsonnet -J ../vendor
local grafonnet = import 'github.com/grafana/grafonnet/gen/grafonnet-v10.4.0/main.libsonnet';
local grafonnet = import 'grafonnet/main.libsonnet';
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,17 +33,28 @@ 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",
columns: [
{selector: "cost", text: "Cost", type: "number", unit: "currencyUSD"},
{selector: "date", text: "Date", type: "timestamp"}
]
],
parser: "backend",
type: "json",
source: "url",
url_options: {
"method": "GET",
"data": "",
},
}
]);


local totalDailyCostsPerHub =
ts.new('Total daily costs per hub')
+ ts.panelOptions.withDescription(
Expand Down Expand Up @@ -75,7 +89,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 @@ -84,20 +101,16 @@ local totalDailyCostsPerHub =
{selector: "name", text: "Name", type: "string"},
{selector: "cost", text: "Cost", type: "number"}
],
parser: "backend",
type: "json",
source: "url",
url_options: {
"method": "GET",
"data": "",
},
}
]);

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 @@ -133,7 +146,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 All @@ -142,17 +158,26 @@ local totalDailyCostsPerComponent =
{selector: "name", text: "Name", type: "string"},
{selector: "cost", text: "Cost", type: "number"}
],
parser: "backend",
type: "json",
source: "url",
url_options: {
"method": "GET",
"data": "",
},
}
]);


local totalDailyCostsPerComponentandHub =
local totalDailyCostsPerComponentAndHub =
ts.new('Total daily costs per component, for ${hub}')
+ ts.panelOptions.withDescription(
|||
Total daily costs per component, for ${hub}
|||
)
+ ts.panelOptions.withRepeat('hub')
+ ts.panelOptions.withMaxPerRow(2)
+ ts.options.withTooltip({ mode: 'single', sort: "none" })
+ ts.options.withLegend({
"calcs": [
Expand Down Expand Up @@ -180,7 +205,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 @@ -189,22 +217,32 @@ local totalDailyCostsPerComponentandHub =
{selector: "name", text: "Name", type: "string"},
{selector: "cost", text: "Cost", type: "number"}
],
parser: "backend",
type: "json",
source: "url",
url_options: {
"method": "GET",
"data": "",
},
}
]);


dashboard.new('Cloud cost attribution')
+ dashboard.withUid('edw06h7udjwg0b')
+ 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(
[
totalDailyCosts,
totalDailyCostsPerHub,
totalDailyCostsPerComponent,
totalDailyCostsPerComponentandHub
totalDailyCostsPerComponentAndHub
],
panelWidth=24,
panelHeight=12,
Expand Down

0 comments on commit 113074c

Please sign in to comment.