## Summary
Fixes https://github.com/elastic/kibana/issues/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](https://github.com/elastic/kibana/issues/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`](
|
||
---|---|---|
.. | ||
bin | ||
lib | ||
index.js | ||
jest.config.js | ||
kibana.jsonc | ||
package.json | ||
README.md |
A mini utility to convert Elasticsearch's REST spec to Console's (Kibana) autocomplete format.
It is used to semi-manually update Console's autocompletion rules.
Retrieving the spec
If you don't have a copy of the Elasticsearch repo on your machine, follow these steps to clone only the rest API specs
mkdir es-spec && cd es-spec
git init
git remote add origin https://github.com/elastic/elasticsearch
git config core.sparsecheckout true
echo "rest-api-spec/src/main/resources/rest-api-spec/api/*\nx-pack/plugin/src/test/resources/rest-api-spec/api/*" > .git/info/sparse-checkout
git pull --depth=1 origin master
Usage
At the root of the Kibana repository, run the following commands:
yarn spec_to_console -g "<ELASTICSEARCH-REPO-FOLDER>/rest-api-spec/src/main/resources/rest-api-spec/api/*" -d "src/plugins/console/server/lib/spec_definitions/json/generated"
Information used in Console that is not available in the REST spec
- Request bodies
- Data fetched at runtime: indices, fields, snapshots, etc
- Ad hoc additions
Updating the script
When converting query params defined in the REST API specs to console autocompletion definitions, the script relies on a set of known conversion rules specified in lib/convert/params.js.
For example, "keep_on_completion":{"type":"boolean"}
from REST API specs is converted to "keep_on_completion": "__flag__"
in console autocomplete definitions.
When an unknown parameter type is encountered in REST API specs, the script will throw an Unexpected type error
and the file lib/convert/params.js needs to be updated by adding a new conversion rule.