-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Index pattern - refactor constructor #77791
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code LGTM
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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) ?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
...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
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ⚡
There was a problem hiding this 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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exported for docs
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
💚 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.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 instanceIndexPatternSpec.fields
now usesRecord<string, FieldSpec>
instead ofFieldSpec[]
indexPattern.fieldsFetcher
is replaced byindexPatternService.getFieldsForWildcard
andindexPatternService.getFieldsForIndexPattern
indexPattern.originalBody
=>indexPattern.originalSavedObjectBody
updates viaindexPattern.resetOriginalSavedObjectBody
indexPattern.refreshFields => indexPatternService.refreshFields(indexPattern)
indexPatternService.createAndSave(indexPatternSpec)
convenience method addedindexPatternService.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 instanceIndexPatternSpec.fields
now usesRecord<string, FieldSpec>
instead ofFieldSpec[]
indexPattern.fieldsFetcher
is replaced byindexPatternService.getFieldsForWildcard
andindexPatternService.getFieldsForIndexPattern
indexPattern.originalBody
=>indexPattern.originalSavedObjectBody
updates viaindexPattern.resetOriginalSavedObjectBody
indexPattern.refreshFields => indexPatternService.refreshFields(indexPattern)
indexPatternService.createAndSave(indexPatternSpec)
convenience method addedindexPatternService.getFieldsForWildcard
can be called directly. Previously a temp index pattern had to be created.