Files
grafana/public/app/plugins/datasource/loki/querybuilder/LokiQueryModeller.ts
Torkel Ödegaard feaa4a5c64 Loki: Support binary operations and nested queries in new builder (#47012)
* Binary ops support

* Add support for nested expressions in loki

* Nested queries working

* Fixing tests

* Share more code between loki and prometheus query modellers
2022-03-29 18:50:07 +02:00

55 lines
1.9 KiB
TypeScript

import { LokiAndPromQueryModellerBase } from '../../prometheus/querybuilder/shared/LokiAndPromQueryModellerBase';
import { QueryBuilderLabelFilter } from '../../prometheus/querybuilder/shared/types';
import { getOperationDefintions } from './operations';
import { LokiOperationId, LokiQueryPattern, LokiVisualQueryOperationCategory } from './types';
export class LokiQueryModeller extends LokiAndPromQueryModellerBase {
constructor() {
super(getOperationDefintions);
this.setOperationCategories([
LokiVisualQueryOperationCategory.Aggregations,
LokiVisualQueryOperationCategory.RangeFunctions,
LokiVisualQueryOperationCategory.Formats,
LokiVisualQueryOperationCategory.BinaryOps,
LokiVisualQueryOperationCategory.LabelFilters,
LokiVisualQueryOperationCategory.LineFilters,
]);
}
renderLabels(labels: QueryBuilderLabelFilter[]) {
if (labels.length === 0) {
return '{}';
}
return super.renderLabels(labels);
}
getQueryPatterns(): LokiQueryPattern[] {
return [
{
name: 'Log query and label filter',
operations: [
{ id: LokiOperationId.LineMatchesRegex, params: [''] },
{ id: LokiOperationId.Logfmt, params: [] },
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
{ id: LokiOperationId.LabelFilter, params: ['', '=', ''] },
],
},
{
name: 'Time series query on value inside log line',
operations: [
{ id: LokiOperationId.LineMatchesRegex, params: [''] },
{ id: LokiOperationId.Logfmt, params: [] },
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
{ id: LokiOperationId.Unwrap, params: [''] },
{ id: LokiOperationId.SumOverTime, params: ['auto'] },
{ id: LokiOperationId.Sum, params: [] },
],
},
];
}
}
export const lokiQueryModeller = new LokiQueryModeller();