Index pattern - refactor constructor#77791
Conversation
mshustov
left a comment
There was a problem hiding this comment.
approved since the current implementation reproduces the old logic
| try { | ||
| emptyPattern = await indexPatterns.createAndSave(indexPatternSpec, overwriteAll, true); | ||
| } catch (err) { | ||
| if (err instanceof DuplicateIndexPatternError) { |
There was a problem hiding this comment.
optional: does it make sense to provide an error helper instead to hide an implementation details?
dataPluginErrors.indexPatterns.isDuplicate(err) ? There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
So we assume it couldn't throw here?
There was a problem hiding this comment.
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.
...lugins/ml/public/application/datavisualizer/file_based/components/import_view/import_view.js
Show resolved
Hide resolved
...tics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts
Outdated
Show resolved
Hide resolved
...lugins/ml/public/application/datavisualizer/file_based/components/import_view/import_view.js
Show resolved
Hide resolved
kertal
left a comment
There was a problem hiding this comment.
KibanaApp owned code LGTM, there were just tests changed.
lukeelmers
left a comment
There was a problem hiding this comment.
Code LGTM. A few nits/questions but nothing critical.
| formatHitProvider, | ||
| } from './index_patterns'; | ||
|
|
||
| export type { IndexPatternsService } from './index_patterns'; |
There was a problem hiding this comment.
does this need to be exported?
| schema: configSchema, | ||
| }; | ||
|
|
||
| export type { IndexPatternsService } from './index_patterns'; |
There was a problem hiding this comment.
does this need to be exported?
| overlays.openConfirm(confirmMessage, confirmModalOptionsRefresh).then(async (isConfirmed) => { | ||
| if (isConfirmed) { | ||
| await indexPattern.refreshFields(); | ||
| // todo catch error as in index_pattern |
There was a problem hiding this comment.
Is this TODO a leftover task from this PR, or for future reference?
There was a problem hiding this comment.
ah, thought I got that one - addressed.
💚 Build SucceededBuild metricsasync chunks size
page load bundle size
History
To update your PR or re-run it, just comment with: |
* 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
* 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) ...
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.createSavedObjectbut 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 instanceIndexPatternSpec.fieldsnow usesRecord<string, FieldSpec>instead ofFieldSpec[]indexPattern.fieldsFetcheris replaced byindexPatternService.getFieldsForWildcardandindexPatternService.getFieldsForIndexPatternindexPattern.originalBody=>indexPattern.originalSavedObjectBodyupdates viaindexPattern.resetOriginalSavedObjectBodyindexPattern.refreshFields => indexPatternService.refreshFields(indexPattern)indexPatternService.createAndSave(indexPatternSpec)convenience method addedindexPatternService.getFieldsForWildcardcan 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.createSavedObjectbut 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 instanceIndexPatternSpec.fieldsnow usesRecord<string, FieldSpec>instead ofFieldSpec[]indexPattern.fieldsFetcheris replaced byindexPatternService.getFieldsForWildcardandindexPatternService.getFieldsForIndexPatternindexPattern.originalBody=>indexPattern.originalSavedObjectBodyupdates viaindexPattern.resetOriginalSavedObjectBodyindexPattern.refreshFields => indexPatternService.refreshFields(indexPattern)indexPatternService.createAndSave(indexPatternSpec)convenience method addedindexPatternService.getFieldsForWildcardcan be called directly. Previously a temp index pattern had to be created.