github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/production/loki-mixin/dashboards/loki-operational.libsonnet (about) 1 local lokiOperational = (import './dashboard-loki-operational.json'); 2 local utils = import 'mixin-utils/utils.libsonnet'; 3 4 (import 'dashboard-utils.libsonnet') { 5 grafanaDashboards+: { 6 local dashboards = self, 7 8 'loki-operational.json': { 9 local cfg = self, 10 11 showAnnotations:: true, 12 showLinks:: true, 13 showMultiCluster:: true, 14 clusterLabel:: $._config.per_cluster_label, 15 16 hiddenRows:: [ 17 'Cassandra', 18 ] + if !$._config.ssd.enabled then [] else [ 19 'Ingester', 20 ], 21 22 jobMatchers:: { 23 cortexgateway: [utils.selector.re('job', '($namespace)/cortex-gw')], 24 distributor: [utils.selector.re('job', '($namespace)/%s' % (if $._config.ssd.enabled then '%s-write' % $._config.ssd.pod_prefix_matcher else 'distributor'))], 25 ingester: [utils.selector.re('job', '($namespace)/%s' % (if $._config.ssd.enabled then '%s-write' % $._config.ssd.pod_prefix_matcher else 'ingester'))], 26 querier: [utils.selector.re('job', '($namespace)/%s' % (if $._config.ssd.enabled then '%s-read' % $._config.ssd.pod_prefix_matcher else 'querier'))], 27 }, 28 29 podMatchers:: { 30 cortexgateway: [utils.selector.re('pod', 'cortex-gw')], 31 distributor: [utils.selector.re('pod', '%s' % (if $._config.ssd.enabled then '%s-write.*' % $._config.ssd.pod_prefix_matcher else 'distributor.*'))], 32 ingester: [utils.selector.re('pod', '%s' % (if $._config.ssd.enabled then '%s-write.*' % $._config.ssd.pod_prefix_matcher else 'ingester.*'))], 33 querier: [utils.selector.re('pod', '%s' % (if $._config.ssd.enabled then '%s-read.*' % $._config.ssd.pod_prefix_matcher else 'querier.*'))], 34 }, 35 } 36 + lokiOperational + { 37 annotations: 38 if dashboards['loki-operational.json'].showAnnotations 39 then super.annotations 40 else {}, 41 42 links: 43 if dashboards['loki-operational.json'].showLinks then 44 super.links 45 else [], 46 47 local matcherStr(matcherId, matcher='job', sep=',') = 48 if matcher == 'job' then 49 if std.length(dashboards['loki-operational.json'].jobMatchers[matcherId]) > 0 then 50 std.join(',', ['%(label)s%(op)s"%(value)s"' % matcher for matcher in dashboards['loki-operational.json'].jobMatchers[matcherId]]) + sep 51 else error 'no job matchers' 52 else if matcher == 'pod' then 53 if std.length(dashboards['loki-operational.json'].podMatchers[matcherId]) > 0 then 54 std.join(',', ['%(label)s%(op)s"%(value)s"' % matcher for matcher in dashboards['loki-operational.json'].podMatchers[matcherId]]) + sep 55 else error 'no pod matchers' 56 else error 'matcher must be either job or container', 57 58 local replaceClusterMatchers(expr) = 59 if dashboards['loki-operational.json'].showMultiCluster 60 then expr 61 else 62 std.strReplace( 63 std.strReplace( 64 std.strReplace( 65 expr, 66 ', ' + $._config.per_cluster_label + '="$cluster"', 67 '' 68 ), 69 ', ' + $._config.per_cluster_label + '=~"$cluster"', 70 '' 71 ), 72 $._config.per_cluster_label + '="$cluster",', 73 '' 74 ), 75 76 local replaceMatchers(expr) = 77 std.strReplace( 78 std.strReplace( 79 std.strReplace( 80 std.strReplace( 81 std.strReplace( 82 std.strReplace( 83 std.strReplace( 84 std.strReplace( 85 std.strReplace( 86 std.strReplace( 87 std.strReplace( 88 std.strReplace( 89 std.strReplace( 90 std.strReplace( 91 std.strReplace( 92 expr, 93 'pod=~"querier.*"', 94 matcherStr('querier', matcher='pod', sep='') 95 ), 96 'pod=~"ingester.*"', 97 matcherStr('ingester', matcher='pod', sep='') 98 ), 99 'pod=~"distributor.*"', 100 matcherStr('distributor', matcher='pod', sep='') 101 ), 102 'job="$namespace/cortex-gw",', 103 matcherStr('cortexgateway') 104 ), 105 'job="$namespace/cortex-gw"', 106 std.rstripChars(matcherStr('cortexgateway'), ',') 107 ), 108 'job=~"($namespace)/cortex-gw",', 109 matcherStr('cortexgateway') 110 ), 111 'job="$namespace/distributor",', 112 matcherStr('distributor') 113 ), 114 'job="$namespace/distributor"', 115 std.rstripChars(matcherStr('distributor'), ',') 116 ), 117 'job=~"($namespace)/distributor",', 118 matcherStr('distributor') 119 ), 120 'job=~"($namespace)/distributor"', 121 std.rstripChars(matcherStr('distributor'), ',') 122 ), 123 'job="$namespace/ingester",', 124 matcherStr('ingester') 125 ), 126 'job="$namespace/ingester"', 127 std.rstripChars(matcherStr('ingester'), ',') 128 ), 129 'job=~"($namespace)/ingester",', 130 matcherStr('ingester'), 131 ), 132 'job="$namespace/querier",', 133 matcherStr('querier') 134 ), 135 'job="$namespace/querier"', 136 std.rstripChars(matcherStr('querier'), ',') 137 ), 138 139 local replaceAllMatchers(expr) = 140 replaceMatchers(replaceClusterMatchers(expr)), 141 142 local selectDatasource(ds) = 143 if ds == null || ds == '' then ds 144 else if ds == '$datasource' then '$datasource' 145 else '$logs', 146 147 local isRowHidden(row) = 148 std.member(dashboards['loki-operational.json'].hiddenRows, row), 149 150 panels: [ 151 p { 152 datasource: selectDatasource(super.datasource), 153 targets: if std.objectHas(p, 'targets') then [ 154 e { 155 expr: replaceAllMatchers(e.expr), 156 } 157 for e in p.targets 158 ] else [], 159 panels: if std.objectHas(p, 'panels') then [ 160 sp { 161 datasource: selectDatasource(super.datasource), 162 targets: if std.objectHas(sp, 'targets') then [ 163 e { 164 expr: replaceAllMatchers(e.expr), 165 } 166 for e in sp.targets 167 ] else [], 168 panels: if std.objectHas(sp, 'panels') then [ 169 ssp { 170 datasource: selectDatasource(super.datasource), 171 targets: if std.objectHas(ssp, 'targets') then [ 172 e { 173 expr: replaceAllMatchers(e.expr), 174 } 175 for e in ssp.targets 176 ] else [], 177 } 178 for ssp in sp.panels 179 ] else [], 180 } 181 for sp in p.panels 182 ] else [], 183 title: if !($._config.ssd.enabled && p.type == 'row') then p.title else 184 if p.title == 'Distributor' then 'Write Path' 185 else if p.title == 'Querier' then 'Read Path' 186 else p.title, 187 } 188 for p in super.panels 189 if !(p.type == 'row' && isRowHidden(p.title)) 190 ], 191 } + 192 $.dashboard('Loki / Operational', uid='operational') 193 // The queries in this dashboard don't make use of the cluster tempalte label selector 194 // but we keep it here to allow selecting a namespace specific to a certain cluster, the 195 // namespace template variable selectors query uses the cluster value. 196 .addLog() 197 .addCluster() 198 .addNamespace() 199 .addTag(), 200 }, 201 }