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

[ML] Move nested property utilities and url state to packages #147912

Merged
merged 14 commits into from
Dec 27, 2022

Conversation

walterra
Copy link
Contributor

@walterra walterra commented Dec 21, 2022

Summary

Part of #136182.

Effort to deduplicate code. Move nested property utilities and url state to packages.

Boilerplate for the packages was created likes this:

node scripts/generate package @kbn/ml-url-state --web --dir ./x-pack/packages/ml/url_state
node scripts/generate package @kbn/ml-nested-property --web --dir ./x-pack/packages/ml/nested_property

I consolidated the different url_state.ts files. One thing to note: Each one had its own definition for pageKey: AppStateKey. I changed that and made it just pageKey: string, I suspect it's good enough. Otherwise we'd have a reverse dependency on all consuming code. Alternative: We could refactor to require overriding a generic to pass in allowed values.

Checklist

@walterra walterra self-assigned this Dec 21, 2022
@walterra walterra force-pushed the ml-package-url-state branch from 25f386c to e653e12 Compare December 21, 2022 12:46
@walterra walterra added :ml release_note:skip Skip the PR/issue when compiling release notes v8.7.0 labels Dec 21, 2022
@walterra walterra marked this pull request as ready for review December 21, 2022 16:21
@walterra walterra requested a review from a team as a code owner December 21, 2022 16:21
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

Copy link
Member

@jgowdyelastic jgowdyelastic 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

@walterra walterra marked this pull request as draft December 23, 2022 08:16
@walterra walterra marked this pull request as ready for review December 23, 2022 08:23
@walterra
Copy link
Contributor Author

I remerged main which now includes #146212 with the updated packages setup. This means in this PR the Bazel files are now gone too.

@@ -239,7 +232,7 @@ export class PageUrlStateService<T> {
* Hook for managing the URL state of the page.
*/
export const usePageUrlState = <PageUrlState extends object>(
pageKey: AppStateKey,
pageKey: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

I reckon it's important to validate the page id here. We could also infer PageUrlState from the page key. I guess it's fine to merge AppStateKey and the appropriate URL states from all plugins. WDYT?

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'd like to avoid having too plugin specific code in the packages which are used by multiple plugins. Instead I now did it the other way around and changed the required generic for usePageUrlState to be a combo of the pageKey definition and the original url state interface in 2f84808. Hope that's good enough for this iteration.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
aiops 457 461 +4
dataVisualizer 301 305 +4
ml 1591 1594 +3
transform 270 272 +2
total +13

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/ml-nested-property - 8 +8
@kbn/ml-url-state - 24 +24
total +32

Any counts in public APIs

Total count of every any typed public API. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats any for more detailed information.

id before after diff
@kbn/ml-nested-property - 2 +2
@kbn/ml-url-state - 1 +1
total +3

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
aiops 737.7KB 738.9KB +1.2KB
dataVisualizer 379.2KB 379.0KB -193.0B
ml 3.4MB 3.4MB +176.0B
transform 347.9KB 347.9KB +8.0B
total +1.2KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/ml-url-state - 1 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
dataVisualizer 23.8KB 25.3KB +1.5KB
Unknown metric groups

API count

id before after diff
@kbn/ml-nested-property - 8 +8
@kbn/ml-url-state - 31 +31
total +39

ESLint disabled in files

id before after diff
@kbn/analytics-shippers-fullstory 1 2 +1
@kbn/analytics-shippers-gainsight 1 2 +1
@kbn/apm-synthtrace 3 4 +1
@kbn/babel-register 1 2 +1
@kbn/bazel-packages 1 2 +1
@kbn/cli-dev-mode 1 2 +1
@kbn/core-deprecations-server-internal 2 3 +1
@kbn/core-metrics-collectors-server-internal 2 4 +2
@kbn/core-overlays-browser-internal 2 4 +2
@kbn/core-rendering-server-internal 2 4 +2
@kbn/core-saved-objects-api-server-internal 1 2 +1
@kbn/crypto-browser 1 2 +1
@kbn/docs-utils 3 4 +1
@kbn/es-query 1 2 +1
@kbn/eslint-plugin-disable 39 76 +37
@kbn/failed-test-reporter-cli 1 2 +1
@kbn/handlebars 5 9 +4
@kbn/i18n 2 3 +1
@kbn/monaco 5 10 +5
@kbn/optimizer 2 4 +2
@kbn/safer-lodash-set 5 8 +3
@kbn/securitysolution-io-ts-alerting-types 9 18 +9
@kbn/securitysolution-io-ts-list-types 14 28 +14
@kbn/shared-ux-file-picker 1 2 +1
@kbn/shared-ux-file-upload 1 2 +1
@kbn/shared-ux-link-redirect-app 1 2 +1
@kbn/storybook 1 2 +1
@kbn/ts-project-linter 2 4 +2
actions 2 4 +2
apm 13 25 +12
bfetch 1 2 +1
canvas 4 7 +3
cases 17 27 +10
cloudFullStory 1 2 +1
cloudSecurityPosture 1 2 +1
console 3 5 +2
crossClusterReplication 2 4 +2
dashboardEnhanced 2 4 +2
data 2 4 +2
dataViewEditor 1 2 +1
dataViews 2 4 +2
discover 1 2 +1
embeddable 2 4 +2
embeddableEnhanced 2 4 +2
enterpriseSearch 1 2 +1
eventAnnotation 1 2 +1
expressionError 1 2 +1
expressionImage 1 2 +1
expressionMetric 1 2 +1
expressionRepeatImage 1 2 +1
expressionRevealImage 1 2 +1
expressions 5 9 +4
expressionTagcloud 1 2 +1
files 2 4 +2
fleet 9 15 +6
home 1 2 +1
indexLifecycleManagement 1 2 +1
indexManagement 4 8 +4
infra 8 15 +7
inspector 2 4 +2
kibanaReact 4 8 +4
kibanaUsageCollection 3 6 +3
kibanaUtils 2 4 +2
lens 3 6 +3
lists 5 10 +5
maps 28 42 +14
ml 3 6 +3
monitoring 7 14 +7
observability 7 10 +3
osquery 1 2 +1
reporting 1 2 +1
ruleRegistry 2 3 +1
savedSearch 1 2 +1
screenshotting 3 5 +2
securitySolution 75 134 +59
share 2 3 +1
snapshotRestore 1 2 +1
synthetics 6 11 +5
telemetry 6 11 +5
transform 3 6 +3
triggersActionsUi 3 5 +2
uiActionsEnhanced 4 8 +4
urlForwarding 1 2 +1
usageCollection 1 2 +1
ux 3 4 +1
visTypeTimelion 1 2 +1
visTypeTimeseries 3 6 +3
visTypeVislib 2 3 +1
visTypeXy 1 2 +1
visualizations 2 4 +2
total +321

ESLint disabled line counts

id before after diff
@kbn/alerts 2 3 +1
@kbn/analytics 1 2 +1
@kbn/analytics-client 18 36 +18
@kbn/analytics-shippers-elastic-v3-browser 4 8 +4
@kbn/analytics-shippers-elastic-v3-server 19 38 +19
@kbn/analytics-shippers-fullstory 5 10 +5
@kbn/apm-config-loader 2 4 +2
@kbn/apm-synthtrace 9 17 +8
@kbn/cases-components 1 2 +1
@kbn/cli-dev-mode 4 8 +4
@kbn/coloring 1 2 +1
@kbn/content-management-table-list 2 3 +1
@kbn/core-analytics-browser-internal 10 20 +10
@kbn/core-application-browser-internal 1 2 +1
@kbn/core-chrome-browser-internal 2 4 +2
@kbn/core-elasticsearch-client-server-internal 2 4 +2
@kbn/core-elasticsearch-server-internal 1 2 +1
@kbn/core-fatal-errors-browser-internal 4 8 +4
@kbn/core-http-server-internal 2 4 +2
@kbn/core-i18n-browser-internal 1 2 +1
@kbn/core-logging-browser-internal 3 6 +3
@kbn/core-logging-server-internal 8 16 +8
@kbn/core-metrics-collectors-server-internal 1 2 +1
@kbn/core-plugins-server-internal 4 8 +4
@kbn/core-root-browser-internal 4 8 +4
@kbn/core-root-server-internal 3 6 +3
@kbn/core-saved-objects-api-server-internal 6 12 +6
@kbn/core-saved-objects-base-server-internal 3 6 +3
@kbn/core-ui-settings-server-internal 1 2 +1
@kbn/datemath 1 2 +1
@kbn/docs-utils 8 16 +8
@kbn/es 1 2 +1
@kbn/eslint-plugin-disable 23 48 +25
@kbn/eslint-plugin-imports 1 2 +1
@kbn/handlebars 4 5 +1
@kbn/i18n 1 2 +1
@kbn/i18n-react 4 6 +2
@kbn/interpreter 5 8 +3
@kbn/journeys 1 2 +1
@kbn/ml-string-hash 2 4 +2
@kbn/ml-url-state - 10 +10
@kbn/monaco 2 3 +1
@kbn/optimizer 4 7 +3
@kbn/peggy-loader 1 2 +1
@kbn/rison 2 4 +2
@kbn/securitysolution-autocomplete 1 2 +1
@kbn/securitysolution-exception-list-components 2 3 +1
@kbn/securitysolution-io-ts-utils 1 2 +1
@kbn/securitysolution-list-api 6 12 +6
@kbn/securitysolution-list-hooks 1 2 +1
@kbn/securitysolution-t-grid 1 2 +1
@kbn/server-http-tools 1 2 +1
@kbn/shared-ux-avatar-user-profile-components 2 4 +2
@kbn/shared-ux-file-image 2 4 +2
@kbn/shared-ux-link-redirect-app 1 2 +1
@kbn/std 1 2 +1
@kbn/storybook 1 2 +1
@kbn/test 6 12 +6
@kbn/ui-shared-deps-npm 1 2 +1
@kbn/ui-shared-deps-src 2 3 +1
@kbn/ui-theme 2 4 +2
@kbn/user-profile-components 3 6 +3
actions 22 42 +20
advancedSettings 2 3 +1
aiops 30 50 +20
alerting 70 121 +51
apm 75 144 +69
canvas 32 52 +20
cases 58 97 +39
cloudChat 2 4 +2
cloudExperiments 4 8 +4
cloudFullStory 1 2 +1
cloudGainsight 1 2 +1
cloudSecurityPosture 12 17 +5
console 36 71 +35
controls 2 4 +2
core 7 14 +7
crossClusterReplication 7 14 +7
customIntegrations 11 20 +9
dashboard 6 10 +4
data 52 92 +40
dataViewFieldEditor 9 14 +5
dataViews 12 16 +4
dataVisualizer 46 86 +40
discover 40 81 +41
embeddable 7 14 +7
embeddableEnhanced 3 4 +1
enterpriseSearch 8 15 +7
esUiShared 12 24 +12
eventLog 4 7 +3
expressionError 5 7 +2
expressionGauge 2 3 +1
expressionHeatmap 2 3 +1
expressionLegacyMetricVis 5 8 +3
expressionMetricVis 2 4 +2
expressionPartitionVis 3 5 +2
expressions 16 25 +9
expressionTagcloud 2 3 +1
expressionXY 1 2 +1
fieldFormats 5 7 +2
fileUpload 4 7 +3
fleet 56 102 +46
globalSearch 3 4 +1
globalSearchBar 1 2 +1
graph 4 8 +4
grokdebugger 1 2 +1
home 10 17 +7
indexLifecycleManagement 1 2 +1
indexManagement 14 28 +14
infra 45 84 +39
ingestPipelines 15 30 +15
interactiveSetup 10 20 +10
kibanaReact 12 23 +11
kibanaUsageCollection 6 10 +4
kibanaUtils 12 23 +11
kubernetesSecurity 7 11 +4
lens 19 37 +18
licenseApiGuard 1 2 +1
lists 18 32 +14
maps 39 76 +37
ml 564 1114 +550
monitoring 18 36 +18
notifications 4 8 +4
observability 47 90 +43
osquery 106 199 +93
painlessLab 1 2 +1
presentationUtil 10 18 +8
profiling 9 15 +6
remoteClusters 2 3 +1
reporting 4 7 +3
rollup 5 10 +5
ruleRegistry 1 2 +1
savedObjectsFinder 1 2 +1
savedObjectsTagging 2 4 +2
savedObjectsTaggingOss 1 2 +1
screenshotMode 1 2 +1
screenshotting 6 12 +6
security 24 47 +23
securitySolution 432 760 +328
sessionView 6 9 +3
share 7 13 +6
snapshotRestore 3 6 +3
spaces 1 2 +1
stackAlerts 25 46 +21
stackConnectors 78 113 +35
synthetics 69 123 +54
taskManager 22 41 +19
telemetry 1 2 +1
telemetryCollectionManager 7 14 +7
telemetryManagementSection 1 2 +1
threatIntelligence 6 10 +4
timelines 23 30 +7
transform 27 54 +27
triggersActionsUi 137 228 +91
uiActions 1 2 +1
uiActionsEnhanced 9 18 +9
unifiedFieldList 17 28 +11
unifiedHistogram 2 4 +2
unifiedSearch 26 48 +22
upgradeAssistant 9 17 +8
urlDrilldown 4 6 +2
usageCollection 2 3 +1
ux 9 16 +7
visDefaultEditor 4 7 +3
visTypeTable 4 5 +1
visTypeTimelion 5 7 +2
visTypeTimeseries 19 23 +4
visTypeVega 6 8 +2
visTypeXy 4 5 +1
visualizations 15 25 +10
watcher 3 6 +3
total +2403

Total ESLint disabled count

id before after diff
@kbn/alerts 2 3 +1
@kbn/analytics 1 2 +1
@kbn/analytics-client 18 36 +18
@kbn/analytics-shippers-elastic-v3-browser 4 8 +4
@kbn/analytics-shippers-elastic-v3-server 19 38 +19
@kbn/analytics-shippers-fullstory 6 12 +6
@kbn/analytics-shippers-gainsight 1 2 +1
@kbn/apm-config-loader 2 4 +2
@kbn/apm-synthtrace 12 21 +9
@kbn/babel-register 1 2 +1
@kbn/bazel-packages 1 2 +1
@kbn/cases-components 1 2 +1
@kbn/cli-dev-mode 5 10 +5
@kbn/coloring 1 2 +1
@kbn/content-management-table-list 2 3 +1
@kbn/core-analytics-browser-internal 10 20 +10
@kbn/core-application-browser-internal 1 2 +1
@kbn/core-chrome-browser-internal 2 4 +2
@kbn/core-deprecations-server-internal 2 3 +1
@kbn/core-elasticsearch-client-server-internal 2 4 +2
@kbn/core-elasticsearch-server-internal 1 2 +1
@kbn/core-fatal-errors-browser-internal 4 8 +4
@kbn/core-http-server-internal 2 4 +2
@kbn/core-i18n-browser-internal 1 2 +1
@kbn/core-logging-browser-internal 3 6 +3
@kbn/core-logging-server-internal 8 16 +8
@kbn/core-metrics-collectors-server-internal 3 6 +3
@kbn/core-overlays-browser-internal 2 4 +2
@kbn/core-plugins-server-internal 4 8 +4
@kbn/core-rendering-server-internal 2 4 +2
@kbn/core-root-browser-internal 4 8 +4
@kbn/core-root-server-internal 3 6 +3
@kbn/core-saved-objects-api-server-internal 7 14 +7
@kbn/core-saved-objects-base-server-internal 3 6 +3
@kbn/core-ui-settings-server-internal 1 2 +1
@kbn/crypto-browser 1 2 +1
@kbn/datemath 1 2 +1
@kbn/docs-utils 11 20 +9
@kbn/es 1 2 +1
@kbn/es-query 9 10 +1
@kbn/eslint-plugin-disable 62 124 +62
@kbn/eslint-plugin-imports 1 2 +1
@kbn/failed-test-reporter-cli 1 2 +1
@kbn/handlebars 9 14 +5
@kbn/i18n 3 5 +2
@kbn/i18n-react 4 6 +2
@kbn/interpreter 5 8 +3
@kbn/journeys 1 2 +1
@kbn/ml-string-hash 2 4 +2
@kbn/ml-url-state - 10 +10
@kbn/monaco 7 13 +6
@kbn/optimizer 6 11 +5
@kbn/peggy-loader 1 2 +1
@kbn/rison 2 4 +2
@kbn/safer-lodash-set 5 8 +3
@kbn/securitysolution-autocomplete 1 2 +1
@kbn/securitysolution-exception-list-components 2 3 +1
@kbn/securitysolution-io-ts-alerting-types 9 18 +9
@kbn/securitysolution-io-ts-list-types 14 28 +14
@kbn/securitysolution-io-ts-utils 1 2 +1
@kbn/securitysolution-list-api 6 12 +6
@kbn/securitysolution-list-hooks 1 2 +1
@kbn/securitysolution-t-grid 1 2 +1
@kbn/server-http-tools 1 2 +1
@kbn/shared-ux-avatar-user-profile-components 2 4 +2
@kbn/shared-ux-file-image 2 4 +2
@kbn/shared-ux-file-picker 1 2 +1
@kbn/shared-ux-file-upload 1 2 +1
@kbn/shared-ux-link-redirect-app 2 4 +2
@kbn/std 1 2 +1
@kbn/storybook 2 4 +2
@kbn/test 6 12 +6
@kbn/ts-project-linter 2 4 +2
@kbn/ui-shared-deps-npm 1 2 +1
@kbn/ui-shared-deps-src 2 3 +1
@kbn/ui-theme 2 4 +2
@kbn/user-profile-components 3 6 +3
actions 24 46 +22
advancedSettings 2 3 +1
aiops 30 50 +20
alerting 71 122 +51
apm 88 169 +81
bfetch 6 7 +1
canvas 36 59 +23
cases 75 124 +49
cloudChat 2 4 +2
cloudExperiments 4 8 +4
cloudFullStory 2 4 +2
cloudGainsight 3 4 +1
cloudSecurityPosture 13 19 +6
console 39 76 +37
controls 2 4 +2
core 7 14 +7
crossClusterReplication 9 18 +9
customIntegrations 11 20 +9
dashboard 6 10 +4
dashboardEnhanced 7 9 +2
data 54 96 +42
dataViewEditor 3 4 +1
dataViewFieldEditor 9 14 +5
dataViews 14 20 +6
dataVisualizer 46 86 +40
discover 41 83 +42
embeddable 9 18 +9
embeddableEnhanced 5 8 +3
enterpriseSearch 9 17 +8
esUiShared 12 24 +12
eventAnnotation 1 2 +1
eventLog 4 7 +3
expressionError 6 9 +3
expressionGauge 2 3 +1
expressionHeatmap 2 3 +1
expressionImage 2 3 +1
expressionLegacyMetricVis 5 8 +3
expressionMetric 2 3 +1
expressionMetricVis 2 4 +2
expressionPartitionVis 3 5 +2
expressionRepeatImage 2 3 +1
expressionRevealImage 2 3 +1
expressions 21 34 +13
expressionTagcloud 3 5 +2
expressionXY 1 2 +1
fieldFormats 5 7 +2
files 3 5 +2
fileUpload 4 7 +3
fleet 65 117 +52
globalSearch 3 4 +1
globalSearchBar 1 2 +1
graph 4 8 +4
grokdebugger 1 2 +1
home 11 19 +8
indexLifecycleManagement 2 4 +2
indexManagement 18 36 +18
infra 53 99 +46
ingestPipelines 15 30 +15
inspector 3 5 +2
interactiveSetup 10 20 +10
kibanaReact 16 31 +15
kibanaUsageCollection 9 16 +7
kibanaUtils 14 27 +13
kubernetesSecurity 7 11 +4
lens 22 43 +21
licenseApiGuard 1 2 +1
lists 23 42 +19
maps 67 118 +51
ml 567 1120 +553
monitoring 25 50 +25
notifications 4 8 +4
observability 54 100 +46
osquery 107 201 +94
painlessLab 1 2 +1
presentationUtil 10 18 +8
profiling 9 15 +6
remoteClusters 2 3 +1
reporting 5 9 +4
rollup 5 10 +5
ruleRegistry 3 5 +2
savedObjectsFinder 1 2 +1
savedObjectsTagging 2 4 +2
savedObjectsTaggingOss 1 2 +1
savedSearch 1 2 +1
screenshotMode 1 2 +1
screenshotting 9 17 +8
security 26 49 +23
securitySolution 507 894 +387
sessionView 6 9 +3
share 9 16 +7
snapshotRestore 4 8 +4
spaces 1 2 +1
stackAlerts 25 46 +21
stackConnectors 82 117 +35
synthetics 75 134 +59
taskManager 22 41 +19
telemetry 7 13 +6
telemetryCollectionManager 7 14 +7
telemetryManagementSection 1 2 +1
threatIntelligence 6 10 +4
timelines 23 30 +7
transform 30 60 +30
triggersActionsUi 140 233 +93
uiActions 1 2 +1
uiActionsEnhanced 13 26 +13
unifiedFieldList 17 28 +11
unifiedHistogram 2 4 +2
unifiedSearch 26 48 +22
upgradeAssistant 9 17 +8
urlDrilldown 4 6 +2
urlForwarding 1 2 +1
usageCollection 3 5 +2
ux 12 20 +8
visDefaultEditor 5 8 +3
visTypeTable 4 5 +1
visTypeTimelion 6 9 +3
visTypeTimeseries 22 29 +7
visTypeVega 6 8 +2
visTypeVislib 3 4 +1
visTypeXy 5 7 +2
visualizations 17 29 +12
watcher 3 6 +3
total +2724

History

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

cc @walterra

Copy link
Contributor

@darnautov darnautov left a comment

Choose a reason for hiding this comment

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

LGTM! I reckon for further enhancement we can get rid of the generic type in usePageUrlState, validate a pageKey and infer the state from it. It'll require storing types inside of the package, but I assume it's fine as they don't affect the bundle size.

@walterra walterra merged commit 8a44ba3 into elastic:main Dec 27, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Dec 27, 2022
@walterra walterra deleted the ml-package-url-state branch December 27, 2022 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting :ml release_note:skip Skip the PR/issue when compiling release notes v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants