mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tempo: Support special characters in identifiers (#79565)
This commit is contained in:
@@ -2,10 +2,10 @@ import { computeErrorMessage, getErrorNodes } from './errorHighlighting';
|
||||
|
||||
describe('Check for syntax errors in query', () => {
|
||||
it.each([
|
||||
['{span.http.status_code = }', 'Invalid value after comparison or aritmetic operator.'],
|
||||
['{span.http.status_code 200}', 'Invalid operator after field expression.'],
|
||||
['{span.http.status_code = }', 'Invalid value after comparison or arithmetic operator.'],
|
||||
['{span.http.status_code 200}', 'Invalid comparison operator after field expression.'],
|
||||
['{span.http.status_code ""}', 'Invalid operator after field expression.'],
|
||||
['{span.http.status_code @ 200}', 'Invalid operator after field expression.'],
|
||||
['{span.http.status_code @ 200}', 'Invalid comparison operator after field expression.'],
|
||||
['{span.http.status_code span.http.status_code}', 'Invalid operator after field expression.'],
|
||||
[
|
||||
'{span.http.status_code = 200} {span.http.status_code = 200}',
|
||||
@@ -24,12 +24,12 @@ describe('Check for syntax errors in query', () => {
|
||||
'{span.http.status_code = 200} && {span.http.status_code = 200} | avg() > 3',
|
||||
'Invalid expression for aggregator operator.',
|
||||
],
|
||||
['{ 1 + 1 = 2 + }', 'Invalid value after comparison or aritmetic operator.'],
|
||||
['{ 1 + 1 = 2 + }', 'Invalid value after comparison or arithmetic operator.'],
|
||||
['{ .a && }', 'Invalid value after logical operator.'],
|
||||
['{ .a || }', 'Invalid value after logical operator.'],
|
||||
['{ .a + }', 'Invalid value after comparison or aritmetic operator.'],
|
||||
['{ 200 = 200 200 }', 'Invalid operator after field expression.'],
|
||||
['{.foo 300}', 'Invalid operator after field expression.'],
|
||||
['{ .a + }', 'Invalid value after comparison or arithmetic operator.'],
|
||||
['{ 200 = 200 200 }', 'Invalid comparison operator after field expression.'],
|
||||
['{.foo 300}', 'Invalid comparison operator after field expression.'],
|
||||
['{.foo 300 && .bar = 200}', 'Invalid operator after field expression.'],
|
||||
['{.foo 300 && .bar 200}', 'Invalid operator after field expression.'],
|
||||
['{.foo=1} {.bar=2}', 'Invalid spanset combining operator after spanset expression.'],
|
||||
@@ -48,8 +48,8 @@ describe('Check for syntax errors in query', () => {
|
||||
['{.}', 'Invalid expression for spanset.'],
|
||||
['{ resource. }', 'Invalid expression for spanset.'],
|
||||
['{ span. }', 'Invalid expression for spanset.'],
|
||||
['{.foo=}', 'Invalid value after comparison or aritmetic operator.'],
|
||||
['{.foo="}', 'Invalid value after comparison or aritmetic operator.'],
|
||||
['{.foo=}', 'Invalid value after comparison or arithmetic operator.'],
|
||||
['{.foo="}', 'Invalid value after comparison or arithmetic operator.'],
|
||||
['{.foo=300} |', 'Invalid aggregation operator after pipepile operator.'],
|
||||
['{.foo=300} && {.bar=200} |', 'Invalid aggregation operator after pipepile operator.'],
|
||||
['{.foo=300} && {.bar=300} && {.foo=300} |', 'Invalid aggregation operator after pipepile operator.'],
|
||||
|
||||
@@ -32,7 +32,7 @@ export const computeErrorMessage = (errorNode: SyntaxNode) => {
|
||||
case Or:
|
||||
return 'Invalid value after logical operator.';
|
||||
case FieldOp:
|
||||
return 'Invalid value after comparison or aritmetic operator.';
|
||||
return 'Invalid value after comparison or arithmetic operator.';
|
||||
default:
|
||||
return 'Invalid operator after field expression.';
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ const keywords = intrinsics.concat(scopes);
|
||||
|
||||
const statusValues = ['ok', 'unset', 'error', 'false', 'true'];
|
||||
|
||||
export const language: languages.IMonarchLanguage = {
|
||||
const language: languages.IMonarchLanguage = {
|
||||
ignoreCase: false,
|
||||
defaultToken: '',
|
||||
tokenPostfix: '.traceql',
|
||||
@@ -88,13 +88,9 @@ export const language: languages.IMonarchLanguage = {
|
||||
|
||||
// functions and predefined values
|
||||
[
|
||||
// If not inside quotes, namely outside of open and closed `"`,
|
||||
// allow only word characters (those matching `\w`) and full stop (`.`).
|
||||
//
|
||||
// If inside quotes, e.g. `"here"`, allow for any character, except for `"` and `\` which must be
|
||||
// escaped with a backslash (`\"` and `\\` respectively).
|
||||
// Quotes can be used to support special tag names, such as those with spaces (e.g., `my tag`).
|
||||
/(?:\w|[.]|"(?:\\"|\\\\|[^\\"])*")+/,
|
||||
// Inside (double) quotes, all characters are allowed, with the exception of `\` and `"` that must be escaped (`\\` and `\"`).
|
||||
// Outside quotes, some more characters are prohibited, such as `!` and `=`.
|
||||
/(?:\w|^[^{}()=~!<>&|," ]|"(?:\\"|\\\\|[^\\"])*")+/,
|
||||
{
|
||||
cases: {
|
||||
'@functions': 'predefined',
|
||||
@@ -147,6 +143,7 @@ export const language: languages.IMonarchLanguage = {
|
||||
},
|
||||
};
|
||||
|
||||
// For "TraceQL" tab (Monarch editor for TraceQL)
|
||||
export const languageDefinition = {
|
||||
id: 'traceql',
|
||||
extensions: ['.traceql'],
|
||||
@@ -158,6 +155,7 @@ export const languageDefinition = {
|
||||
},
|
||||
};
|
||||
|
||||
// For "Search" tab (query builder)
|
||||
export const traceqlGrammar: Grammar = {
|
||||
comment: {
|
||||
pattern: /\/\/.*/,
|
||||
|
||||
Reference in New Issue
Block a user