@@ -10,23 +10,27 @@ local utils = import '../utils.libsonnet';
1010 varMetric='up' ,
1111 enableLokiLogs=false ,
1212 customAllValue='.+' ,
13- prometheusDatasourceName='datasource' ,
14- prometheusDatasourceLabel='Data source' ,
13+ prometheusDatasourceName=if enableLokiLogs then 'prometheus_datasource' else 'datasource' ,
14+ prometheusDatasourceLabel=if enableLokiLogs then 'Prometheus datasource' else 'Data source' ,
1515 ): {
16- local varMetricTemplate =
17- if std.type (varMetric) == 'array'
18- then '{__name__=~"%s",%%s}' % std.join ('|' , std.uniq (varMetric))
16+ local varMetricTemplate(varMetric, chainSelector) =
17+ // check if chainSelector is not empty string (case when filtering selector is empty):
18+ if std.type (varMetric) == 'array' && chainSelector != ''
19+ then '{__name__=~"%s",%s}' % [std.join ('|' , std.uniq (varMetric)), chainSelector]
20+ else if std.type (varMetric) == 'array' && chainSelector == ''
21+ then '{__name__=~"%s"}' % std.join ('|' , std.uniq (varMetric))
1922 else if std.type (varMetric) == 'string'
20- then '%s{%% s}' % varMetric
23+ then '%s{%s}' % [ varMetric, chainSelector]
2124 else error ('varMetric must be array or string' ),
25+
2226 local root = self ,
2327 local variablesFromLabels(groupLabels, instanceLabels, filteringSelector, multiInstance=true ) =
2428 local chainVarProto(index, chainVar) =
2529 var.query.new(chainVar.label)
2630 + var.query.withDatasourceFromVariable(root.datasources.prometheus)
2731 + var.query.queryTypes.withLabelValues(
2832 chainVar.label,
29- varMetricTemplate % [ chainVar.chainSelector] ,
33+ varMetricTemplate(varMetric, chainVar.chainSelector) ,
3034 )
3135 + var.query.generalOptions.withLabel(utils.toSentenceCase(chainVar.label))
3236 + var.query.selectionOptions.withIncludeAll(
@@ -43,7 +47,7 @@ local utils = import '../utils.libsonnet';
4347 asc=true ,
4448 caseInsensitive=false
4549 );
46- std.mapWithIndex (chainVarProto, utils.chainLabels(groupLabels + instanceLabels, [filteringSelector])),
50+ std.mapWithIndex (chainVarProto, utils.chainLabels(groupLabels + instanceLabels, if std.length (filteringSelector) > 0 then [filteringSelector] else [ ])),
4751 datasources: {
4852 prometheus:
4953 var.datasource.new(prometheusDatasourceName, 'prometheus' )
0 commit comments