Skip to content

Commit

Permalink
Add optional adhoc support for logs-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
v-zhuravlev committed Dec 18, 2024
1 parent f5dab6f commit ae187bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions logs-lib/logs/main.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ local variables = import './variables.libsonnet';
logsVolumeGroupBy='level',
extraFilters='',
customAllValue='.*',
adHocEnabled=false,
adHocLabels=[],
): {

local this = self,
Expand All @@ -27,6 +29,8 @@ local variables = import './variables.libsonnet';
filterSelector,
labels,
customAllValue,
adHocEnabled,
adHocLabels,
),

targets: targets(
Expand Down
20 changes: 18 additions & 2 deletions logs-lib/logs/variables.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function(
filterSelector,
labels,
customAllValue,
adHocEnabled,
adHocLabels,
)
{
// strip trailing or starting comma if present that are not accepted in LoqQL
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ae187bd

Please sign in to comment.