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:
李国忠 2023-03-03 17:09:34 +08:00 committed by GitHub
parent fdc4973b77
commit 9521b0d2d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 12 deletions

View File

@ -264,7 +264,7 @@
"@grafana/faro-core": "1.0.0-beta2",
"@grafana/faro-web-sdk": "1.0.0-beta2",
"@grafana/google-sdk": "0.0.4",
"@grafana/lezer-logql": "0.1.1",
"@grafana/lezer-logql": "0.1.2",
"@grafana/monaco-logql": "^0.0.6",
"@grafana/runtime": "workspace:*",
"@grafana/scenes": "^0.0.14",

View File

@ -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 () => {

View File

@ -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':

View File

@ -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'] }],
})
);
});

View File

@ -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(

View File

@ -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 = {

View File

@ -5070,12 +5070,12 @@ __metadata:
languageName: node
linkType: hard
"@grafana/lezer-logql@npm:0.1.1":
version: 0.1.1
resolution: "@grafana/lezer-logql@npm:0.1.1"
"@grafana/lezer-logql@npm:0.1.2":
version: 0.1.2
resolution: "@grafana/lezer-logql@npm:0.1.2"
peerDependencies:
"@lezer/lr": ^1.0.0
checksum: b0d71e5670c54d92fbc4bd92fe72cfb27469cc9797d5595b284f9d2b86782584cb1a9b8bac51af07648b807a9287e7159dcdd0e1fc3e32a2e79d52b3a7700e4b
checksum: 4b62fda9c2c7e29c48f7485df19573b96bfd34539529283980f24e9931f81b44c86b1e655bae5f50730d9d7b37bae87e6f7f7773dafaf4f6acef90b2c2cb776f
languageName: node
linkType: hard
@ -21995,7 +21995,7 @@ __metadata:
"@grafana/faro-core": 1.0.0-beta2
"@grafana/faro-web-sdk": 1.0.0-beta2
"@grafana/google-sdk": 0.0.4
"@grafana/lezer-logql": 0.1.1
"@grafana/lezer-logql": 0.1.2
"@grafana/monaco-logql": ^0.0.6
"@grafana/runtime": "workspace:*"
"@grafana/scenes": ^0.0.14