mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Fix vector(5) syntax error in loki log explore (#63994)
* [fix] loki log explore : fix vector(5) err * changelog * changelog fmt * rollback change log * fix test and pretty fmt * Update package.json update lezer-logql depedency to 0.1.2 * Update package.json fix conflict ➤ YN0000: │ "@grafana/monaco-logql@npm:^0.0.6": ➤ YN0000: │ @@ -21988,9 +21987,9 @@ ➤ YN0000: │ "@grafana/experimental": 1.1.0 ➤ YN0000: │ "@grafana/faro-core": 1.0.0-beta2 ➤ YN0000: │ "@grafana/faro-web-sdk": 1.0.0-beta2 ➤ YN0000: │ "@grafana/google-sdk": 0.0.4 ➤ YN0028: │ - "@grafana/lezer-logql": 0.1.1 ➤ YN0028: │ + "@grafana/lezer-logql": 0.1.2 ➤ YN0000: │ "@grafana/monaco-logql": ^0.0.6 ➤ YN0000: │ "@grafana/runtime": "workspace:*" ➤ YN0000: │ "@grafana/scenes": ^0.0.14 ➤ YN0000: │ "@grafana/schema": "workspace:*" * Upgrade lezer-logql * fix logql test --------- Co-authored-by: Matias Chomicki <matyax@gmail.com>
This commit is contained in:
@@ -206,7 +206,7 @@ describe('getCompletions', () => {
|
||||
const situation = { type } as Situation;
|
||||
const completions = await getCompletions(situation, completionProvider);
|
||||
|
||||
expect(completions).toHaveLength(24);
|
||||
expect(completions).toHaveLength(25);
|
||||
});
|
||||
|
||||
test('Returns completion options when the situation is IN_RANGE', async () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { escapeLabelValueInExactSelector } from '../../../languageUtils';
|
||||
import { explainOperator } from '../../../querybuilder/operations';
|
||||
import { LokiOperationId } from '../../../querybuilder/types';
|
||||
import { AGGREGATION_OPERATORS, RANGE_VEC_FUNCTIONS } from '../../../syntax';
|
||||
import { AGGREGATION_OPERATORS, RANGE_VEC_FUNCTIONS, BUILT_IN_FUNCTIONS } from '../../../syntax';
|
||||
|
||||
import { CompletionDataProvider } from './CompletionDataProvider';
|
||||
import { NeverCaseError } from './NeverCaseError';
|
||||
@@ -58,6 +58,16 @@ const FUNCTION_COMPLETIONS: Completion[] = RANGE_VEC_FUNCTIONS.map((f) => ({
|
||||
documentation: f.documentation,
|
||||
}));
|
||||
|
||||
const BUILT_IN_FUNCTIONS_COMPLETIONS: Completion[] = BUILT_IN_FUNCTIONS.map((f) => ({
|
||||
type: 'FUNCTION',
|
||||
label: f.label,
|
||||
insertText: `${f.insertText ?? ''}($0)`,
|
||||
isSnippet: true,
|
||||
triggerOnInsert: true,
|
||||
detail: f.detail,
|
||||
documentation: f.documentation,
|
||||
}));
|
||||
|
||||
const DURATION_COMPLETIONS: Completion[] = ['$__interval', '$__range', '1m', '5m', '10m', '30m', '1h', '1d'].map(
|
||||
(text) => ({
|
||||
type: 'DURATION',
|
||||
@@ -293,7 +303,13 @@ export async function getCompletions(
|
||||
case 'EMPTY':
|
||||
case 'AT_ROOT':
|
||||
const historyCompletions = await getAllHistoryCompletions(dataProvider);
|
||||
return [...historyCompletions, ...LOG_COMPLETIONS, ...AGGREGATION_COMPLETIONS, ...FUNCTION_COMPLETIONS];
|
||||
return [
|
||||
...historyCompletions,
|
||||
...LOG_COMPLETIONS,
|
||||
...AGGREGATION_COMPLETIONS,
|
||||
...BUILT_IN_FUNCTIONS_COMPLETIONS,
|
||||
...FUNCTION_COMPLETIONS,
|
||||
];
|
||||
case 'IN_RANGE':
|
||||
return DURATION_COMPLETIONS;
|
||||
case 'IN_GROUPING':
|
||||
|
||||
@@ -141,7 +141,7 @@ describe('buildVisualQueryFromString', () => {
|
||||
});
|
||||
|
||||
it('parses query with with unit label filter', () => {
|
||||
expect(buildVisualQueryFromString('{app="frontend"} | bar < 8mb')).toEqual(
|
||||
expect(buildVisualQueryFromString('{app="frontend"} | bar < 8m')).toEqual(
|
||||
noErrors({
|
||||
labels: [
|
||||
{
|
||||
@@ -150,7 +150,7 @@ describe('buildVisualQueryFromString', () => {
|
||||
label: 'app',
|
||||
},
|
||||
],
|
||||
operations: [{ id: LokiOperationId.LabelFilter, params: ['bar', '<', '8mb'] }],
|
||||
operations: [{ id: LokiOperationId.LabelFilter, params: ['bar', '<', '8m'] }],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -33,6 +33,7 @@ describe('Loki syntax', () => {
|
||||
expect(Prism.highlight('avg_over_time({key="value"}[5m])', syntax, 'loki')).toContain(
|
||||
'<span class="token function">avg_over_time</span>'
|
||||
);
|
||||
expect(Prism.highlight('vector(5)', syntax, 'loki')).toContain('<span class="token function">vector</span>');
|
||||
});
|
||||
it('should highlight operators in Loki query correctly', () => {
|
||||
expect(Prism.highlight('{key="value"} |= "test"', syntax, 'loki')).toContain(
|
||||
|
||||
@@ -181,7 +181,16 @@ export const RANGE_VEC_FUNCTIONS = [
|
||||
},
|
||||
];
|
||||
|
||||
export const FUNCTIONS = [...AGGREGATION_OPERATORS, ...RANGE_VEC_FUNCTIONS];
|
||||
export const BUILT_IN_FUNCTIONS = [
|
||||
{
|
||||
insertText: 'vector',
|
||||
label: 'vector',
|
||||
detail: 'vector(scalar)',
|
||||
documentation: 'Returns the scalar as a vector with no labels.',
|
||||
},
|
||||
];
|
||||
|
||||
export const FUNCTIONS = [...AGGREGATION_OPERATORS, ...RANGE_VEC_FUNCTIONS, ...BUILT_IN_FUNCTIONS];
|
||||
export const LOKI_KEYWORDS = [...FUNCTIONS, ...PIPE_OPERATORS, ...PIPE_PARSERS].map((keyword) => keyword.label);
|
||||
|
||||
export const lokiGrammar: Grammar = {
|
||||
|
||||
Reference in New Issue
Block a user