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 - refactor constructor #77791

Merged
merged 72 commits into from
Sep 23, 2020

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented Sep 17, 2020

Summary

The index pattern factory and crud methods have been refactored -

Create new indexPattern instance (unsaved) -
indexPatternService.make() => indexPatternService.create(indexPatternSpec, skipFetchFields)

Save new index pattern -
indexPattern.create() => indexPatternService.createSavedObject(indexPattern)

Setting the default index pattern is done as part of indexPatternService.createSavedObject but can also be called individually-
uiSettings.set('defaultIndex', id) => indexPatternService.setDefault(indexPatternId, force)

Update index pattern -
indexPattern.save() => indexPatternService.updateSavedObject(indexPattern)

Unchanged
get index pattern - indexPatternService.get(id);

Other changes

  • indexPatternService.get(); no longer returns a new IndexPattern instance
  • IndexPatternSpec.fields now uses Record<string, FieldSpec> instead of FieldSpec[]
  • No longer throwing on unknown field (this was a bug)
  • indexPattern.fieldsFetcher is replaced by indexPatternService.getFieldsForWildcard and indexPatternService.getFieldsForIndexPattern
  • indexPattern.originalBody => indexPattern.originalSavedObjectBody updates via indexPattern.resetOriginalSavedObjectBody
  • indexPattern.refreshFields => indexPatternService.refreshFields(indexPattern)
  • indexPatternService.createAndSave(indexPatternSpec) convenience method added
  • indexPatternService.getFieldsForWildcard can be called directly. Previously a temp index pattern had to be created.

Addresses

Checklist

For maintainers

Dev Docs

The index pattern factory and crud methods have been refactored -

Create new indexPattern instance (unsaved) -
indexPatternService.make() => indexPatternService.create(indexPatternSpec, skipFetchFields)

Save new index pattern -
indexPattern.create() => indexPatternService.createSavedObject(indexPattern)

Setting the default index pattern is done as part of indexPatternService.createSavedObject but can also be called individually-
uiSettings.set('defaultIndex', id) => indexPatternService.setDefault(indexPatternId, force)

Update index pattern -
indexPattern.save() => indexPatternService.updateSavedObject(indexPattern)

Additional changes

  • indexPatternService.get(); no longer returns a new IndexPattern instance
  • IndexPatternSpec.fields now uses Record<string, FieldSpec> instead of FieldSpec[]
  • indexPattern.fieldsFetcher is replaced by indexPatternService.getFieldsForWildcard and indexPatternService.getFieldsForIndexPattern
  • indexPattern.originalBody => indexPattern.originalSavedObjectBody updates via indexPattern.resetOriginalSavedObjectBody
  • indexPattern.refreshFields => indexPatternService.refreshFields(indexPattern)
  • indexPatternService.createAndSave(indexPatternSpec) convenience method added
  • indexPatternService.getFieldsForWildcard can be called directly. Previously a temp index pattern had to be created.

@mattkime mattkime requested a review from a team September 21, 2020 04:14
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

Copy link
Contributor

@mshustov mshustov left a comment

Choose a reason for hiding this comment

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

approved since the current implementation reproduces the old logic

try {
emptyPattern = await indexPatterns.createAndSave(indexPatternSpec, overwriteAll, true);
} catch (err) {
if (err instanceof DuplicateIndexPatternError) {
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: does it make sense to provide an error helper instead to hide an implementation details?

dataPluginErrors.indexPatterns.isDuplicate(err) ? 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a code style question. In this case DuplicateIndexPatternError is being treated as a public interface. The code is trivial. I think code consistency is more important than which path we choose.

} else {
return;
if (isConfirmed) {
emptyPattern = await indexPatterns.createAndSave(indexPatternSpec, true, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

So we assume it couldn't throw here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case we're overriding any existing index patterns so DuplicateIndexPatternError won't throw.

As best I can tell the handling of errors (or lack thereof) has been maintained.

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.

KibanaApp owned code LGTM, there were just tests changed.

Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 left a comment

Choose a reason for hiding this comment

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

LGTM ⚡

Copy link
Member

@lukeelmers lukeelmers 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. A few nits/questions but nothing critical.

@@ -230,6 +230,8 @@ import {
formatHitProvider,
} from './index_patterns';

export type { IndexPatternsService } from './index_patterns';
Copy link
Member

Choose a reason for hiding this comment

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

does this need to be exported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exported for docs

@@ -289,3 +289,5 @@ export const config: PluginConfigDescriptor<ConfigSchema> = {
},
schema: configSchema,
};

export type { IndexPatternsService } from './index_patterns';
Copy link
Member

Choose a reason for hiding this comment

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

does this need to be exported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exported for docs

src/plugins/data/public/index.ts Outdated Show resolved Hide resolved
@@ -121,7 +121,9 @@ export const EditIndexPattern = withRouter(
const refreshFields = () => {
overlays.openConfirm(confirmMessage, confirmModalOptionsRefresh).then(async (isConfirmed) => {
if (isConfirmed) {
await indexPattern.refreshFields();
// todo catch error as in index_pattern
Copy link
Member

Choose a reason for hiding this comment

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

Is this TODO a leftover task from this PR, or for future reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, thought I got that one - addressed.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

async chunks size

id value diff baseline
fileUpload 719.6KB -1.2KB 720.7KB
indexPatternManagement 807.2KB +963.0B 806.2KB
ml 8.1MB -1.6KB 8.1MB
transform 660.9KB -264.0B 661.1KB
total -2.0KB

page load bundle size

id value diff baseline
data 1.5MB +2.0KB 1.5MB
ml 873.6KB +53.0B 873.5KB
savedObjectsManagement 226.2KB +263.0B 225.9KB
total +2.3KB

History

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

@mattkime mattkime merged commit 9450248 into elastic:master Sep 23, 2020
mattkime added a commit to mattkime/kibana that referenced this pull request Sep 23, 2020
* index pattern - refactor constructor
# Conflicts:
#	docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md
#	docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md
#	docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern._constructor_.md
#	docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.md
#	src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts
#	src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts
#	src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts
#	src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts
#	src/plugins/data/public/public.api.md
#	src/plugins/data/server/server.api.md
#	x-pack/plugins/translations/translations/ja-JP.json
#	x-pack/plugins/translations/translations/zh-CN.json
gmmorris added a commit to gmmorris/kibana that referenced this pull request Sep 23, 2020
* master: (31 commits)
  skip tests for old pacakge (elastic#78194)
  [Ingest Pipelines] Add url generator for ingest pipelines app (elastic#77872)
  [Lens] Rename "telemetry" to "stats" (elastic#78125)
  [CSM] Url search (elastic#77516)
  [Drilldowns] Config to disable URL Drilldown  (elastic#77887)
  [Lens] Combined histogram/range aggregation for numbers (elastic#76121)
  Remove legacy plugins support (elastic#77599)
  'Auto' interval must be correctly calculated for natural numbers (elastic#77995)
  [CSM] fix ingest data retry order messed up (elastic#78163)
  Add response status helpers (elastic#78006)
  Bump react-beautiful-dnd (elastic#78028)
  [Security Solution][Detection Engine] Bubbles up more error messages from ES queries to the UI (elastic#78004)
  Index pattern  - refactor constructor (elastic#77791)
  Add `xpack.security.sameSiteCookies` to docker allow list (elastic#78192)
  Remove [key: string]: any; from IIndexPattern (elastic#77968)
  Remove requirement for manage_index_templates privilege for Index Management (elastic#77377)
  [Ingest Manager] Agent bulk actions UI (elastic#77690)
  [Metrics UI] Add inventory view timeline (elastic#77804)
  Reporting/Docs: Updates for setting to enable CSV Download (elastic#78101)
  Update to latest rum-react (elastic#78193)
  ...
mattkime added a commit that referenced this pull request Sep 23, 2020
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:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants