From 38fdfe43f573aa61aa9951facc3455887a624e98 Mon Sep 17 00:00:00 2001 From: Joey <90795735+joey-grafana@users.noreply.github.com> Date: Wed, 22 May 2024 13:03:51 +0100 Subject: [PATCH] Tempo: Update lezer autocomplete (histogram, quantile) and add missing functions (#88131) * Update version * Update autocomplete, add new functions * Update highlighting * Update yarn.lock --- .../app/plugins/datasource/tempo/package.json | 2 +- .../datasource/tempo/traceql/autocomplete.ts | 40 +++++++++++++++---- .../datasource/tempo/traceql/highlighting.ts | 9 +++-- .../datasource/tempo/traceql/traceql.ts | 10 ++++- yarn.lock | 10 ++--- 5 files changed, 52 insertions(+), 19 deletions(-) diff --git a/public/app/plugins/datasource/tempo/package.json b/public/app/plugins/datasource/tempo/package.json index 5a58e5f665a..18c3e8024cb 100644 --- a/public/app/plugins/datasource/tempo/package.json +++ b/public/app/plugins/datasource/tempo/package.json @@ -9,7 +9,7 @@ "@grafana/e2e-selectors": "workspace:*", "@grafana/experimental": "1.7.11", "@grafana/lezer-logql": "0.2.3", - "@grafana/lezer-traceql": "0.0.16", + "@grafana/lezer-traceql": "0.0.17", "@grafana/monaco-logql": "^0.0.7", "@grafana/o11y-ds-frontend": "workspace:*", "@grafana/runtime": "workspace:*", diff --git a/public/app/plugins/datasource/tempo/traceql/autocomplete.ts b/public/app/plugins/datasource/tempo/traceql/autocomplete.ts index 15b81656bbf..63335ce4f81 100644 --- a/public/app/plugins/datasource/tempo/traceql/autocomplete.ts +++ b/public/app/plugins/datasource/tempo/traceql/autocomplete.ts @@ -171,19 +171,19 @@ export class CompletionProvider implements monacoTypes.languages.CompletionItemP ]; // Functions (aggregator, selector, and combining operators) - static readonly spansetAggregatorOps: MinimalCompletionItem[] = [ - { - label: 'count', - insertText: 'count()$0', - detail: 'Number of spans', - documentation: 'Counts the number of spans in a spanset', - }, + static readonly aggregatorFunctions: MinimalCompletionItem[] = [ { label: 'avg', insertText: 'avg($0)', detail: 'Average of attribute', documentation: 'Computes the average of a given numeric attribute or intrinsic for a spanset.', }, + { + label: 'count', + insertText: 'count()$0', + detail: 'Number of spans', + documentation: 'Counts the number of spans in a spanset.', + }, { label: 'max', insertText: 'max($0)', @@ -205,13 +205,37 @@ export class CompletionProvider implements monacoTypes.languages.CompletionItemP ]; static readonly functions: MinimalCompletionItem[] = [ - ...this.spansetAggregatorOps, + ...this.aggregatorFunctions, { label: 'by', insertText: 'by($0)', detail: 'Grouping of attributes', documentation: 'Groups by arbitrary attributes.', }, + { + label: 'count_over_time', + insertText: 'count_over_time()$0', + detail: 'Number of spans over time', + documentation: 'Counts the number of spans over time.', + }, + { + label: 'histogram_over_time', + insertText: 'histogram_over_time($0)', + detail: 'Histogram of attribute over time', + documentation: 'Retrieves a histogram of an attributes values over time which are sorted into buckets.', + }, + { + label: 'quantile_over_time', + insertText: 'quantile_over_time($0)', + detail: 'Quantile of attribute over time', + documentation: 'Retrieves one or more quantiles of an attributes numeric values over time.', + }, + { + label: 'rate', + insertText: 'rate()$0', + detail: 'Rate of spans', + documentation: 'Counts the rate of spans per second.', + }, { label: 'select', insertText: 'select($0)', diff --git a/public/app/plugins/datasource/tempo/traceql/highlighting.ts b/public/app/plugins/datasource/tempo/traceql/highlighting.ts index 9ba47beba6f..a8fbefc23ce 100644 --- a/public/app/plugins/datasource/tempo/traceql/highlighting.ts +++ b/public/app/plugins/datasource/tempo/traceql/highlighting.ts @@ -58,11 +58,12 @@ export const computeErrorMessage = (errorNode: SyntaxNode) => { } case IntrinsicField: case Aggregate: + if (errorNode.parent?.parent?.parent?.type.id === GroupOperation) { + return 'Invalid expression for by operator.'; + } else if (errorNode.parent?.parent?.parent?.parent?.type.id === SelectOperation) { + return 'Invalid expression for select operator.'; + } return 'Invalid expression for aggregator operator.'; - case GroupOperation: - return 'Invalid expression for by operator.'; - case SelectOperation: - return 'Invalid expression for select operator.'; case AttributeField: return 'Invalid expression for spanset.'; case ScalarFilter: diff --git a/public/app/plugins/datasource/tempo/traceql/traceql.ts b/public/app/plugins/datasource/tempo/traceql/traceql.ts index b2d23399da1..5d8dc077584 100644 --- a/public/app/plugins/datasource/tempo/traceql/traceql.ts +++ b/public/app/plugins/datasource/tempo/traceql/traceql.ts @@ -40,7 +40,15 @@ export const intrinsics = [ ]; export const scopes: string[] = ['resource', 'span']; -export const functions = ['avg', 'min', 'max', 'sum', 'count', 'by']; +const aggregatorFunctions = ['avg', 'count', 'max', 'min', 'sum']; +const functions = aggregatorFunctions.concat([ + 'by', + 'count_over_time', + 'histogram_over_time', + 'quantile_over_time', + 'rate', + 'select', +]); const keywords = intrinsics.concat(scopes); diff --git a/yarn.lock b/yarn.lock index b4610bb6fc8..918b1291b1a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2871,7 +2871,7 @@ __metadata: "@grafana/e2e-selectors": "workspace:*" "@grafana/experimental": "npm:1.7.11" "@grafana/lezer-logql": "npm:0.2.3" - "@grafana/lezer-traceql": "npm:0.0.16" + "@grafana/lezer-traceql": "npm:0.0.17" "@grafana/monaco-logql": "npm:^0.0.7" "@grafana/o11y-ds-frontend": "workspace:*" "@grafana/plugin-configs": "npm:11.0.0" @@ -3225,12 +3225,12 @@ __metadata: languageName: node linkType: hard -"@grafana/lezer-traceql@npm:0.0.16": - version: 0.0.16 - resolution: "@grafana/lezer-traceql@npm:0.0.16" +"@grafana/lezer-traceql@npm:0.0.17": + version: 0.0.17 + resolution: "@grafana/lezer-traceql@npm:0.0.17" peerDependencies: "@lezer/lr": ^1.3.0 - checksum: 10/64443356f9ef880cbd2ccba7990c7a05d8eb73b165ef79d6ea55a269a775954a22262c3c90988dff82a21f4081dd8236ffe2c4af7c3ea41d03f7d994bea1af93 + checksum: 10/f9b32989ab5bab1f6407b1c83c4fd3169d589cd83d2abe95bcf68dca1ce1c512b923a0087dd010f528a202f47d102ae6dec81385f6a506632f23ece1e471a3df languageName: node linkType: hard