-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Conversation
@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()); |
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.
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 { |
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.
We need a try-catch clause here, otherwise if there is an error while loading definitions, the process fails silently.
Pinging @elastic/platform-deployment-management (Team:Deployment Management) |
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.
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.
}, | ||
// composable index templates | ||
// currently seems to be unused, but that is a useful functionality |
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.
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 🤔
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.
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.
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.
Sounds good. Thanks for the explanation and looking into this!
Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>
Thanks a lot for the review, @alisonelizabeth! |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
## 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'] }`.
## 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>
## 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'] }`.
## 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'] }`.
Summary
Fixes #160539
This PR updates the logic for dynamic parameters in the Console autocomplete engine in preparation for the new script.
Changes
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.indices
- is deleted and onlyindex
is used instead. Originally, there was a minor difference betweenindices
andindex
: 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
andtypes
- deleted becauseindex 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
andusername
- 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 listnodes
- 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.variables
todynamic parameters
in the Console README file: I first used the wordvariables
in readme for the values defined in the filekb.js
. But then variables support was added to Console and there were several sections in the readme using the wordvariables
for different concepts. Since in the autocomplete engine code, the function is calledparametrizedComponentFactories
I think calling these valuesdynamic parameters
makes more sense and avoids confusion.