Skip to content

Commit

Permalink
Add helper function for adding asserts specific variables (#1274)
Browse files Browse the repository at this point in the history
* initial commit; start adding util to add variables to promql

* Add asserts_env and asserts_site labels from util

* Set variables to update on time range

* Only add asserts variables to metrics dashboards

* Take datasource from config

* Check existence of target in panels - to handle row cases

* Add hidden option

* Set hidden by default true for asserts variables
  • Loading branch information
mshahzeb authored Jul 8, 2024
1 parent 68b6e9d commit 167b75f
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions grafana-cloud-integration-utils/util.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local g = import 'grafonnet-latest/main.libsonnet';
local grafana = (import 'grafonnet/grafana.libsonnet');
local statusPanels = import 'status-panels-lib/status-panels/main.libsonnet';
local xtd = import 'xtd/main.libsonnet';
local var = g.dashboard.variable;

local debug(obj) =
std.trace(std.toString(obj), obj);
Expand Down Expand Up @@ -207,6 +208,79 @@ 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,

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

0 comments on commit 167b75f

Please sign in to comment.