mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Do not throw error for label_join function (#86465)
This commit is contained in:
parent
95ad100cb9
commit
2d733a4d77
@ -219,6 +219,7 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] {
|
||||
],
|
||||
defaultParams: ['', ',', ''],
|
||||
renderer: labelJoinRenderer,
|
||||
explainHandler: labelJoinExplainHandler,
|
||||
addOperationHandler: labelJoinAddOperationHandler,
|
||||
}),
|
||||
createFunction({ id: PromOperationId.Log10 }),
|
||||
@ -374,11 +375,21 @@ function addNestedQueryHandler(def: QueryBuilderOperationDef, query: PromVisualQ
|
||||
}
|
||||
|
||||
function labelJoinRenderer(model: QueryBuilderOperation, def: QueryBuilderOperationDef, innerExpr: string) {
|
||||
if (typeof model.params[1] !== 'string') {
|
||||
throw 'The separator must be a string';
|
||||
const paramZero = model.params[0] ?? '';
|
||||
const paramOne = model.params[1] ?? '';
|
||||
|
||||
const separator = `"${paramOne}"`;
|
||||
return `${model.id}(${innerExpr}, "${paramZero}", ${separator}, "${model.params.slice(2).join(separator)}")`;
|
||||
}
|
||||
|
||||
function labelJoinExplainHandler(op: QueryBuilderOperation, def?: QueryBuilderOperationDef): string {
|
||||
let explainMessage = def?.documentation ?? 'no docs';
|
||||
|
||||
if (typeof op.params[1] !== 'string') {
|
||||
explainMessage += ' 🚨🚨🚨 The `separator` must be a string.';
|
||||
}
|
||||
const separator = `"${model.params[1]}"`;
|
||||
return `${model.id}(${innerExpr}, "${model.params[0]}", ${separator}, "${model.params.slice(2).join(separator)}")`;
|
||||
|
||||
return explainMessage;
|
||||
}
|
||||
|
||||
function labelJoinAddOperationHandler<T extends QueryWithOperations>(def: QueryBuilderOperationDef, query: T) {
|
||||
|
Loading…
Reference in New Issue
Block a user