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

Wrap rison-node to improve types #146649

Merged
merged 2 commits into from
Dec 1, 2022

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Nov 29, 2022

@maximpn brought up the issues caused by the types required by the rison-node package, which attempted to communicate that "encoded values must be primitive values, or recursive arrays/object of primitive values". This isn't actually expressible in TypeScript, which lead to many instances of rison.encode(value as unknown as RisonValue) which is useless. Additionally, the rison-node library actually supports any value and will either produce valid rison or undefined for that value.

To address this I'm adding a wrapper function which accepts any and returns a string. If rison-node is totally unable to produce any rison for the value (because the value is undefined or some other type like Symbol or BigInt) the encode() function will throw. If you're accepting arbitrary input you can use the encodeUnknown() function, which will return a string or undefined, if the value you provided has zero rison representation.

Like JSON.stringify() any non-circular primitive, object, or array can be encoded with either function. If the values within those objects are not encodable (functions, RegExps, etc) then they will be skipped. Any object/array with the toJSON() method will be converted to JSON first, and if the prototype of the object has the encode_rison() method it will be used to convert he value into rison.

The changes in this PR are mostly updating usage of rison-node to use @kbn/rison (which is also enforced by eslint). There are also several changes which remove unnecessary casting.

@spalger spalger changed the title add wrapper around rison-node Wrap rison-node to improve types Nov 30, 2022
@spalger spalger force-pushed the implement/rison-node-wrapper branch 2 times, most recently from 487b716 to 82a08b9 Compare November 30, 2022 22:57
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

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/rison - 7 +7

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/rison - 2 +2

Async chunks

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

id before after diff
maps 2.7MB 2.7MB +176.0B

Page load bundle

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

id before after diff
aiops 5.2KB 5.2KB -1.0B
apm 30.0KB 29.9KB -1.0B
cloudSecurityPosture 10.6KB 10.6KB -1.0B
dataVisualizer 20.4KB 20.4KB -1.0B
discover 27.9KB 27.9KB -1.0B
fleet 119.6KB 119.6KB -1.0B
graph 7.4KB 7.4KB -1.0B
infra 85.9KB 85.9KB -1.0B
kbnUiSharedDeps-npmDll 5.2MB 5.2MB -5.1KB
kbnUiSharedDeps-srcJs 4.1MB 4.1MB +6.0KB
kibanaUtils 68.9KB 68.9KB +40.0B
lens 29.4KB 29.4KB -1.0B
maps 53.9KB 53.9KB -2.0B
ml 42.2KB 42.2KB -1.0B
observability 73.1KB 73.1KB -1.0B
osquery 48.5KB 48.5KB -1.0B
reporting 42.5KB 42.5KB -1.0B
securitySolution 50.8KB 50.8KB -1.0B
synthetics 25.3KB 25.3KB -1.0B
uiActionsEnhanced 22.3KB 22.3KB -1.0B
upgradeAssistant 19.3KB 19.3KB -1.0B
visTypeTimeseries 19.7KB 19.7KB -1.0B
visualizations 53.8KB 53.8KB -1.0B
total +932.0B
Unknown metric groups

API count

id before after diff
@kbn/rison - 11 +11

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
@kbn/rison - 2 +2
enterpriseSearch 19 21 +2
fleet 59 65 +6
maps 38 39 +1
osquery 109 115 +6
securitySolution 442 448 +6
total +23

Total ESLint disabled count

id before after diff
@kbn/rison - 2 +2
enterpriseSearch 20 22 +2
fleet 68 74 +6
maps 66 67 +1
osquery 110 117 +7
securitySolution 519 525 +6
total +24

History

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

@spalger spalger added Team:Operations Team label for Operations Team release_note:skip Skip the PR/issue when compiling release notes labels Dec 1, 2022
@spalger spalger marked this pull request as ready for review December 1, 2022 04:23
@spalger spalger requested review from a team as code owners December 1, 2022 04:23
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

@botelastic botelastic bot added Team:APM All issues that need APM UI Team support Team:Fleet Team label for Observability Data Collection Fleet team Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability labels Dec 1, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:APM)

@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@elasticmachine
Copy link
Contributor

Pinging @elastic/uptime (Team:uptime)

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

Visualizations team changes LGTM

Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

Core changes LGTM!

Q: Should we add an Eslint rule to promote @kbn/rison over rison-node?

packages/kbn-rison/kbn_rison.ts Show resolved Hide resolved
packages/kbn-rison/package.json Show resolved Hide resolved
Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

kibana-gis changes LGTM
code review

Copy link
Member

@kpollich kpollich left a comment

Choose a reason for hiding this comment

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

Fleet changes 🚀

Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

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

LGTM from @elastic/security-onboarding-and-lifecycle-mgt team

@spalger spalger merged commit 2e314db into elastic:main Dec 1, 2022
@spalger spalger deleted the implement/rison-node-wrapper branch December 1, 2022 15:33
@kibanamachine kibanamachine added v8.7.0 backport:skip This commit does not require backporting labels Dec 1, 2022
maximpn added a commit that referenced this pull request Jan 5, 2023
…147218)

Addresses: #140263

This PR was inspired by #146649 and while working on persistent rules table state #145111.

## Summary

It includes improvements for url search parameters manipulation functionality. In particular `useGetInitialUrlParamValue` and `useReplaceUrlParams` hooks.

The main idea is to isolate the encoding layer ([rison](https://github.com/Nanonid/rison)) as an implementation detail so `useGetInitialUrlParamValue` and `useReplaceUrlParams` consumers can just provide types they wish and the hooks serialize/desirealize the data into appropriate format under the hood.

On top of that after `@kbn/rison` was added in #146649 it's possible to use this package directly to encode and decode parameters whenever necessary.

The improvements include
- store unserialized url parameters state in the redux store
- encode and decode data by using functions from `@kbn/rison` directly
- let `useReplaceUrlParams` accept an updater object

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
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 release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support Team:Fleet Team label for Observability Data Collection Fleet team Team:Operations Team label for Operations Team Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet