From ae187bd8e6ed2b947b200c685f9fac27ccfb248c Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Wed, 18 Dec 2024 09:35:46 +0000 Subject: [PATCH] Add optional adhoc support for logs-lib --- logs-lib/logs/main.libsonnet | 4 ++++ logs-lib/logs/variables.libsonnet | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/logs-lib/logs/main.libsonnet b/logs-lib/logs/main.libsonnet index 42a574cc4..386319620 100644 --- a/logs-lib/logs/main.libsonnet +++ b/logs-lib/logs/main.libsonnet @@ -17,6 +17,8 @@ local variables = import './variables.libsonnet'; logsVolumeGroupBy='level', extraFilters='', customAllValue='.*', + adHocEnabled=false, + adHocLabels=[], ): { local this = self, @@ -27,6 +29,8 @@ local variables = import './variables.libsonnet'; filterSelector, labels, customAllValue, + adHocEnabled, + adHocLabels, ), targets: targets( diff --git a/logs-lib/logs/variables.libsonnet b/logs-lib/logs/variables.libsonnet index 7bdb393c8..012d121c3 100644 --- a/logs-lib/logs/variables.libsonnet +++ b/logs-lib/logs/variables.libsonnet @@ -9,6 +9,8 @@ function( filterSelector, labels, customAllValue, + adHocEnabled, + adHocLabels, ) { // strip trailing or starting comma if present that are not accepted in LoqQL @@ -47,14 +49,28 @@ function( + var.datasource.withRegex(datasourceRegex) + var.query.generalOptions.withLabel(datasourceLabel), - regex_search: + regexSearch: var.textbox.new('regex_search', default='') + var.query.generalOptions.withLabel('Regex search'), + adHoc: + var.adhoc.new('adhoc', 'loki', '${' + self.datasource.name + '}') + + var.adhoc.generalOptions.withLabel('Adhoc filters') + + var.adhoc.generalOptions.withDescription('Add additional filters') + + (if std.length(adHocLabels) > 0 then { + defaultKeys: [ + { + text: l, + value: l, + } + for l in adHocLabels + ], + } else {}), toArray: [self.datasource] + variablesFromLabels(labels, _filteringSelector) - + [self.regex_search], + + [self.regexSearch] + + (if adHocEnabled then [self.adHoc] else []), queriesSelector: std.join(