mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Fix incorrect TopK value type in query builder (#52226)
* Loki: Fix incorrect TopK value type in query builder * Simplify code * Remove bracket * Brackets are back
This commit is contained in:
parent
91fd0223a4
commit
8fc51932f5
@ -124,4 +124,43 @@ describe('createAggregationOperationWithParams', () => {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
it('returns correct query string using aggregation definitions with overrides and number type param', () => {
|
||||||
|
const def = createAggregationOperationWithParam(
|
||||||
|
'test_aggregation',
|
||||||
|
{
|
||||||
|
params: [{ name: 'K-value', type: 'number' }],
|
||||||
|
defaultParams: [5],
|
||||||
|
},
|
||||||
|
{ category: 'test_category' }
|
||||||
|
);
|
||||||
|
|
||||||
|
const topKByDefinition = def[1];
|
||||||
|
expect(
|
||||||
|
topKByDefinition.renderer(
|
||||||
|
{ id: '__topk_by', params: ['5', 'source', 'place'] },
|
||||||
|
def[1],
|
||||||
|
'rate({place="luna"} |= `` [5m])'
|
||||||
|
)
|
||||||
|
).toBe('test_aggregation by(source, place) (5, rate({place="luna"} |= `` [5m]))');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns correct query string using aggregation definitions with overrides and string type param', () => {
|
||||||
|
const def = createAggregationOperationWithParam(
|
||||||
|
'test_aggregation',
|
||||||
|
{
|
||||||
|
params: [{ name: 'Identifier', type: 'string' }],
|
||||||
|
defaultParams: ['count'],
|
||||||
|
},
|
||||||
|
{ category: 'test_category' }
|
||||||
|
);
|
||||||
|
|
||||||
|
const countValueDefinition = def[1];
|
||||||
|
expect(
|
||||||
|
countValueDefinition.renderer(
|
||||||
|
{ id: 'count_values', params: ['5', 'source', 'place'] },
|
||||||
|
def[1],
|
||||||
|
'rate({place="luna"} |= `` [5m])'
|
||||||
|
)
|
||||||
|
).toBe('test_aggregation by(source, place) ("5", rate({place="luna"} |= `` [5m]))');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -279,15 +279,13 @@ function getAggregationExplainer(aggregationName: string, mode: 'by' | 'without'
|
|||||||
|
|
||||||
function getAggregationByRendererWithParameter(aggregation: string) {
|
function getAggregationByRendererWithParameter(aggregation: string) {
|
||||||
return function aggregationRenderer(model: QueryBuilderOperation, def: QueryBuilderOperationDef, innerExpr: string) {
|
return function aggregationRenderer(model: QueryBuilderOperation, def: QueryBuilderOperationDef, innerExpr: string) {
|
||||||
function mapType(p: QueryBuilderOperationParamValue) {
|
const restParamIndex = def.params.findIndex((param) => param.restParam);
|
||||||
if (typeof p === 'string') {
|
const params = model.params.slice(0, restParamIndex);
|
||||||
return `\"${p}\"`;
|
const restParams = model.params.slice(restParamIndex);
|
||||||
}
|
|
||||||
return p;
|
return `${aggregation} by(${restParams.join(', ')}) (${params
|
||||||
}
|
.map((param, idx) => (def.params[idx].type === 'string' ? `\"${param}\"` : param))
|
||||||
const params = model.params.slice(0, -1);
|
.join(', ')}, ${innerExpr})`;
|
||||||
const restParams = model.params.slice(1);
|
|
||||||
return `${aggregation} by(${restParams.join(', ')}) (${params.map(mapType).join(', ')}, ${innerExpr})`;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user