Loki: Add the ability to prettify logql queries (#64337)

* pushed to get help of a genius

* fix: error response is not json

* feat: make request on click

* refactor: remove print statement

* refactor: remove unnecessary code

* feat: convert grafana variables to value for API request

* use the parser to interpolate and recover the original query (#64591)

* Prettify query: use the parser to interpolate and recover the original query

* Fix typo

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>

* Fix typo

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>

* fix: reverse transformation not working

---------

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
Co-authored-by: Gareth Dawson <gwdawson.work@gmail.com>

* fix: bugs created from merge

* refactor: move prettify code out of monaco editor

* fix: variables with the same value get converted back to the incorect variable

* refactor

* use consistent styling with bigquery

* fix: only allow text/plain and application/json

* fix: only make the request if the query is valid

* endpoint now returns application/json

* prettify from js

* WIP: not all cases are handles, code still needs cleaning up

* WIP

* large refactor, finished support for all pipeline expressions

* add tests for all format functions

* idk why these files changed

* add support for range aggregation expr & refactor

* add support for vector aggregation expressions

* add support for bin op expression

* add support for literal and vector expressions

* add tests and fix some bugs

* add support for distinct and decolorize

* feat: update variable replace and return

* fix: lezer throws an errow when using a range variable

* remove api implementation

* remove api implementation

* remove type assertions

* add feature flag

* update naming

* fix: bug incorrectly formatting unwrap with labelfilter

* support label replace expr

* remove duplicate code (after migration)

* add more tests

* validate query before formatting

* move tests to lezer repo

* add feature tracking

* populate feature tracking with some data

* upgrade lezer version to 0.1.7

* bump lezer to 0.1.8

* add tests

---------

Co-authored-by: Matias Chomicki <matyax@gmail.com>
Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
This commit is contained in:
Gareth Dawson
2023-07-21 13:03:56 +01:00
committed by GitHub
co-authored by Ivana Huckova Gareth Dawson Matias Chomicki
parent c84d689ce0
commit 4e42f9b619
11 changed files with 133 additions and 9 deletions
+7
View File
@@ -546,6 +546,13 @@ var (
Stage: FeatureStagePublicPreview,
Owner: grafanaBiSquad,
},
{
Name: "lokiFormatQuery",
Description: "Enables the ability to format Loki queries",
FrontendOnly: true,
Stage: FeatureStageExperimental,
Owner: grafanaObservabilityLogsSquad,
},
{
Name: "cloudWatchLogsMonacoEditor",
Description: "Enables the Monaco editor for CloudWatch Logs queries",
+1
View File
@@ -79,6 +79,7 @@ pluginsFrontendSandbox,experimental,@grafana/plugins-platform-backend,false,fals
dashboardEmbed,experimental,@grafana/grafana-as-code,false,false,false,true
frontendSandboxMonitorOnly,experimental,@grafana/plugins-platform-backend,false,false,false,true
sqlDatasourceDatabaseSelection,preview,@grafana/grafana-bi-squad,false,false,false,true
lokiFormatQuery,experimental,@grafana/observability-logs,false,false,false,true
cloudWatchLogsMonacoEditor,experimental,@grafana/aws-datasources,false,false,false,true
exploreScrollableLogsContainer,experimental,@grafana/observability-logs,false,false,false,true
recordedQueriesMulti,experimental,@grafana/observability-metrics,false,false,false,false
1 Name Stage Owner requiresDevMode RequiresLicense RequiresRestart FrontendOnly
79 dashboardEmbed experimental @grafana/grafana-as-code false false false true
80 frontendSandboxMonitorOnly experimental @grafana/plugins-platform-backend false false false true
81 sqlDatasourceDatabaseSelection preview @grafana/grafana-bi-squad false false false true
82 lokiFormatQuery experimental @grafana/observability-logs false false false true
83 cloudWatchLogsMonacoEditor experimental @grafana/aws-datasources false false false true
84 exploreScrollableLogsContainer experimental @grafana/observability-logs false false false true
85 recordedQueriesMulti experimental @grafana/observability-metrics false false false false
+4
View File
@@ -327,6 +327,10 @@ const (
// Enables previous SQL data source dataset dropdown behavior
FlagSqlDatasourceDatabaseSelection = "sqlDatasourceDatabaseSelection"
// FlagLokiFormatQuery
// Enables the ability to format Loki queries
FlagLokiFormatQuery = "lokiFormatQuery"
// FlagCloudWatchLogsMonacoEditor
// Enables the Monaco editor for CloudWatch Logs queries
FlagCloudWatchLogsMonacoEditor = "cloudWatchLogsMonacoEditor"