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

Index pattern field class refactor #73180

Merged
merged 20 commits into from
Aug 10, 2020

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented Jul 24, 2020

Summary

  • Better distinction and relationship between IndexPatternField and its spec
  • IndexPatternField class is no longer defined via object mutation
  • Reduction of dependencies
  • UI code moved into Index Pattern class (will be removed in next ticket)
  • IndexPattern field list was previously composed of IndexPatternFields or specs, now only IndexPatternFields
  • IndexPattern field list was previously redefined when loading fields, now only its contents are replaced.

Checklist

For maintainers

@elastic elastic deleted a comment from kibanamachine Jul 24, 2020
@elastic elastic deleted a comment from kibanamachine Jul 24, 2020
@elastic elastic deleted a comment from kibanamachine Jul 24, 2020
@mattkime mattkime changed the title first pass at new field class Index pattern field class refactor Aug 4, 2020
@elastic elastic deleted a comment from kibanamachine Aug 5, 2020
@mattkime mattkime added v8.0.0 v7.10.0 Team:AppArch Feature:Data Views Data Views code and UI - index patterns before 8.0 release_note:skip Skip the PR/issue when compiling release notes labels Aug 5, 2020
@mattkime mattkime added this to In progress in kibana-app-arch via automation Aug 5, 2020
@mattkime mattkime marked this pull request as ready for review August 5, 2020 21:58
@mattkime mattkime requested a review from a team August 5, 2020 21:58
@mattkime mattkime requested a review from a team as a code owner August 5, 2020 21:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@mattkime mattkime moved this from In progress to Review in progress in kibana-app-arch Aug 5, 2020
Copy link
Contributor

@streamich streamich left a comment

Choose a reason for hiding this comment

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

There seems to be a functional test failing related to this change. Other than that LGTM, checked on Mac/Ubuntu Chrome, all seems to be working.

this.groups.get(field.type)!.set(field.name, field);
};
private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name);
export class FieldList extends Array<IndexPatternField> implements IIndexPatternFieldList {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit concerned about extending the native Array here. Array has many public methods, are we sure we want to expose all of those as part of FieldList. If users use those, they can basically mutate the FieldList while by-passing the business logic of FieldList.

Maybe we could use composition instead?

class FieldList {
  private data: Array<IndexPatternField> = [];
}

Copy link
Member

Choose a reason for hiding this comment

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

++

Copy link
Contributor Author

@mattkime mattkime Aug 6, 2020

Choose a reason for hiding this comment

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

100% agree, but I'm avoiding changing the class interfaces in this PR. Will address in a follow up - #68020


specs.map((field) => this.add(field));
}
getByName = (name: IndexPatternField['name']) => this.byName.get(name);
Copy link
Contributor

Choose a reason for hiding this comment

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

All these could have readonly modifier.

Suggested change
getByName = (name: IndexPatternField['name']) => this.byName.get(name);
readonly getByName = (name: IndexPatternField['name']) => this.byName.get(name);

or

Suggested change
getByName = (name: IndexPatternField['name']) => this.byName.get(name);
public readonly getByName = (name: IndexPatternField['name']) => this.byName.get(name);

displayName: string,
onNotification: OnNotification
) {
this.indexPattern = indexPattern;
Copy link
Member

Choose a reason for hiding this comment

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

i don't like the fact that we need to pass indexPattern in just to be able to get to formatter, could we:

  • remove format function and have consumers always use indexPattern.getFormatterForField(field) ?
  • or actually push that to the service, so we would do something like indexPatterns.getFormatter(indexPattern, field) and both IndexPattern and IndexPatternField get rid of that dependency (and can be static)

i am fine with doing this later, i am just wondering how reasonable you think that is ?

Copy link
Contributor Author

@mattkime mattkime Aug 6, 2020

Choose a reason for hiding this comment

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

100% This PR keeps the class interfaces largely the same. My next PR will address this -#71909

@walterra
Copy link
Contributor

walterra commented Aug 6, 2020

I investigated the failing functional test in the transform plugin.

We use the Kibana index pattern field information to determine whether that field is suitable to be used for a preview visualization. Among other things we check against the aggregatable attribute.

On master, for the fields of the kibana e-commerce sample dataset we get the following:

name: category 	type: string 	aggregatable: false
name: currency 	type: string 	aggregatable: true
name: customer_birth_date 	type: date 	aggregatable: true
name: customer_first_name 	type: string 	aggregatable: false

When running this PR, we get:

name: category 	type: string 	aggregatable: undefined
name: currency 	type: string 	aggregatable: true
name: customer_birth_date 	type: date 	aggregatable: true
name: customer_first_name 	type: string 	aggregatable: undefined

Since in our code we do a strict equal check (field?.aggregatable === false) the code no longer works as expected.

The code causing this can be found here: https://github.com/elastic/kibana/blob/master/x-pack/plugins/ml/public/application/components/data_grid/common.ts#L157

Hope this helps, let me know if I can help out with more investigations.

@mattkime
Copy link
Contributor Author

mattkime commented Aug 6, 2020

@walterra

Thanks! Extremely helpful!

@elastic elastic deleted a comment from kibanamachine Aug 6, 2020
Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

code LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
data 537 -1 538

async chunks size

id value diff baseline
discover 431.6KB +1.3KB 430.3KB
indexPatternManagement 698.1KB +191.0B 697.9KB
total +1.5KB

page load bundle size

id value diff baseline
data 1.4MB +609.0B 1.4MB
indexPatternManagement 133.3KB +6.0B 133.3KB
total +615.0B

History

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

@mattkime
Copy link
Contributor Author

mattkime commented Aug 9, 2020

@elasticmachine merge upstream

@mattkime mattkime merged commit cccf15a into elastic:master Aug 10, 2020
kibana-app-arch automation moved this from Review in progress to Done in current release Aug 10, 2020
mattkime added a commit to mattkime/kibana that referenced this pull request Aug 10, 2020
- Better distinction and relationship between IndexPatternField and its spec
- IndexPatternField class is no longer defined via object mutation
- Reduction of dependencies
- UI code moved into Index Pattern class (will be removed in next ticket)
- IndexPattern field list was previously composed of IndexPatternFields or specs, now only IndexPatternFields
- IndexPattern field list was previously redefined when loading fields, now only its contents are replaced.
# Conflicts:
#	docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md
#	src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts
#	src/plugins/data/public/index.ts
mattkime added a commit that referenced this pull request Aug 10, 2020
- Better distinction and relationship between IndexPatternField and its spec
- IndexPatternField class is no longer defined via object mutation
- Reduction of dependencies
- UI code moved into Index Pattern class (will be removed in next ticket)
- IndexPattern field list was previously composed of IndexPatternFields or specs, now only IndexPatternFields
- IndexPattern field list was previously redefined when loading fields, now only its contents are replaced.
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 11, 2020
…-task

* master: (42 commits)
  Allow any hostname for chromium proxy bypass (elastic#74693)
  [ML] ML on Kibana Management: Add ability to pass a group ID filter to job management page (elastic#74533)
  [Metrics UI] Fix No Data preview pluralization (elastic#74399)
  [Bug][Security_Solution][Telemetry] Capitalize S in macOS (elastic#74688)
  Remove karma tests  from legacy maps (elastic#74668)
  [Ingest Manager] stop creating events-* index pattern and placeholder index (elastic#74683)
  [Enterprise Search] Update the browser/document title on plugin navigation (elastic#74392)
  [visualizations] Add i18n translation for 'No results found' (elastic#74619)
  [maps] convert vector style properties to TS (elastic#74553)
  bump geckodriver binary to 0.27 (elastic#74638)
  fix: update apm agents to catch abort requests (elastic#74658)
  [Security Solution] Resolver children pagination (elastic#74603)
  add memoryStatus to df analytics page and analytics table in management (elastic#74570)
  [Ingest Manager] Allow prerelease in package version (elastic#74452)
  [App Arch]: remove legacy karma tests (elastic#74599)
  [i18n] revert reverted changes (elastic#74633)
  [Lens] Clear out all attribute properties before updating (elastic#74483)
  [Uptime] Fix full reloads while navigating to alert/ml (elastic#73796)
  Index pattern field class refactor (elastic#73180)
  [ML] Functional tests - stabilize DFA job type check (elastic#74631)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Data Views Data Views code and UI - index patterns before 8.0 release_note:skip Skip the PR/issue when compiling release notes v7.10.0 v8.0.0
Projects
kibana-app-arch
  
Done in current release
Development

Successfully merging this pull request may close these issues.

None yet

6 participants