Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions common-lib/common/variables/variables.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ local utils = import '../utils.libsonnet';
varMetric='up',
enableLokiLogs=false,
customAllValue='.+',
prometheusDatasourceName='datasource',
prometheusDatasourceLabel='Data source',
prometheusDatasourceName=if enableLokiLogs then 'prometheus_datasource' else 'datasource',
prometheusDatasourceLabel=if enableLokiLogs then 'Prometheus datasource' else 'Data source',
): {
local varMetricTemplate =
if std.type(varMetric) == 'array'
then '{__name__=~"%s",%%s}' % std.join('|', std.uniq(varMetric))
local varMetricTemplate(varMetric, chainSelector) =
// check if chainSelector is not empty string (case when filtering selector is empty):
if std.type(varMetric) == 'array' && chainSelector != ''
then '{__name__=~"%s",%s}' % [std.join('|', std.uniq(varMetric)), chainSelector]
else if std.type(varMetric) == 'array' && chainSelector == ''
then '{__name__=~"%s"}' % std.join('|', std.uniq(varMetric))
else if std.type(varMetric) == 'string'
then '%s{%%s}' % varMetric
then '%s{%s}' % [varMetric, chainSelector]
else error ('varMetric must be array or string'),

local root = self,
local variablesFromLabels(groupLabels, instanceLabels, filteringSelector, multiInstance=true) =
local chainVarProto(index, chainVar) =
var.query.new(chainVar.label)
+ var.query.withDatasourceFromVariable(root.datasources.prometheus)
+ var.query.queryTypes.withLabelValues(
chainVar.label,
varMetricTemplate % [chainVar.chainSelector],
varMetricTemplate(varMetric, chainVar.chainSelector),
)
+ var.query.generalOptions.withLabel(utils.toSentenceCase(chainVar.label))
+ var.query.selectionOptions.withIncludeAll(
Expand All @@ -43,7 +47,7 @@ local utils = import '../utils.libsonnet';
asc=true,
caseInsensitive=false
);
std.mapWithIndex(chainVarProto, utils.chainLabels(groupLabels + instanceLabels, [filteringSelector])),
std.mapWithIndex(chainVarProto, utils.chainLabels(groupLabels + instanceLabels, if std.length(filteringSelector) > 0 then [filteringSelector] else [])),
datasources: {
prometheus:
var.datasource.new(prometheusDatasourceName, 'prometheus')
Expand Down
Loading