Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions mixin-utils/test/test_native-classic-histogram.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,13 @@ test.new(std.thisFile)
},
)
)
+ test.case.new(
name='simple templating',
test=test.expect.eq(
actual=utils.ncHistogramApplyTemplate('label_replace(%s, "x", "$1", "y", "(.*)")', { classic: 'classic_query', native: 'native_query' }),
expected={
classic: 'label_replace(classic_query, "x", "$1", "y", "(.*)")',
native: 'label_replace(native_query, "x", "$1", "y", "(.*)")',
}
)
)
10 changes: 10 additions & 0 deletions mixin-utils/utils.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ local g = import 'grafana-builder/grafana.libsonnet';
},
},

// ncHistogramApplyTemplate (native classic histogram template applier)
// Takes a template like 'label_replace(%s, "x", "$1", "y", ".*")'
// with a single substitution and applies to both the classic and native
// histogram query.
ncHistogramApplyTemplate(template, query):: {
assert $.isNativeClassicQuery(query),
native: template % query.native,
classic: template % query.classic,
},

// ncHistogramComment (native classic histogram comment) helps attach
// comments to the query and also keep multiline strings where applicable.
ncHistogramComment(query, comment):: {
Expand Down
Loading