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] Add logic for query params #160515

Merged
merged 12 commits into from
Jul 5, 2023

Conversation

yuliacech
Copy link
Contributor

@yuliacech yuliacech commented Jun 26, 2023

Summary

Fixes #160528
Follow up to #159241

This PR adds logic for query parameters to the new script generating Console autocomplete definitions from ES specification. The logic is explained in details in the file but here is a short version:

  • Currently, the autocomplete engine only works with url params of 2 types: boolean (__flag__) and a list of options (for example ['all', 'open', 'hidden']). The script will convert all of the url params from the specification into this format: a boolean or a list. If there are no set options for a parameter, but a default value is known, then it will be converted into a list with 1 option, for example ['random'] so that the autocomplete engine will display it as a single suggestion. We also need to convert any numbers to strings, because they won't be displayed otherwise.
  • Endpoints in the specification have a property request which in turn has 2 properties describing url params: attachedBehaviours and query. Both object contain an array of property's each describing a url param. property is configured with either a built in type (string, number, boolean) or defined type, for example ExpandWildcards. By finding the type ExpandWildcards in the specification, we can convert this type to a list of options ['open', 'all', 'none', 'hidden'].

How to test

Similar to #159241, you need to re-generenate the definitions and see if local changes to definitions files make sense.

  1. Checkout the ES specification repo
  2. Run the command node scripts/generate_console_definitions.js --source <ES_SPECIFICATION_REPO> --emptyDest
  3. Check the changes in the folder KIBANA_REPO/src/plugins/console/server/lib/spec_definitions/json/generated

Intended changes to the definitions files

  • Most of endpoints have 4 default url params that previously were not in the definitions files but added to all endpoints in this file. These params are configured in the interface CommonQueryParameters in the specification (see this file).
The interface in the specification
export interface CommonQueryParameters {
  error_trace?: boolean
  filter_path?: string | string[]
  human?: boolean
  pretty?: boolean
}

The converted url params

"error_trace": "__flag__",
"filter_path": [],
"human": "__flag__",
"pretty": "__flag__",
  • Previously existing url_components property in the definitions is deleted and this change will be addressed separately. (not sure it is currently working but added a task to the meta issue)
  • Previously numbers were configured as 0 or 0.0 but that is not currently displayed in suggestions. Instead, the new script converts numbers to strings and if any default value is present, it will be displayed as a suggestion.

@yuliacech yuliacech added Feature:Console Dev Tools Console Feature enhancement New value added to drive a business result 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 Jun 26, 2023
*/

/**
* --------------- THIS FILE IS COPIED FROM ES SPECIFICATION REPO -------------------
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a task to the meta issue to see if we could import the types instead of copying

@yuliacech yuliacech marked this pull request as ready for review June 29, 2023 15:26
@yuliacech yuliacech requested a review from a team as a code owner June 29, 2023 15:26
@elasticmachine
Copy link
Contributor

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

@yuliacech
Copy link
Contributor Author

The current UI for url params is limited so I open this issue to track some improvements.

Copy link
Member

@sabarasaba sabarasaba left a comment

Choose a reason for hiding this comment

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

Nice one @yuliacech! I tested locally following the instructions and everything seems to be working as expected, I checked the changes in the generated file and seems to be correct.

I was wondering though if it would make sense to include the testing commands into the package readme along with some more deets about how this works so that whoever needs to run it or pick this work up has more context (this could totally be done with a separate issue though!)

* - "__flag__" for a boolean (suggesting value 'true' and 'false')
* - list of options in an array, for example ['30s', '-1', '0'], suggesting all 3 values in a list
* If there is only a default value, we need to wrap it in an array, so that this value is displayed in a suggestion (similar to the list).
* Numbers need to be converted to strings, otherwise they are not displayed as suggestions.
Copy link
Member

Choose a reason for hiding this comment

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

interesting! is this a bug from the editor? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't investigated in too much detail, but I added a note about numbers to the issue I opened for the current UI for url params. Basically, autocomplete suggestions currently only work for booleans and lists and could be improved.

return booleanFlagString;
} else {
// if default value, convert to string and put in an array
return serverDefault ? [serverDefault + ''] : '';
Copy link
Member

Choose a reason for hiding this comment

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

nit: serverDefault.toString()


const convertLiteralValue = (type: SpecificationTypes.LiteralValue): UrlParamValue | undefined => {
// convert the value to a string
return [type.value + ''];
Copy link
Member

Choose a reason for hiding this comment

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

nit: type.value.toString()

@yuliacech
Copy link
Contributor Author

Thanks a lot for your review, @sabarasaba! Great idea about the readme file, I updated it with the instructions how to run the command as you suggested.

@yuliacech yuliacech enabled auto-merge (squash) July 5, 2023 09:39
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 14 16 +2
securitySolution 410 414 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 15 17 +2
securitySolution 489 493 +4
total +6

History

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

@yuliacech yuliacech merged commit ee6ca65 into elastic:main Jul 5, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jul 5, 2023
@yuliacech yuliacech deleted the console/new_script_url_params branch February 15, 2024 12:05
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 enhancement New value added to drive a business result 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] Implement the logic for query params
5 participants