Skip to content

Commit

Permalink
Update add_asserts_variables (remove statusPanelsDashboardsMetrics) (g…
Browse files Browse the repository at this point in the history
  • Loading branch information
v-zhuravlev authored Jul 12, 2024
1 parent 49029fc commit 0e5092c
Showing 1 changed file with 77 additions and 70 deletions.
147 changes: 77 additions & 70 deletions grafana-cloud-integration-utils/util.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -210,76 +210,83 @@ local integration_version_panel(version, statusPanelDataSource, height, width, x

// Adds asserts specific variables to the dashboards
add_asserts_variables(dashboard, config, hidden=true)::
if std.member(config.statusPanelsDashboardsMetrics, dashboard.title) then
dashboard
{
templating: {
list: [
var.query.new('env')
+ var.query.withDatasource('prometheus', config.statusPanelsDatasourceNameMetrics)
+ var.query.queryTypes.withLabelValues(
'asserts_env',
'asserts:mixin_workload_job',
)
+ var.query.generalOptions.withLabel('Asserts environment')
+ (
if hidden then var.query.generalOptions.showOnDashboard.withNothing() else var.query.generalOptions.showOnDashboard.withLabelAndValue()
)
+ var.query.selectionOptions.withIncludeAll(
value=true,
customAllValue='.*'
)
+ var.query.selectionOptions.withMulti(
false
)
+ var.query.refresh.onTime()
+ var.query.withSort(
i=1,
type='alphabetical',
asc=true,
caseInsensitive=false
),
var.query.new('site')
+ var.query.withDatasource('prometheus', config.statusPanelsDatasourceNameMetrics)
+ var.query.queryTypes.withLabelValues(
'asserts_site',
'asserts:mixin_workload_job{asserts_env=~"$env"}',
)
+ var.query.generalOptions.withLabel('Asserts site')
+ (
if hidden then var.query.generalOptions.showOnDashboard.withNothing() else var.query.generalOptions.showOnDashboard.withLabelAndValue()
)
+ var.query.selectionOptions.withIncludeAll(
value=true,
customAllValue='.*'
)
+ var.query.selectionOptions.withMulti(
false
)
+ var.query.refresh.onTime()
+ var.query.withSort(
i=1,
type='alphabetical',
asc=true,
caseInsensitive=false
),
] + dashboard.templating.list,
},
panels: [
if std.objectHas(panel, 'targets') then
panel {
targets: [
if std.objectHas(target, 'expr') then
target {
expr: std.strReplace(target.expr, '{', '{asserts_env=~"$env", asserts_site=~"$site", '),
}
else target
for target in panel.targets
],
} else panel
for panel in dashboard.panels
],
} else dashboard,
local ds_name =
std.prune([
if std.objectHas(template, 'type') && template.type == 'datasource' && template.query == 'prometheus'
then
std.get(template, 'name')
else null
for template in dashboard.templating.list
])[0];
dashboard
{
templating: {
list: [
var.query.new('env')
+ var.query.withDatasource('prometheus', '${%s}' % ds_name)
+ var.query.queryTypes.withLabelValues(
'asserts_env',
'asserts:mixin_workload_job',
)
+ var.query.generalOptions.withLabel('Asserts environment')
+ (
if hidden then var.query.generalOptions.showOnDashboard.withNothing() else var.query.generalOptions.showOnDashboard.withLabelAndValue()
)
+ var.query.selectionOptions.withIncludeAll(
value=true,
customAllValue='.*'
)
+ var.query.selectionOptions.withMulti(
false
)
+ var.query.refresh.onTime()
+ var.query.withSort(
i=1,
type='alphabetical',
asc=true,
caseInsensitive=false
),
var.query.new('site')
+ var.query.withDatasource('prometheus', '${%s}' % ds_name)
+ var.query.queryTypes.withLabelValues(
'asserts_site',
'asserts:mixin_workload_job{asserts_env=~"$env"}',
)
+ var.query.generalOptions.withLabel('Asserts site')
+ (
if hidden then var.query.generalOptions.showOnDashboard.withNothing() else var.query.generalOptions.showOnDashboard.withLabelAndValue()
)
+ var.query.selectionOptions.withIncludeAll(
value=true,
customAllValue='.*'
)
+ var.query.selectionOptions.withMulti(
false
)
+ var.query.refresh.onTime()
+ var.query.withSort(
i=1,
type='alphabetical',
asc=true,
caseInsensitive=false
),
] + dashboard.templating.list,
},
panels: [
if std.objectHas(panel, 'targets') then
panel {
targets: [
if std.objectHas(target, 'expr') then
target {
expr: std.strReplace(target.expr, '{', '{asserts_env=~"$env", asserts_site=~"$site", '),
}
else target
for target in panel.targets
],
} else panel
for panel in dashboard.panels
],
},

prepare_dashboards(dashboards, tags, folderName, ignoreDashboards=[], refresh='30s', timeFrom='now-30m'):: {
[k]: {
Expand Down

0 comments on commit 0e5092c

Please sign in to comment.