From 0e5092ced0d8290844e3caff21747f86e4f6cf96 Mon Sep 17 00:00:00 2001 From: v-zhuravlev Date: Fri, 12 Jul 2024 14:29:32 +0800 Subject: [PATCH] Update add_asserts_variables (remove statusPanelsDashboardsMetrics) (#1277) --- .../util.libsonnet | 147 +++++++++--------- 1 file changed, 77 insertions(+), 70 deletions(-) diff --git a/grafana-cloud-integration-utils/util.libsonnet b/grafana-cloud-integration-utils/util.libsonnet index 470be89d3..f0a86b5db 100644 --- a/grafana-cloud-integration-utils/util.libsonnet +++ b/grafana-cloud-integration-utils/util.libsonnet @@ -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]: {