Commit Graph

247 Commits

Author SHA1 Message Date
Gareth Dawson
4e42f9b619
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>
2023-07-21 13:03:56 +01:00
Ashley Harrison
9852b24d61
Chore: Upgrade prettier to v3 (#71764)
* Update dependency prettier to v3 (#71586)

* Update dependency prettier to v3

* run prettier

* ignore prettier update in legacy select scss

* update command line arg

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>

* unplug prettier

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-17 15:58:22 +01:00
Ashley Harrison
5ca382c88a
Revert "Update dependency prettier to v3 (#71586)" (#71755)
This reverts commit 2e8cd1c021.
2023-07-17 14:46:15 +01:00
renovate[bot]
2e8cd1c021
Update dependency prettier to v3 (#71586)
* Update dependency prettier to v3

* run prettier

* ignore prettier update in legacy select scss

* update command line arg

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
2023-07-17 09:19:27 +01:00
Joey
6615418df8
Tracing: Show next/prev buttons when span filters are collapsed (#71025)
* Show next/prev buttons when span filters are collapsed

* Update test

* Remove imports

* Update lint

* Prettier

* Update test

* Update styling
2023-07-12 07:52:07 +01:00
Gareth Dawson
0072b2cca4
Loki: Use better query validation before requesting stats (#70800)
* fix: use correct validate funtion

* rename isValidQuery to isQueryWithError

* lets pretend i didnt break things again

* Loki validation: add missing comments and refactor validation function

* isValidQuery: add unit test

* Loki datasource: add tests for getQueryStats

* Remove isValidQuery function

* UnwrapParamEditor: interpolate query before testing validity

* Stats: trim queries when evaluating change

---------

Co-authored-by: Matias Chomicki <matyax@gmail.com>
2023-06-29 16:50:17 +01:00
Sven Grossmann
d7337e4f9c
Loki: Preserve pipeline stages in context query (#70472)
* add pipeline stages to context query

* add ui

* improve `Postion`

* add `processPipelineStagesToExpr` to logcontextprovider

* add ui toggle

* fix lokicontextui tests

* remove import

* contextually hide the toggle

* Update `SHOULD_INCLUDE_PIPELINE_OPERATIONS` name

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

* add setIncludePipelineOperations to false in revert

* add prepareExpression method

* remove unused method

* fix test and add `runContextQuery`

* set correct revert state

* let let be const

* remove argument

---------

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
2023-06-22 17:34:43 +02:00
Matias Chomicki
a489135825
Loki Query Utils: Extract and refactor common functionality (#70185)
* Query utils: refactor isQueryPipelineErrorFiltering and getLogQueryFromMetricsQuery

* Query utils: refactor isQueryWithRangeVariable and getHighlighterExpressionsFromQuery

* Get parser: return log expression even if no pipelineExpr is present

* Update tests
2023-06-21 11:59:50 +03:00
Ivana Huckova
60f6538bad
Loki: Use getNormalizedLokiQuery to get queryType (#70237)
* Loki: Use getNormalizedLokiQuery to get queryType

* Simplify

* Remove unused import

* Refactor, improve and add tests

* Update
2023-06-20 16:27:32 +02:00
Gábor Farkas
271cdb4baa
loki: rename experimental feature flag (#70306) 2023-06-19 10:03:51 +00:00
Sven Grossmann
25b65cce25
Log Context: Fix component height to fit revert-button (#70159)
fix item height
2023-06-15 15:48:24 +02:00
Ivana Huckova
0245ef63ba
Loki: Fix showing of correct line limit in options (#69572)
* Loki: Fix showing of line limit

* Refactor tests to not use id
2023-06-08 14:40:39 +02:00
Ivana Huckova
8322b353f5
Loki: Make stream selector input in variables editor larger (#69729)
* Loki: Make strem selector input in variables editor larger

* Remove 75%
2023-06-07 18:56:35 +03:00
Ivana Huckova
14d2f371a4
Loki: Fix including of template variables in variable query editor (#69698) 2023-06-07 15:38:45 +02:00
Ivana Huckova
21021502b5
Loki: Remove unused datasource prop from LokiQueryBuilderOptions (#69445)
Loki: Remove unused props from LokiQueryBuilderOptions
2023-06-02 13:26:20 +02:00
Ivana Huckova
06003c98c8
Loki: Add predefined operations functionality behind feature flag (#69379)
* Add feature toggle for lokiPredefinedOperations

* Add config editor for predefined operations

* Add predefined patterns to editor

* Update content in tooltip

* Update public/app/plugins/datasource/loki/configuration/QuerySettings.tsx

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>

* Update public/app/plugins/datasource/loki/components/LokiQueryEditor.tsx

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>

* Add experimental badge

---------

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>
2023-06-02 12:52:36 +02:00
Ivana Huckova
3e46720a96
Loki: Fix creating correct context query when preserved labels used (#69252) 2023-05-30 17:12:40 +02:00
Matias Chomicki
9abf8140c7
Loki: Add support for distinct operation in autocomplete and query builder (#69003)
* Loki Autocomplete: add support for suggesting distinct

* Loki query builder: add distinct as format operation

* Remove unused import

* Loki visual query: add support to parse distinct filters

* Query builder: use label param editor for distinct

* Loki Autocomplete: Improve distinct label suggestions

* Query Builder: improve distinct parsing

* Fix tests

* Update tests
2023-05-25 14:22:16 +02:00
Ivana Huckova
ca44164bea
Loki: Implement decolorize logql operation (#68972)
* Loki: Implement decolorize operation

* Fix tests
2023-05-24 15:23:54 +02:00
Ivana Huckova
7c7e021ccd
Loki: Preserve pre-selected labels in the log context UI (#68700)
* WIP

* Refactor and add tests

* Update
2023-05-22 10:41:35 +02:00
Ivana Huckova
1462ae91da
Loki: Add functionality to revert to initial query in log context (#68484)
* Loki: Add functionality to revert to initial query

* Add tests and fix button in button

* Use usereven instead of fireEvent

* Shortern onClick

* Add feature tracking

* Use testid instead of title

* Always show revert button

* Remove unused imports
2023-05-16 18:58:25 +02:00
Sven Grossmann
a3d31e0420
Loki: Fix margin in Log Context (#67299)
* remove top margin

* also fix for parsed labels
2023-04-27 12:44:16 +02:00
Ivana Huckova
106eceab55
Loki: Remove experimental badge for context ui (#67219)
* Loki: Remove experimental badge

* Remove unused styles
2023-04-26 11:03:07 +02:00
Ivana Huckova
67ca91ece3
Loki: Fix incorrect evaluation of real and extracted labels in context (#67112)
* Loki: Fix incorrect evaluation of real/extracted labels in context

* Add tests

* Improve caching and add more tests

* Use mockResolvedValue

* Flip logic for getInitContextFiltersFromLabels

* Update to logic to use fetchSeriesLabels for queries with more than 1 parser
2023-04-24 17:36:30 +02:00
Ivana Huckova
24c754334f
Loki: Update content for log context ui (#66978)
* Loki: Update content for context ui

* Update

* Update public/app/plugins/datasource/loki/components/LokiContextUi.tsx

Co-authored-by: J Stickler <julie.stickler@grafana.com>

* Update public/app/plugins/datasource/loki/components/LokiContextUi.tsx

Co-authored-by: J Stickler <julie.stickler@grafana.com>

* Update public/app/plugins/datasource/loki/components/LokiContextUi.tsx

Co-authored-by: J Stickler <julie.stickler@grafana.com>

* Update public/app/plugins/datasource/loki/components/LokiContextUi.tsx

Co-authored-by: J Stickler <julie.stickler@grafana.com>

---------

Co-authored-by: J Stickler <julie.stickler@grafana.com>
2023-04-22 14:07:44 +02:00
Ivana Huckova
3c0e896282
Loki: Change default state for log context ui to toggled (#67032) 2023-04-21 11:51:02 +02:00
Sven Grossmann
74d3d3cf4a
Log Context: Improve loading indicator (#66979)
* remove loadingplaceholder

* lint
2023-04-20 18:22:09 +03:00
Ivana Huckova
c96b704af3
Loki: Update log context UI (#66848)
* Loki: Update log context UI

* Update copy
2023-04-19 18:02:37 +02:00
Gareth Dawson
13c5aadd5d
Loki: Don't request stats with invalid query (#65287)
* fix: dont call endpoint if invalid query

* fix: use latest lezer-logql

* refactor: use null instead of undefined

* test: returns null when query is invalid

* update
2023-04-18 15:52:37 +01:00
Ivana Huckova
f612a72f96
Loki: Update log context UI (#66730)
* fix logrowcontext scrolling behavior

* Loki: Update loki context ui menu

* Update

* Add test, update

* Use escapeLabelValueInSelector when displaying labels

* Update test for new appliedContextFilters

---------

Co-authored-by: Sven Grossmann <svennergr@gmail.com>
2023-04-18 15:59:22 +02:00
Ivana Huckova
a31104b107
Loki: Refactor logic for using context filters (#66382)
* Loki: Change logic for using context filters

* Dont add parser and parsed labels if multiple

* Update public/app/plugins/datasource/loki/LogContextProvider.ts

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>

* Update public/app/plugins/datasource/loki/LogContextProvider.ts

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>

* Update

* Rename variable

---------

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>
2023-04-14 13:44:02 +02:00
Matias Chomicki
46742f6d96
Loki Variable Query Editor: Fix bug when the query is updated (#66509)
* Variable Query Editor: Remove options override in effect

* Add regression test
2023-04-13 23:30:27 +02:00
Matias Chomicki
2a12283da8
Loki Autocomplete: Update Lezer LogQL and update labels autocomplete after the upgrade (#66289)
* Dependencies: update lezer

* Loki Autocomplete: Add support for selectors containing error nodes

* Update tests
2023-04-13 12:11:14 +00:00
Ashley Harrison
1261345b81
Chore: Upgrade to react 18 (#64428)
* update react 18 related deps

* fix some types

* make sure we're on react-router-dom >= 5.3.3

* Use new root API

* Remove StrictMode for now - react 18 double rendering causes issues

* fix + ignore some @grafana/ui types

* fix some more types

* use renderHook from @testing-library/react in almost all cases

* fix storybook types

* rewrite useDashboardSave to not use useEffect

* make props optional

* only render if props are provided

* add correct type for useCallback

* make resourcepicker tests more robust

* fix ModalManager rendering

* fix some more unit tests

* store the click coordinates in a ref as setState is NOT synchronous

* fix remaining e2e tests

* rewrite dashboardpage tests to avoid act warnings

* undo lint ignores

* fix ExpanderCell types

* set SymbolCell type correctly

* fix QueryAndExpressionsStep

* looks like the types were actually wrong instead :D

* undo this for now...

* remove spinner waits

* more robust tests

* rewrite errorboundary test to not explicitly count the number of renders

* make urlParam expect async

* increase timeout in waitFor

* revert ExplorePage test changes

* Update public/app/features/dashboard/containers/DashboardPage.test.tsx

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* Update public/app/features/dashboard/containers/PublicDashboardPage.test.tsx

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* Update public/app/features/dashboard/containers/PublicDashboardPage.test.tsx

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* Update public/app/features/dashboard/containers/PublicDashboardPage.test.tsx

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* skip fakeTimer test, ignore table types for now + other review comments

* update package peerDeps

* small tweak to resourcepicker test

* update lockfile...

* increase timeout in sharepublicdashboard tests

* ensure ExplorePaneContainer passes correct queries to initializeExplore

* fix LokiContextUI test

* fix unit tests

* make importDashboard flow more consistent

* wait for dashboard name before continuing

* more test fixes

* readd dashboard name to variable e2e tests

* wait for switches to be enabled before clicking

* fix modal rendering

* don't use @testing-library/dom directly

* quick fix for rendering of panels in firefox

* make PromQueryField test more robust

* don't wait for chartData - in react 18 this can happen before the wait code even gets executed

---------

Co-authored-by: kay delaney <kay@grafana.com>
Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
2023-04-11 10:51:54 +01:00
Matias Chomicki
58287c2df2
Loki Query Editor: Increase autocomplete suggestions window with to 50% (#66041)
Loki Monaco Editor: Increase autocomplete min width to 50%
2023-04-05 16:46:44 +00:00
Sven Grossmann
d790cb1c09
Loki: Add unpack query builder hint (#65608)
* add unpack hint

* use `hasOwnProperty`

* add unpack completion to monaco

* adjust test name

* fix tests

* fix tests
2023-03-30 15:18:02 +02:00
Sven Grossmann
b01194f81e
Loki: Fix autocomplete situations with multiple escaped quotes (#65520)
fix situations with multiple quotes
2023-03-29 15:00:42 +02:00
Torkel Ödegaard
395890c357
Prometheus/Loki: Run query explicitly instead of onblur in panel edit (#64815)
* Prometheus: Run query explicitly instead of onblur in panel edit, and highlight Run qqueries when query changed

* Update loki to do the same

* Cleanup unused prop

* Remove test
2023-03-21 07:55:34 +01:00
Sven Grossmann
7a17a8f02d
QueryStats: Fix comparison of relative and absolute timeranges (#65035)
* add missing fix of relative timeranges

* add doc
2023-03-20 11:35:03 +01:00
Sven Grossmann
6ae373b8c7
QueryStats: Fix comparison of timeranges (#65025)
* fix timerange comparison

* remove import
2023-03-20 10:04:41 +01:00
Gareth Dawson
c16280a4e8
Loki: Improve the display of loki query stats (#63623)
* fix: refresh query stats on timerange change

* partial fix: request stats update on type in code mode

* complete fix: request stats update on type in code mode

* fix: update failing tests and props

* refactor: pass only essential query string to getQueryStats

* refactor: remove unused variables

* test: fix datasource.getTimeRange is not a function

* refactor: use lodash debounce instead of setTimeout

* refactor: add suggestions from code review

* test: shouldUpdateStats and makeStatsRequest

* refactor: use more appropriate variable names

* refactor: make setQueryStats required instead of optional

* refactor: move setQueryStats into LokiQueryEditor

* fix: add missing props to LokiQueryField

* revert changes

* refactor: use inversion of control to request stats

* refactor: remove unnecessary code
2023-03-16 18:50:42 +00:00
Ivana Huckova
a996344e14
Loki: Add autocomplete updates for improved suggestions (#64744)
* Loki: Add autocomplete updates for improved suggestions

* Use trimEnd for trailing pipeline

* Update public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/completions.ts

Co-authored-by: Matias Chomicki <matyax@gmail.com>

* Fix unused imports

---------

Co-authored-by: Matias Chomicki <matyax@gmail.com>
2023-03-15 14:26:46 +01:00
Ashley Harrison
e0e6165f70
Chore: adjust more unit tests to work with react 18 (#64759)
adjust unit tests to work with react 18
2023-03-15 10:12:13 +00:00
Ashley Harrison
85e5326040
Chore: Adjust unit tests so they work with react 18 (#64698)
tweak unit tests so they work with react 18
2023-03-14 17:24:04 +00:00
Ryan McKinley
d710507bc5
Chore: Avoid explicit React.FC<Props> when possible (#64722) 2023-03-14 16:38:21 +02:00
Sven Grossmann
5db0d14606
LokiContextUi: Add loading indicator (#64167)
add loading indicator to LokiContextUi
2023-03-06 17:25:04 +01:00
李国忠
9521b0d2d2
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>
2023-03-03 10:09:34 +01:00
Ashley Harrison
4a2695349d
Chore: more ts test fixes (#63438)
* replace anys in tests

* more test fixes

* clean up any's in tests
2023-02-23 10:07:44 +00:00
Sven Grossmann
00edc1c6b1
Loki Context UI: Do not disable last label (#62866)
* improved text

* prevent all labels removed

* use `structuredClone` instead of lodash

* update test

* get `structuredClone` in test?

* fix using structuredClone
2023-02-10 14:23:17 +01:00
Gareth Dawson
ac942d5e72
Loki: Add placeholder to the loki query editor (#62773)
* fix: add placeholder to loki query editor

* fix: use original placeholder

* refactor: extract set placeholder into seperate function

* fix: use correct monaco types

* revert: unwanted change from merge
2023-02-06 15:38:19 +00:00