Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore: Use SeriesData format for loki/logs #16793

Merged
merged 14 commits into from
Apr 30, 2019
Merged

Conversation

marefr
Copy link
Member

@marefr marefr commented Apr 26, 2019

What this PR does / why we need it:
This is the first step moving towards Explore supporting logs for additional datasources than Loki. In the first step we move all the log processing from Loki into Explore.

Summary of changes:
Make explore convert logs result returned from datasources to SeriesData,
if needed, and for now convert SeriesData to LogsModel.
Loki datasource query now returns SeriesData and all
processing have been moved into explore instead.
Removed key from LogRowModel and use log row indexes as
the unique key instead.
Removed id from LogsModel since it looks like it's not in use.

Which issue(s) this PR fixes:
Closes #16287

Special notes for your reviewer:
I removed key from LogRowModel and used index of each log row as key for rendering unique keys for <LogRow /> component. To me this seems to work and makes the row model easier, but I may have missed some important aspect?

Make explore expect SeriesData to be returned as logs result
from datasources and for now convert SeriesData to LogsModel.
Loki datasource query now returns SeriesData and all
processing have been moved into explore instead.
@marefr
Copy link
Member Author

marefr commented Apr 26, 2019

@ryantxu Please have a look at the changes if you're interested to see if this maps to your vision in referenced issue. This is the first step and there will probably be a lot of other changes needed, but now we make it easier for each datasource to return log data.

Copy link
Member Author

@marefr marefr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on some of the design decision I've made.

public/app/plugins/datasource/loki/result_transformer.ts Outdated Show resolved Hide resolved
public/app/core/logs_model.ts Outdated Show resolved Hide resolved
Copy link
Member

@torkelo torkelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! So nice to see progress on this front! Just some minor comments about the overuse of callback loops (reduce/maps etc) for arrays that can have thousands of entries.

public/app/core/logs_model.ts Outdated Show resolved Hide resolved
public/app/core/logs_model.ts Outdated Show resolved Hide resolved
public/app/plugins/datasource/loki/result_transformer.ts Outdated Show resolved Hide resolved
@ryantxu
Copy link
Member

ryantxu commented Apr 27, 2019

@marefr -- this looks really good. thank you.

LogsSeriesFieldProcessor extends SeriesFieldProcessor and can validate
that series are valid for being visualized as logs. Valid log series
is now defined as having a time and a string field. Also, there now
support for checking if a series has a log level field.
The processing and sorting of logs have been refactored to hopefully
be more efficient than before.
@marefr
Copy link
Member Author

marefr commented Apr 28, 2019

@ryantxu @torkelo thanks for the feedback 👍 Have pushed some changes now. I guess the biggest change is the SeriesFieldsProcessor which I did find handy when processing a lot of rows without needing to loop thru all the fields every time to find the correct field indices.

Besides this have tried to make the log processing more efficient by using regular loops instead.

@ryantxu
Copy link
Member

ryantxu commented Apr 29, 2019

@marefr this is looking really good -- thanks.

The name on SeriesFieldsProcessor feels a bit off, and potentially in conflict with some series processing/transforming work I hope to standardize in #16756

As implemented it is a way to find field indexes based on name/type -- maybe FieldIndexFinder or IndexFieldFinder?

Copy link
Contributor

@hugohaggmark hugohaggmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work, found some very minor stuff.

public/app/core/logs_model.ts Outdated Show resolved Hide resolved
@marefr
Copy link
Member Author

marefr commented Apr 29, 2019

The name on SeriesFieldsProcessor feels a bit off, and potentially in conflict with some series processing/transforming work I hope to standardize in #16756

As implemented it is a way to find field indexes based on name/type -- maybe FieldIndexFinder or IndexFieldFinder?

@ryantxu I agree, I'm not super happy with that name. But it's not only a way for finding field indexes based on name/type - it also guesses field type for undefined/other field types and "caches" it so you don't have to iterate over all fields over and over again. And for LogsSeriesFieldProcessor it adds some extra field type processing to find log level field => the log level finding seems kind of similar to your proposed matchers.

Would it be possible/a good thing to wrap the SeriesData in some sort of class/structure, similar to SeriesFieldsProcessor, mixed with your matchers, extensions and transforms and then use this class/structure internally in Grafana instead of SeriesData?

I guess it's easier to start with renaming SeriesFieldsProcessor and get this merged and later if we merge your proposed PR and potential additional matchers/transforms we may be able to easier spot what is missing/how to properly refactor things.

@marefr
Copy link
Member Author

marefr commented Apr 29, 2019

@ryantxu I think changes in https://github.com/grafana/grafana/pull/16793/files#diff-317237f74791e054ee61a4e01ed3cb3bR58 and https://github.com/grafana/grafana/pull/16793/files#diff-c10a219f8d98d5afcc02054eb27f23a3R36 highlights the need of using some abstraction on top of SeriesData. What do you think?

@ryantxu
Copy link
Member

ryantxu commented Apr 29, 2019

@marefr -- maybe, I don't think we need more now. regardless, the details of this class should not hold up merging the PR.

@ryantxu
Copy link
Member

ryantxu commented Apr 29, 2019

it also guesses field type for undefined/other field types and "caches" it so you don't have to iterate over all fields over and over again.

FYI - this step already happens if you query with the new PanelQueryRunner right now that is only react panels, but soon will be everything. Essentially it makes sure there is a type on everything before sending it to any panel.

@marefr
Copy link
Member Author

marefr commented Apr 29, 2019

it also guesses field type for undefined/other field types and "caches" it so you don't have to iterate over all fields over and over again.

FYI - this step already happens if you query with the new PanelQueryRunner right now that is only react panels, but soon will be everything. Essentially it makes sure there is a type on everything before sending it to any panel.

I totally see the win and simplicity of using this. Next step for me in explore is to refractor how queries are executed and then I think it will make sense to use the same, guessFieldTypes(toSeriesData(...)), and later on add some additional field processing specific for logs. Then the SeriesDataProcessor may not be needed or it will be just a FieldIndexFinder or whatever we decide to call it. I'll give this a try tomorrow before merging.

@ryantxu
Copy link
Member

ryantxu commented Apr 30, 2019

If you get ambitions and subscribe to the results, you may get streaming to work for "free" -- see:
#16815

Renames SeriesFieldsProcessor to FieldCache which makes it explicit to only be used for
lookup of fields by type or name.
Removes LogsSeriesFieldProcessor and postpone finding log level fields to later.
@marefr
Copy link
Member Author

marefr commented Apr 30, 2019

@ryantxu decided to rename SeriesFieldsProcessor to FieldCache and remove field type processing from that one. Also removed guessing of log level for now and postpone that one to later since Loki is the only (official) datasource supporting logs in Explore so far and I want to get this merged.

@marefr marefr merged commit fe20dde into master Apr 30, 2019
@marefr marefr deleted the 16287_loki_series_data branch April 30, 2019 16:21
@marefr marefr added this to the 6.2-beta1 milestone Apr 30, 2019
@ryantxu
Copy link
Member

ryantxu commented Apr 30, 2019

@marefr -- looks great. this is a huge improvement.

@marefr
Copy link
Member Author

marefr commented Apr 30, 2019

Thanks for great feedback @ryantxu 👍 Really love how the new SeriesData format simplifies a lot of stuff! Next up is #16823 and next after that simplifying query execution in explore so that SeriesData is used for all both metrics and logs.

@davkal
Copy link
Contributor

davkal commented Apr 30, 2019

@marefr using indexes as React keys is rarely advisable. The key tells react what to unmount. so now when you look at a loki stream (seeing all results) and then decide to add a search term that would match some of the later results (e.g., a term from row 10) and then run the query, the non-matched results still show. This happens because in the filtered set the first indexes are still present, so react thinks it won't have to unmount those rows.

Update: can't repro index-as-keys issues anymore.

ryantxu added a commit to ryantxu/grafana that referenced this pull request Apr 30, 2019
…MetricPanelCtrl

* grafana/master:
  Explore: Use SeriesData format for loki/logs (grafana#16793)
  Refactor: move NavModel to @grafana/ui (grafana#16813)
  Auth: Enable retries and transaction for some db calls for auth tokens  (grafana#16785)
  Provisioning: Show file path of provisioning file in save/delete dialogs (grafana#16706)
  Add tracing headers for prometheus datasource (grafana#16724)
  Config: Fixes bug where timeouts for alerting was not parsed correctly (grafana#16784)
  build: removes gopkg files from dev docker file (grafana#16817)
  Provisioning: Trying to fix failing test (grafana#16800)
  Table: React table fix rotate support in storybook (grafana#16816)
  TestData: add log level in dummy message (grafana#16815)
  removes gopkg.lock from root folder
  Explore: Support user timezone (grafana#16469)
  Plugins: rename vizPlugin to panelPlugin (grafana#16802)
  Plugins: move app/feature/plugin properties into PluginMeta (grafana#16809)
  Plugins: move PanelPluginMeta to grafana/ui (grafana#16804)
  Plugins: move datasource specific meta out of the main meta type (grafana#16803)
  updates changelog for 6.1.6
  Fix: Fetch histogram series from other api route (grafana#16768)
  phantomjs: set web-security to true
  Chore: Lowered implicit anys limit to 5668
ryantxu added a commit to ryantxu/grafana that referenced this pull request Apr 30, 2019
* grafana/master:
  Explore: Use SeriesData format for loki/logs (grafana#16793)
  Refactor: move NavModel to @grafana/ui (grafana#16813)
  Auth: Enable retries and transaction for some db calls for auth tokens  (grafana#16785)
  Provisioning: Show file path of provisioning file in save/delete dialogs (grafana#16706)
  Add tracing headers for prometheus datasource (grafana#16724)
  Config: Fixes bug where timeouts for alerting was not parsed correctly (grafana#16784)
  build: removes gopkg files from dev docker file (grafana#16817)
  Provisioning: Trying to fix failing test (grafana#16800)
  Table: React table fix rotate support in storybook (grafana#16816)
  TestData: add log level in dummy message (grafana#16815)
  removes gopkg.lock from root folder
  Explore: Support user timezone (grafana#16469)
  Plugins: rename vizPlugin to panelPlugin (grafana#16802)
  Plugins: move app/feature/plugin properties into PluginMeta (grafana#16809)
  Plugins: move PanelPluginMeta to grafana/ui (grafana#16804)
  Plugins: move datasource specific meta out of the main meta type (grafana#16803)
  updates changelog for 6.1.6
  Fix: Fetch histogram series from other api route (grafana#16768)
  phantomjs: set web-security to true
  Chore: Lowered implicit anys limit to 5668
ryantxu added a commit to ryantxu/grafana that referenced this pull request May 2, 2019
* grafana/master:
  FormLabel: allow any rather than just a string for tooltip (grafana#16841)
  prometheus: fix regression after adding support for tracing headers (grafana#16829)
  area/circleci: Speed up circleci build process for branches and pr (grafana#16778)
  DataProxy: Restore Set-Cookie header after proxy request (grafana#16838)
  docs: clarify page parameter version support for folder/dashboard search (grafana#16836)
  Chore: revise some of the gosec rules (grafana#16713)
  Refactor: consistant plugin/meta usage (grafana#16834)
  Explore: Use SeriesData format for loki/logs (grafana#16793)
  Refactor: move NavModel to @grafana/ui (grafana#16813)
ryantxu added a commit to ryantxu/grafana that referenced this pull request May 2, 2019
* grafana/master: (27 commits)
  FormLabel: allow any rather than just a string for tooltip (grafana#16841)
  prometheus: fix regression after adding support for tracing headers (grafana#16829)
  area/circleci: Speed up circleci build process for branches and pr (grafana#16778)
  DataProxy: Restore Set-Cookie header after proxy request (grafana#16838)
  docs: clarify page parameter version support for folder/dashboard search (grafana#16836)
  Chore: revise some of the gosec rules (grafana#16713)
  Refactor: consistant plugin/meta usage (grafana#16834)
  Explore: Use SeriesData format for loki/logs (grafana#16793)
  Refactor: move NavModel to @grafana/ui (grafana#16813)
  Auth: Enable retries and transaction for some db calls for auth tokens  (grafana#16785)
  Provisioning: Show file path of provisioning file in save/delete dialogs (grafana#16706)
  Add tracing headers for prometheus datasource (grafana#16724)
  Config: Fixes bug where timeouts for alerting was not parsed correctly (grafana#16784)
  build: removes gopkg files from dev docker file (grafana#16817)
  Provisioning: Trying to fix failing test (grafana#16800)
  Table: React table fix rotate support in storybook (grafana#16816)
  TestData: add log level in dummy message (grafana#16815)
  removes gopkg.lock from root folder
  Explore: Support user timezone (grafana#16469)
  Plugins: rename vizPlugin to panelPlugin (grafana#16802)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use SeriesData format for loki/logging
5 participants