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

[Lens] Use index pattern service instead saved object client #74654

Merged
merged 17 commits into from
Aug 21, 2020

Conversation

mbondyra
Copy link
Contributor

@mbondyra mbondyra commented Aug 10, 2020

Summary

Uses indexPatternsService provided by the data plugin to fetch index patterns instead of saved object client.
Fixes #73306
Uses displayName field property as labels instead of raw field.name.

Field displayName changes

  1. Filtering the fields in field list should (?) be possible by field.name or field.displayName:

Screenshot 2020-08-14 at 10 28 50

  1. All the places where displayName replaces field.name:

Screenshot 2020-08-14 at 10 27 16

Screenshot 2020-08-14 at 10 23 38

To test it, you can add this snippet to 58. line of x-pack/plugins/lens/public/indexpattern_datasource/loader.ts:

        .map((field, i) => ({
          ...field,
          aggregatable: field.aggregatable,
          name: field.name,
          searchable: field.searchable,
          type: field.type,
          displayName: 'customName' + i,
        }));

Checklist

@mbondyra mbondyra added Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v8.0.0 labels Aug 10, 2020
@mbondyra mbondyra force-pushed the lens/indexPatternFromIPService branch from 18dc6b6 to 78e42e9 Compare August 13, 2020 11:58
@elastic elastic deleted a comment from kibanamachine Aug 13, 2020
@mbondyra mbondyra marked this pull request as ready for review August 14, 2020 10:32
@mbondyra mbondyra requested a review from a team August 14, 2020 10:32
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

I tested this in Chrome and it works great with regular index patterns, but I can't use it with rollups at all. I know there are some problems in master as well, but it seems like on this PR the fields are not shown (not sure why)

master:
Screenshot 2020-08-17 at 18 40 37

this PR:
Screenshot 2020-08-17 at 18 40 44

It's probably related to the IndexPatternField instance which has some methods along with the regular JSON properties. Maybe we can get around it by not spreading the field in here https:/elastic/kibana/pull/74654/files#diff-2edf5b6f299eb91ac9ef5fd386eef219R72 but specifically copying over the values we actually use. Not sure though, maybe there's a big reason to use the actual IndexPatternField stuff I'm missing.

Also, I know this wasn't introduced by this PR, but the IndexPattern objects we use in Lens aren't actually IndexPatterns. It's basically this imprecise cast: https:/elastic/kibana/pull/74654/files#diff-2edf5b6f299eb91ac9ef5fd386eef219R80 If it's a lot of work, please omit, but if it's easy to add, we could introduce our own type here which is actually correct (maybe just by letting type inference do it's job and using the return value of the loader).

@mbondyra
Copy link
Contributor Author

mbondyra commented Aug 18, 2020

@flash1293 thanks for checking - I tested the rollup indices before marking this PR as ready, but I apparently had a snippet added in my code for testing displayName and it had hidden the bug. Sorry about it!
My last commit does the typing a bit better - let me know what you think about it :)

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Tested in Chrome and Firefox and works fine for me - dotted field names are used correctly.

Search in the data panel works fine for both ways of writing the field name which is very helpful I think - in the field dropdown in the dimension popover however on the display name is considered. We can't change this for now because EUI is controlling the matcher (elastic/eui#2199). However I think the behavior is fine for now.

Added a typing nit, but this looks good to me overall

const indexPatterns = await Promise.all(missingIds.map((id) => indexPatternsService.get(id)));
const indexPatternsObject = indexPatterns.reduce(
(acc, indexPattern) => {
const newFields = (indexPattern.fields as IndexPatternField[])
Copy link
Contributor

Choose a reason for hiding this comment

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

This cast is not precise and can be omitted

aggregatable: field.aggregatable,
scripted: field.scripted,
searchable: field.searchable,
aggregationRestrictions: field.aggregationRestrictions,
Copy link
Contributor

Choose a reason for hiding this comment

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

If you remove the case from above, this line will error because the field of an IndexPattern instance doesn't have aggregationRestrictions. You can simply set this to an empty object, because to logic below will map the restrictions into the fields.

…exPatternFromIPService

# Conflicts:
#	x-pack/plugins/lens/public/indexpattern_datasource/field_item.tsx
@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Just tested combined with #70039, LGTM
Bildschirmfoto 2020-08-21 um 11 12 45

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

page load bundle size

id value diff baseline
lens 853.7KB -48.0B 853.7KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@mbondyra mbondyra merged commit 23f46c9 into elastic:master Aug 21, 2020
@mbondyra mbondyra deleted the lens/indexPatternFromIPService branch August 21, 2020 09:35
mbondyra added a commit to mbondyra/kibana that referenced this pull request Aug 21, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 21, 2020
* master: (71 commits)
  [Lens] Show 'No data for this field' for empty field in accordion (elastic#73772)
  Skip failing lens test
  Configure ScopedHistory consistenty regardless of URL used to mount app (elastic#75074)
  Fix returned payload by "search" usage collector (elastic#75340)
  [Security Solution] Fix missing key error (elastic#75576)
  Upgrade EUI to v27.4.1 (elastic#75240)
  Update datasets UI copy to data streams (elastic#75618)
  [Lens] Register saved object references (elastic#74523)
  [DOCS] Update links to Beats documentation (elastic#70380)
  [Enterprise Search] Convert our `public_url` route to `config_data` and collect initialAppData (elastic#75616)
  [Usage Collection Schemas] Remove Legacy entries (elastic#75652)
  [Dashboard First] Lens Originating App Breadcrumb (elastic#75470)
  Improve login UI error message. (elastic#75642)
  [Security Solution] modify circular deps checker to output images of circular deps graphs (elastic#75579)
  [Data Telemetry] Add index pattern to identify "meow" attacks (elastic#75163)
  Migrate CSP usage collector to `kibana_usage_collection` plugin (elastic#75536)
  [Console] Get ES Config from core (elastic#75406)
  [Uptime] Add delay in telemetry test (elastic#75162)
  [Lens] Use index pattern service instead saved object client (elastic#74654)
  Embeddable input (elastic#73033)
  ...
thomasneirynck pushed a commit to thomasneirynck/kibana that referenced this pull request Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Use index pattern service instead saved object client
5 participants