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

[Console] Update dynamic parameters for the new script #162917

Merged
merged 11 commits into from
Aug 4, 2023

Conversation

yuliacech
Copy link
Contributor

@yuliacech yuliacech commented Aug 1, 2023

Summary

Fixes #160539

This PR updates the logic for dynamic parameters in the Console autocomplete engine in preparation for the new script.

Changes

  • The old script packages/spec-to-console contained some logic that would rename parameters in the json specs: {index} -> {indices}, {node_id} -> {nodes}, {metric} -> {metrics}. I don't think we need this anymore because such logic only introduces more hidden mechanics to the script. There is no significant improvements to autocomplete suggestions due to these replacements.
  • The dynamic parameters defined in the Console autocomplete engine:
    • indices - is deleted and only index is used instead. Originally, there was a minor difference between indices and index: the former should accept several index names, the latter only 1. But this logic is not working for urls currently anyways. I don't think there is a significant improvement for UX to keep this distinction. The main useful feature of this parameter is to display a list of indices in the deployment.
    • type and types - deleted because index mapping types is a removed ES feature (see this doc)
    • id, transform_id, ids, task_id - deleted as not working. Also definitions using these parameters don't intend them to be autofilled. For example, in the url /_async_search/{id} the parameter {id} can be any string.
    • user and username - deleted as incorrectly being resolved to a list of indices. Also definitions using these parameters don't intend them to be autofilled, for example _security/user/{username} when creating a new user.
    • node - delete because it was just an empty list
    • nodes - deleted because the suggestions of the form ['_local', '_master', 'data:true', 'data:false', 'master:true', 'master:false'] are not correct for definitions where a node ID is expected.
  • Renamed variables to dynamic parameters in the Console README file: I first used the word variables in readme for the values defined in the file kb.js. But then variables support was added to Console and there were several sections in the readme using the word variables for different concepts. Since in the autocomplete engine code, the function is called parametrizedComponentFactories I think calling these values dynamic parameters makes more sense and avoids confusion.

@yuliacech yuliacech changed the title [Console] Update variables for the new script [Console] Update dynamic parameters for the new script Aug 2, 2023
@yuliacech
Copy link
Contributor Author

@elasticmachine merge upstream

throw new Error("no factory found for '" + value + "'");
console.warn("[Console] no factory found for '" + value + "'");
// using upper case as an indication that this value is a parameter
return new ConstantComponent(value.toUpperCase());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of throwing an error and failing all definitions loading, we log a warning and use a constant with an upper case string.

names.unshift(name);
_.each(apiJson.globals || {}, function (globalJson, globalName) {
api.addGlobalAutocompleteRules(globalName, globalJson);
try {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need a try-catch clause here, otherwise if there is an error while loading definitions, the process fails silently.

@yuliacech yuliacech marked this pull request as ready for review August 3, 2023 06:55
@yuliacech yuliacech requested a review from a team as a code owner August 3, 2023 06:55
@yuliacech yuliacech added Feature:Console Dev Tools Console Feature Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes v8.10.0 labels Aug 3, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/platform-deployment-management (Team:Deployment Management)

@yuliacech yuliacech added the ci:cloud-deploy Create or update a Cloud deployment label Aug 3, 2023
Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

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

Nice work @yuliacech! Thanks for updating the readme as well - super helpful. I left one question about one of your code comments, but I don't think it's directly related to this PR. Also, found a small typo in the readme. Otherwise, LGTM.

src/plugins/console/README.md Outdated Show resolved Hide resolved
},
// composable index templates
// currently seems to be unused, but that is a useful functionality
Copy link
Contributor

@alisonelizabeth alisonelizabeth Aug 3, 2023

Choose a reason for hiding this comment

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

Can you elaborate on this? I believe this functionality was added via #124655. I don't remember it being removed, so I wonder if there was a regression somewhere 🤔

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 catch, thanks @alisonelizabeth! I checked the PR and the dynamic parameters were added there and they indeed still work correctly. But their usage was in the generated definitions file. The next time we used the script (#153098), we reverted the manual changes made to those definitions. So instead of _component_template/{component_template} we have _component_template/{name} because name is how it's defined in the specs. I'll open an issue to use those dynamic parameters, but in the overrides files.
I think the goal is to not edit generated files and not even have to review them when they are re-generated using the script. On the other hand, we should spend more time on updating the overrides.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Thanks for the explanation and looking into this!

Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>
@yuliacech yuliacech enabled auto-merge (squash) August 4, 2023 12:43
@yuliacech
Copy link
Contributor Author

Thanks a lot for the review, @alisonelizabeth!

@kibana-ci
Copy link
Collaborator

kibana-ci commented Aug 4, 2023

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
console 205 201 -4

Async chunks

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

id before after diff
console 418.6KB 416.6KB -2.0KB

Page load bundle

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

id before after diff
console 27.4KB 26.7KB -703.0B

History

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

@yuliacech yuliacech merged commit 04b3d17 into elastic:main Aug 4, 2023
21 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Aug 4, 2023
yuliacech added a commit that referenced this pull request Aug 7, 2023
## Summary
While working on #162917, I
noticed that there is a property `url_components` that is being
generated with the old script. This PR adds the same functionality to
the new script. The purpose of this property is to provide autocomplete
suggestions for dynamic parameters used in `patterns`. For example, the
URL defined as `_cluster/state/{metrics}` has a list of options allowed
for the parameter `metrics`. These options are defined in the json
specs, but unfortunately they are not always translated into concrete
types in the specification repo. In this example, `metrics` is described
as `string | string[]` in the specification repo. Because of that I
added some override files with `url_components` that will not be
available when we switch to the new script and re-generate the
definitions with it.

The logic for generating the url components is the same as for query
parameters. Most changes in this PR is extracting the code so that both
functions `generateQueryParams` and `generateUrlComponents` can share
it. The only difference between query parameters and url components:
with query parameters we keep all properties so that all parameters are
displayed in the autocomplete suggestions, for example `{ param1: '',
param2: '' }` provide information about 2 query parameters, specifically
their names. For url components, the name of the parameter is not
important, because only the values will be displayed for autocompletion.
That is why, we ignore all parameters without known values and only keep
properties like `{ param: ['value1', 'value2'] }`.
crespocarlos pushed a commit to crespocarlos/kibana that referenced this pull request Aug 8, 2023
## Summary
Fixes elastic#160539

This PR updates the logic for dynamic parameters in the Console
autocomplete engine in preparation for the new script.

#### Changes
- The old script `packages/spec-to-console` contained some logic that
would rename parameters in the json specs: `{index} -> {indices`},
`{node_id} -> {nodes}, {metric} -> {metrics}`. I don't think we need
this anymore because such logic only introduces more hidden mechanics to
the script. There is no significant improvements to autocomplete
suggestions due to these replacements.
- The dynamic parameters defined in the Console autocomplete engine: 
- `indices` - is deleted and only `index` is used instead. Originally,
there was a minor difference between `indices` and `index`: the former
should accept several index names, the latter only 1. [But this logic is
not working for urls currently
anyways](elastic#163000). I don't think
there is a significant improvement for UX to keep this distinction. The
main useful feature of this parameter is to display a list of indices in
the deployment.
- `type` and `types` - deleted because `index mapping types` is a
removed ES feature (see this
[doc](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html))
- `id`, `transform_id`, `ids`, `task_id` - deleted as not working. Also
definitions using these parameters don't intend them to be autofilled.
For example, in the url `/_async_search/{id}` the parameter `{id}` can
be any string.
- `user` and `username` - deleted as incorrectly being resolved to a
list of indices. Also definitions using these parameters don't intend
them to be autofilled, for example `_security/user/{username}` when
creating a new user.
  - `node` - delete because it was just an empty list
- `nodes` - deleted because the suggestions of the form `['_local',
'_master', 'data:true', 'data:false', 'master:true', 'master:false']`
are not correct for definitions where a node ID is expected.
- Renamed `variables` to `dynamic parameters` in the Console README
file: I first used the word `variables` in readme for the values defined
in the file
[`kb.js`](https://github.com/elastic/kibana/blob/6e1445b66aae27a9a762ed5632549b3f6a6dfa51/src/plugins/console/public/lib/kb/kb.js).
But then variables support was added to Console and there were several
sections in the readme using the word `variables` for different
concepts. Since in the autocomplete engine code, the function is called
`parametrizedComponentFactories` I think calling these values `dynamic
parameters` makes more sense and avoids confusion.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>
crespocarlos pushed a commit to crespocarlos/kibana that referenced this pull request Aug 8, 2023
## Summary
While working on elastic#162917, I
noticed that there is a property `url_components` that is being
generated with the old script. This PR adds the same functionality to
the new script. The purpose of this property is to provide autocomplete
suggestions for dynamic parameters used in `patterns`. For example, the
URL defined as `_cluster/state/{metrics}` has a list of options allowed
for the parameter `metrics`. These options are defined in the json
specs, but unfortunately they are not always translated into concrete
types in the specification repo. In this example, `metrics` is described
as `string | string[]` in the specification repo. Because of that I
added some override files with `url_components` that will not be
available when we switch to the new script and re-generate the
definitions with it.

The logic for generating the url components is the same as for query
parameters. Most changes in this PR is extracting the code so that both
functions `generateQueryParams` and `generateUrlComponents` can share
it. The only difference between query parameters and url components:
with query parameters we keep all properties so that all parameters are
displayed in the autocomplete suggestions, for example `{ param1: '',
param2: '' }` provide information about 2 query parameters, specifically
their names. For url components, the name of the parameter is not
important, because only the values will be displayed for autocompletion.
That is why, we ignore all parameters without known values and only keep
properties like `{ param: ['value1', 'value2'] }`.
bryce-b pushed a commit to bryce-b/kibana that referenced this pull request Aug 9, 2023
## Summary
While working on elastic#162917, I
noticed that there is a property `url_components` that is being
generated with the old script. This PR adds the same functionality to
the new script. The purpose of this property is to provide autocomplete
suggestions for dynamic parameters used in `patterns`. For example, the
URL defined as `_cluster/state/{metrics}` has a list of options allowed
for the parameter `metrics`. These options are defined in the json
specs, but unfortunately they are not always translated into concrete
types in the specification repo. In this example, `metrics` is described
as `string | string[]` in the specification repo. Because of that I
added some override files with `url_components` that will not be
available when we switch to the new script and re-generate the
definitions with it.

The logic for generating the url components is the same as for query
parameters. Most changes in this PR is extracting the code so that both
functions `generateQueryParams` and `generateUrlComponents` can share
it. The only difference between query parameters and url components:
with query parameters we keep all properties so that all parameters are
displayed in the autocomplete suggestions, for example `{ param1: '',
param2: '' }` provide information about 2 query parameters, specifically
their names. For url components, the name of the parameter is not
important, because only the values will be displayed for autocompletion.
That is why, we ignore all parameters without known values and only keep
properties like `{ param: ['value1', 'value2'] }`.
@yuliacech yuliacech deleted the console/update_vars branch February 15, 2024 12:05
@yuliacech yuliacech mentioned this pull request Jun 21, 2024
10 tasks
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 ci:cloud-deploy Create or update a Cloud deployment Feature:Console Dev Tools Console Feature release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Console] Update the logic for variables
5 participants