mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Binary ops support * Add support for nested expressions in loki * Nested queries working * Fixing tests * Share more code between loki and prometheus query modellers
55 lines
1.9 KiB
TypeScript
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();
|