Skip to content

Commit 113074c

Browse files
authored
Merge pull request #4949 from consideRatio/pr/repeating-panel
AWS cost attribution: iterate on the .jsonnet version of the dashboard
2 parents 3dc4f75 + 6832b90 commit 113074c

File tree

2 files changed

+96
-21
lines changed

2 files changed

+96
-21
lines changed

grafana-dashboards/common.libsonnet

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
local grafonnet = import 'grafonnet/main.libsonnet';
2+
local var = grafonnet.dashboard.variable;
3+
4+
{
5+
// grafonnet ref: https://grafana.github.io/grafonnet/API/dashboard/variable.html
6+
variables: {
7+
infinity_datasource:
8+
var.datasource.new('infinity_datasource', 'yesoreyeram-infinity-datasource')
9+
+ var.datasource.generalOptions.showOnDashboard.withNothing()
10+
,
11+
hub:
12+
var.query.new(
13+
'hub',
14+
{
15+
query: "",
16+
queryType: "infinity",
17+
infinityQuery: {
18+
format: "table",
19+
parser: "backend",
20+
refId: "variable",
21+
source: "url",
22+
type: "json",
23+
url: "http://aws-ce-grafana-backend.support.svc.cluster.local/hub-names?from=${__from:date}&to=${__to:date}",
24+
url_options: {
25+
data: "",
26+
method: "GET"
27+
}
28+
},
29+
}
30+
)
31+
+ var.query.withDatasourceFromVariable(self.infinity_datasource)
32+
+ var.query.selectionOptions.withIncludeAll(value=true)
33+
+ var.query.generalOptions.showOnDashboard.withNothing()
34+
+ var.query.refresh.onTime()
35+
,
36+
},
37+
}

grafana-dashboards/cost-attribution.jsonnet

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/usr/bin/env -S jsonnet -J ../vendor
2-
local grafonnet = import 'github.com/grafana/grafonnet/gen/grafonnet-v10.4.0/main.libsonnet';
2+
local grafonnet = import 'grafonnet/main.libsonnet';
33
local dashboard = grafonnet.dashboard;
44
local ts = grafonnet.panel.timeSeries;
55
local var = grafonnet.dashboard.variable;
66

7+
local common = import './common.libsonnet';
8+
9+
710
local totalDailyCosts =
811
ts.new('Total daily costs')
912
+ ts.panelOptions.withDescription(
@@ -30,17 +33,28 @@ local totalDailyCosts =
3033
+ ts.standardOptions.withUnit('currencyUSD')
3134
+ ts.queryOptions.withTargets([
3235
{
33-
datasource: { type: 'yesoreyeram-infinity-datasource', uid: 'fdsrfvebctptsf' },
36+
datasource: {
37+
type: 'yesoreyeram-infinity-datasource',
38+
uid: '${infinity_datasource}',
39+
},
3440
url: "http://aws-ce-grafana-backend.support.svc.cluster.local/total-costs?from=${__from:date}&to=${__to:date}",
3541
format: "table",
3642
refId: "A",
3743
columns: [
3844
{selector: "cost", text: "Cost", type: "number", unit: "currencyUSD"},
3945
{selector: "date", text: "Date", type: "timestamp"}
40-
]
46+
],
47+
parser: "backend",
48+
type: "json",
49+
source: "url",
50+
url_options: {
51+
"method": "GET",
52+
"data": "",
53+
},
4154
}
4255
]);
4356

57+
4458
local totalDailyCostsPerHub =
4559
ts.new('Total daily costs per hub')
4660
+ ts.panelOptions.withDescription(
@@ -75,7 +89,10 @@ local totalDailyCostsPerHub =
7589
+ ts.standardOptions.withUnit('currencyUSD')
7690
+ ts.queryOptions.withTargets([
7791
{
78-
datasource: { type: 'yesoreyeram-infinity-datasource', uid: 'fdsrfvebctptsf' },
92+
datasource: {
93+
type: 'yesoreyeram-infinity-datasource',
94+
uid: '${infinity_datasource}',
95+
},
7996
url: "http://aws-ce-grafana-backend.support.svc.cluster.local/total-costs-per-hub?from=${__from:date}&to=${__to:date}",
8097
format: "timeseries",
8198
refId: "A",
@@ -84,20 +101,16 @@ local totalDailyCostsPerHub =
84101
{selector: "name", text: "Name", type: "string"},
85102
{selector: "cost", text: "Cost", type: "number"}
86103
],
104+
parser: "backend",
105+
type: "json",
106+
source: "url",
107+
url_options: {
108+
"method": "GET",
109+
"data": "",
110+
},
87111
}
88112
]);
89113

90-
local hubQueryVar =
91-
var.query.new('hub')
92-
+ var.query.queryTypes.withLabelValues(
93-
'Hub',
94-
)
95-
+ var.query.withDatasource(
96-
type= 'yesoreyeram-infinity-datasource', uid='fdsrfvebctptsf'
97-
98-
)
99-
+ var.query.selectionOptions.withIncludeAll();
100-
101114

102115
local totalDailyCostsPerComponent =
103116
ts.new('Total daily costs per component')
@@ -133,7 +146,10 @@ local totalDailyCostsPerComponent =
133146
+ ts.standardOptions.withUnit('currencyUSD')
134147
+ ts.queryOptions.withTargets([
135148
{
136-
datasource: { type: 'yesoreyeram-infinity-datasource', uid: 'fdsrfvebctptsf' },
149+
datasource: {
150+
type: 'yesoreyeram-infinity-datasource',
151+
uid: '${infinity_datasource}',
152+
},
137153
url: "http://aws-ce-grafana-backend.support.svc.cluster.local/total-costs-per-component?from=${__from:date}&to=${__to:date}",
138154
format: "timeseries",
139155
refId: "A",
@@ -142,17 +158,26 @@ local totalDailyCostsPerComponent =
142158
{selector: "name", text: "Name", type: "string"},
143159
{selector: "cost", text: "Cost", type: "number"}
144160
],
161+
parser: "backend",
162+
type: "json",
163+
source: "url",
164+
url_options: {
165+
"method": "GET",
166+
"data": "",
167+
},
145168
}
146169
]);
147170

148171

149-
local totalDailyCostsPerComponentandHub =
172+
local totalDailyCostsPerComponentAndHub =
150173
ts.new('Total daily costs per component, for ${hub}')
151174
+ ts.panelOptions.withDescription(
152175
|||
153176
Total daily costs per component, for ${hub}
154177
|||
155178
)
179+
+ ts.panelOptions.withRepeat('hub')
180+
+ ts.panelOptions.withMaxPerRow(2)
156181
+ ts.options.withTooltip({ mode: 'single', sort: "none" })
157182
+ ts.options.withLegend({
158183
"calcs": [
@@ -180,7 +205,10 @@ local totalDailyCostsPerComponentandHub =
180205
+ ts.standardOptions.withUnit('currencyUSD')
181206
+ ts.queryOptions.withTargets([
182207
{
183-
datasource: { type: 'yesoreyeram-infinity-datasource', uid: 'fdsrfvebctptsf' },
208+
datasource: {
209+
type: 'yesoreyeram-infinity-datasource',
210+
uid: '${infinity_datasource}',
211+
},
184212
url: "http://aws-ce-grafana-backend.support.svc.cluster.local/total-costs-per-component?from=${__from:date}&to=${__to:date}&hub=${hub}",
185213
format: "timeseries",
186214
refId: "A",
@@ -189,22 +217,32 @@ local totalDailyCostsPerComponentandHub =
189217
{selector: "name", text: "Name", type: "string"},
190218
{selector: "cost", text: "Cost", type: "number"}
191219
],
220+
parser: "backend",
221+
type: "json",
222+
source: "url",
223+
url_options: {
224+
"method": "GET",
225+
"data": "",
226+
},
192227
}
193228
]);
194229

195230

196231
dashboard.new('Cloud cost attribution')
197-
+ dashboard.withUid('edw06h7udjwg0b')
232+
+ dashboard.withUid('cloud-cost-attribution')
198233
+ dashboard.withEditable(true)
199234
+ dashboard.time.withFrom('now-30d')
200-
+ dashboard.withVariables(hubQueryVar)
235+
+ dashboard.withVariables([
236+
common.variables.hub,
237+
common.variables.infinity_datasource,
238+
])
201239
+ dashboard.withPanels(
202240
grafonnet.util.grid.makeGrid(
203241
[
204242
totalDailyCosts,
205243
totalDailyCostsPerHub,
206244
totalDailyCostsPerComponent,
207-
totalDailyCostsPerComponentandHub
245+
totalDailyCostsPerComponentAndHub
208246
],
209247
panelWidth=24,
210248
panelHeight=12,

0 commit comments

Comments
 (0)