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] Moves shared code to @kbn/ml-error-utils. #155372

Merged
merged 18 commits into from
Apr 22, 2023

Conversation

walterra
Copy link
Contributor

@walterra walterra commented Apr 20, 2023

Summary

Part of #136182.

  • Moves code from x-pack/plugins/ml/common/util/errors that was shared via x-pack/plugins/ml/public/shared.ts to @kbn/ml-error-utils.
  • data_visualizer and aiops plugins now use that package instead of code duplication.

Checklist

@walterra walterra added :ml release_note:skip Skip the PR/issue when compiling release notes v8.8.0 labels Apr 20, 2023
@walterra walterra requested a review from a team as a code owner April 20, 2023 11:32
@walterra walterra self-assigned this Apr 20, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@@ -35,6 +35,7 @@ export interface MLResponseError {
}

export interface ErrorMessage {
query: string;
Copy link
Member

@jgowdyelastic jgowdyelastic Apr 20, 2023

Choose a reason for hiding this comment

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

It looks like we have two different versions of ErrorMessage in ML, this one is used in conjunction with isErrorMessage and is used for extracting the message string from an error returned from the kibana server which contains a message.
The other types which contain query are created in client side code, where the query is added to the error object for later use.

I think we should keep these separate and have an interface which extends ErrorMessage to add the query.
IMO this new interface shouldn't live in this file as these types are purely for describing errors returned from es or kibana.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll do some renaming to make them more distinct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renaming done in cf1b19a.

@walterra walterra requested a review from a team as a code owner April 20, 2023 13:39
@botelastic botelastic bot added the Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability label Apr 20, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/uptime (Team:uptime)

@walterra walterra requested a review from qn895 April 21, 2023 07:07
Copy link
Contributor

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

@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

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
aiops 493 496 +3
dataVisualizer 321 324 +3
synthetics 1238 1244 +6
transform 325 329 +4
total +16

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-error-utils - 8 +8
ml 83 81 -2
total +6

Async chunks

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

id before after diff
aiops 772.4KB 772.5KB +139.0B
dataVisualizer 365.9KB 366.0KB +141.0B
ml 3.4MB 3.4MB +1.9KB
synthetics 1.2MB 1.2MB +2.2KB
transform 383.0KB 385.2KB +2.2KB
total +6.5KB

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
ml 40 39 -1

Page load bundle

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

id before after diff
ml 79.6KB 77.2KB -2.5KB
synthetics 27.3KB 27.2KB -132.0B
total -2.6KB
Unknown metric groups

API count

id before after diff
@kbn/ml-error-utils - 36 +36
ml 259 257 -2
total +34

ESLint disabled line counts

id before after diff
enterpriseSearch 16 18 +2
securitySolution 395 398 +3
total +5

Total ESLint disabled count

id before after diff
enterpriseSearch 17 19 +2
securitySolution 475 478 +3
total +5

History

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

cc @walterra

@walterra walterra merged commit d6d933a into elastic:main Apr 22, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Apr 22, 2023
@walterra walterra deleted the ml-package-error-utils branch April 22, 2023 07:25
jgowdyelastic added a commit that referenced this pull request Jun 19, 2023
PR #155372 moved our error utils
to a package and also made a few small code changes, one of which added
`isPopulatedObject` to the error object type guards.
`isPopulatedObject` uses `Object.keys` under the hood which cannot be
used to access the non-enumerable properties of an object, like Error's
`message`.


![image](https://github.com/elastic/kibana/assets/22172091/6a0269df-ca2a-494a-9364-8f35f2b52388)

This PR reverts all of these functions back to their original versions
which had existed in ML for a while without issue.

This was change had been causing error messages to not display
correctly.


![image](https://github.com/elastic/kibana/assets/22172091/1862f069-1626-4ac3-8961-dca016b91956)

vs


![image](https://github.com/elastic/kibana/assets/22172091/243143a5-0c8f-4365-a41d-7c1c09858ad8)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 19, 2023
PR elastic#155372 moved our error utils
to a package and also made a few small code changes, one of which added
`isPopulatedObject` to the error object type guards.
`isPopulatedObject` uses `Object.keys` under the hood which cannot be
used to access the non-enumerable properties of an object, like Error's
`message`.

![image](https://github.com/elastic/kibana/assets/22172091/6a0269df-ca2a-494a-9364-8f35f2b52388)

This PR reverts all of these functions back to their original versions
which had existed in ML for a while without issue.

This was change had been causing error messages to not display
correctly.

![image](https://github.com/elastic/kibana/assets/22172091/1862f069-1626-4ac3-8961-dca016b91956)

vs

![image](https://github.com/elastic/kibana/assets/22172091/243143a5-0c8f-4365-a41d-7c1c09858ad8)

(cherry picked from commit 8ca1789)
kibanamachine added a commit that referenced this pull request Jun 19, 2023
#159923)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[ML] Reverting use of isPopulatedObject in error utils
(#159913)](#159913)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"James
Gowdy","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-06-19T12:52:11Z","message":"[ML]
Reverting use of isPopulatedObject in error utils (#159913)\n\nPR
#155372 moved our error
utils\r\nto a package and also made a few small code changes, one of
which added\r\n`isPopulatedObject` to the error object type
guards.\r\n`isPopulatedObject` uses `Object.keys` under the hood which
cannot be\r\nused to access the non-enumerable properties of an object,
like
Error's\r\n`message`.\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/22172091/6a0269df-ca2a-494a-9364-8f35f2b52388)\r\n\r\nThis
PR reverts all of these functions back to their original
versions\r\nwhich had existed in ML for a while without
issue.\r\n\r\nThis was change had been causing error messages to not
display\r\ncorrectly.\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/22172091/1862f069-1626-4ac3-8961-dca016b91956)\r\n\r\nvs\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/22172091/243143a5-0c8f-4365-a41d-7c1c09858ad8)","sha":"8ca1789faa899f2e0a7abcf58fac50fa4d552af6","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","v8.9.0","v8.8.2"],"number":159913,"url":"https://github.com/elastic/kibana/pull/159913","mergeCommit":{"message":"[ML]
Reverting use of isPopulatedObject in error utils (#159913)\n\nPR
#155372 moved our error
utils\r\nto a package and also made a few small code changes, one of
which added\r\n`isPopulatedObject` to the error object type
guards.\r\n`isPopulatedObject` uses `Object.keys` under the hood which
cannot be\r\nused to access the non-enumerable properties of an object,
like
Error's\r\n`message`.\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/22172091/6a0269df-ca2a-494a-9364-8f35f2b52388)\r\n\r\nThis
PR reverts all of these functions back to their original
versions\r\nwhich had existed in ML for a while without
issue.\r\n\r\nThis was change had been causing error messages to not
display\r\ncorrectly.\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/22172091/1862f069-1626-4ac3-8961-dca016b91956)\r\n\r\nvs\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/22172091/243143a5-0c8f-4365-a41d-7c1c09858ad8)","sha":"8ca1789faa899f2e0a7abcf58fac50fa4d552af6"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/159913","number":159913,"mergeCommit":{"message":"[ML]
Reverting use of isPopulatedObject in error utils (#159913)\n\nPR
#155372 moved our error
utils\r\nto a package and also made a few small code changes, one of
which added\r\n`isPopulatedObject` to the error object type
guards.\r\n`isPopulatedObject` uses `Object.keys` under the hood which
cannot be\r\nused to access the non-enumerable properties of an object,
like
Error's\r\n`message`.\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/22172091/6a0269df-ca2a-494a-9364-8f35f2b52388)\r\n\r\nThis
PR reverts all of these functions back to their original
versions\r\nwhich had existed in ML for a while without
issue.\r\n\r\nThis was change had been causing error messages to not
display\r\ncorrectly.\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/22172091/1862f069-1626-4ac3-8961-dca016b91956)\r\n\r\nvs\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/22172091/243143a5-0c8f-4365-a41d-7c1c09858ad8)","sha":"8ca1789faa899f2e0a7abcf58fac50fa4d552af6"}},{"branch":"8.8","label":"v8.8.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: James Gowdy <[email protected]>
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 Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants