From ce2e6d520b48fe9c5c7593ae2400a6983905782e Mon Sep 17 00:00:00 2001 From: Quentin Bisson Date: Thu, 19 Sep 2024 11:40:55 +0200 Subject: [PATCH] feat: mixins / allow bloom dashboards disabling (#14177) This PR allows hiding the bloom dashboards if they are not used. --- production/loki-mixin/config.libsonnet | 5 + .../dashboards/loki-bloom-compactor.libsonnet | 115 +++++++++--------- .../dashboards/loki-bloom-gateway.libsonnet | 115 +++++++++--------- 3 files changed, 119 insertions(+), 116 deletions(-) diff --git a/production/loki-mixin/config.libsonnet b/production/loki-mixin/config.libsonnet index 501fe03b6baa..eeea227c8f06 100644 --- a/production/loki-mixin/config.libsonnet +++ b/production/loki-mixin/config.libsonnet @@ -15,6 +15,11 @@ // Enable dashboard and panels for Grafana Labs internal components. internal_components: false, + blooms: { + // Whether or not to include blooms specific dashboards + enabled: true, + }, + promtail: { // Whether or not to include promtail specific dashboards enabled: true, diff --git a/production/loki-mixin/dashboards/loki-bloom-compactor.libsonnet b/production/loki-mixin/dashboards/loki-bloom-compactor.libsonnet index 236ebff8666d..fc78becb2713 100644 --- a/production/loki-mixin/dashboards/loki-bloom-compactor.libsonnet +++ b/production/loki-mixin/dashboards/loki-bloom-compactor.libsonnet @@ -6,67 +6,66 @@ local raw = (import './dashboard-bloom-compactor.json'); // 2. Copy the JSON into `dashboard-bloom-compactor.json` // 3. Delete the `id` and `templating` fields from the JSON (import 'dashboard-utils.libsonnet') { - grafanaDashboards+: - { - 'loki-bloom-compactor.json': - raw - { - local replaceClusterMatchers(expr) = - // Replace the recording rules cluster label with the per-cluster label + grafanaDashboards+:: if !$._config.blooms.enabled then {} else { + 'loki-bloom-compactor.json': + raw + { + local replaceClusterMatchers(expr) = + // Replace the recording rules cluster label with the per-cluster label + std.strReplace( + // Replace the cluster label for equality matchers with the per-cluster label std.strReplace( - // Replace the cluster label for equality matchers with the per-cluster label + // Replace the cluster label for regex matchers with the per-cluster label std.strReplace( - // Replace the cluster label for regex matchers with the per-cluster label - std.strReplace( - expr, - 'cluster=~"$cluster"', - $._config.per_cluster_label + '=~"$cluster"' - ), - 'cluster="$cluster"', - $._config.per_cluster_label + '="$cluster"' + expr, + 'cluster=~"$cluster"', + $._config.per_cluster_label + '=~"$cluster"' ), - 'cluster_job', - $._config.per_cluster_label + '_job' + 'cluster="$cluster"', + $._config.per_cluster_label + '="$cluster"' ), + 'cluster_job', + $._config.per_cluster_label + '_job' + ), - panels: [ - p { - targets: if std.objectHas(p, 'targets') then [ - e { - expr: replaceClusterMatchers(e.expr), - } - for e in p.targets - ] else [], - panels: if std.objectHas(p, 'panels') then [ - sp { - targets: if std.objectHas(sp, 'targets') then [ - spe { - expr: replaceClusterMatchers(spe.expr), - } - for spe in sp.targets - ] else [], - panels: if std.objectHas(sp, 'panels') then [ - ssp { - targets: if std.objectHas(ssp, 'targets') then [ - sspe { - expr: replaceClusterMatchers(sspe.expr), - } - for sspe in ssp.targets - ] else [], - } - for ssp in sp.panels - ] else [], - } - for sp in p.panels - ] else [], - } - for p in super.panels - ], - } - + $.dashboard('Loki / Bloom Compactor', uid='bloom-compactor') - .addCluster() - .addNamespace() - .addLog() - .addTag(), - }, + panels: [ + p { + targets: if std.objectHas(p, 'targets') then [ + e { + expr: replaceClusterMatchers(e.expr), + } + for e in p.targets + ] else [], + panels: if std.objectHas(p, 'panels') then [ + sp { + targets: if std.objectHas(sp, 'targets') then [ + spe { + expr: replaceClusterMatchers(spe.expr), + } + for spe in sp.targets + ] else [], + panels: if std.objectHas(sp, 'panels') then [ + ssp { + targets: if std.objectHas(ssp, 'targets') then [ + sspe { + expr: replaceClusterMatchers(sspe.expr), + } + for sspe in ssp.targets + ] else [], + } + for ssp in sp.panels + ] else [], + } + for sp in p.panels + ] else [], + } + for p in super.panels + ], + } + + $.dashboard('Loki / Bloom Compactor', uid='bloom-compactor') + .addCluster() + .addNamespace() + .addLog() + .addTag(), + }, } diff --git a/production/loki-mixin/dashboards/loki-bloom-gateway.libsonnet b/production/loki-mixin/dashboards/loki-bloom-gateway.libsonnet index db9c90783911..40e1644ac029 100644 --- a/production/loki-mixin/dashboards/loki-bloom-gateway.libsonnet +++ b/production/loki-mixin/dashboards/loki-bloom-gateway.libsonnet @@ -6,67 +6,66 @@ local raw = (import './dashboard-bloom-gateway.json'); // 2. Copy the JSON into `dashboard-bloom-gateway.json` // 3. Delete the `id` and `templating` fields from the JSON (import 'dashboard-utils.libsonnet') { - grafanaDashboards+: - { - 'loki-bloom-gateway.json': - raw - { - local replaceClusterMatchers(expr) = - // Replace the recording rules cluster label with the per-cluster label + grafanaDashboards+:: if !$._config.blooms.enabled then {} else { + 'loki-bloom-gateway.json': + raw + { + local replaceClusterMatchers(expr) = + // Replace the recording rules cluster label with the per-cluster label + std.strReplace( + // Replace the cluster label for equality matchers with the per-cluster label std.strReplace( - // Replace the cluster label for equality matchers with the per-cluster label + // Replace the cluster label for regex matchers with the per-cluster label std.strReplace( - // Replace the cluster label for regex matchers with the per-cluster label - std.strReplace( - expr, - 'cluster=~"$cluster"', - $._config.per_cluster_label + '=~"$cluster"' - ), - 'cluster="$cluster"', - $._config.per_cluster_label + '="$cluster"' + expr, + 'cluster=~"$cluster"', + $._config.per_cluster_label + '=~"$cluster"' ), - 'cluster_job', - $._config.per_cluster_label + '_job' + 'cluster="$cluster"', + $._config.per_cluster_label + '="$cluster"' ), + 'cluster_job', + $._config.per_cluster_label + '_job' + ), - panels: [ - p { - targets: if std.objectHas(p, 'targets') then [ - e { - expr: replaceClusterMatchers(e.expr), - } - for e in p.targets - ] else [], - panels: if std.objectHas(p, 'panels') then [ - sp { - targets: if std.objectHas(sp, 'targets') then [ - spe { - expr: replaceClusterMatchers(spe.expr), - } - for spe in sp.targets - ] else [], - panels: if std.objectHas(sp, 'panels') then [ - ssp { - targets: if std.objectHas(ssp, 'targets') then [ - sspe { - expr: replaceClusterMatchers(sspe.expr), - } - for sspe in ssp.targets - ] else [], - } - for ssp in sp.panels - ] else [], - } - for sp in p.panels - ] else [], - } - for p in super.panels - ], - } - + $.dashboard('Loki / Bloom Gateway', uid='bloom-gateway') - .addCluster() - .addNamespace() - .addLog() - .addTag(), - }, + panels: [ + p { + targets: if std.objectHas(p, 'targets') then [ + e { + expr: replaceClusterMatchers(e.expr), + } + for e in p.targets + ] else [], + panels: if std.objectHas(p, 'panels') then [ + sp { + targets: if std.objectHas(sp, 'targets') then [ + spe { + expr: replaceClusterMatchers(spe.expr), + } + for spe in sp.targets + ] else [], + panels: if std.objectHas(sp, 'panels') then [ + ssp { + targets: if std.objectHas(ssp, 'targets') then [ + sspe { + expr: replaceClusterMatchers(sspe.expr), + } + for sspe in ssp.targets + ] else [], + } + for ssp in sp.panels + ] else [], + } + for sp in p.panels + ] else [], + } + for p in super.panels + ], + } + + $.dashboard('Loki / Bloom Gateway', uid='bloom-gateway') + .addCluster() + .addNamespace() + .addLog() + .addTag(), + }, }