Conversation
🌐 Coverage report
|
mrodm
left a comment
There was a problem hiding this comment.
That new type select and the related options object look a good approach 👍
Please, update the test package good_v2 to include a new field using this new select type with some options.
And add also some new test "bad" package, for instance, with a package where the options is defined but with another type. It should be added here a new test case
|
@mrodm I pushed a change with conditional subschema thanks to your suggestion and help 🙂 |
## Summary This PR adds support for the new `select` var type in integrations. Context and discussion in related issue: elastic/package-spec#453 Related package-spec PR: elastic/package-spec#486 ### Screenshots #### Before Current `Scope` advanced option in the Elasticsearch metrics settings (free text field): <img width="777" alt="Screenshot 2023-03-08 at 09 37 30" src="https://user-images.githubusercontent.com/23701614/223664474-a5cc5c2b-43c3-451f-9678-30e8c661bfcf.png"> #### After Same option with a select instead: <img width="777" alt="Screenshot 2023-03-08 at 09 36 25" src="https://user-images.githubusercontent.com/23701614/223664552-37c56bff-d6c9-4035-af4c-3a27e355beed.png"> <img width="777" alt="Screenshot 2023-03-08 at 09 36 31" src="https://user-images.githubusercontent.com/23701614/223664581-9e92abfa-6202-433e-b4de-2740fc7c96bc.png"> ### Checklist - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [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 - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
| default: | ||
| description: Default value(s) for variable | ||
| $ref: "#/definitions/input_variable_value" | ||
| if: |
There was a problem hiding this comment.
Oh nice, maybe we can use if/then in more cases where we are validating with go now.
| if strings.Contains(e.Error(), msg.original) { | ||
| processedErrs = append(processedErrs, errors.New(strings.Replace(e.Error(), msg.original, msg.new, 1))) | ||
| } else if !substringInSlice(e.Error(), redundant) { | ||
| processedErrs = append(processedErrs, e) | ||
| } |
There was a problem hiding this comment.
Nit. I tend to prefer to avoid elses and have each exception on its own if:
| if strings.Contains(e.Error(), msg.original) { | |
| processedErrs = append(processedErrs, errors.New(strings.Replace(e.Error(), msg.original, msg.new, 1))) | |
| } else if !substringInSlice(e.Error(), redundant) { | |
| processedErrs = append(processedErrs, e) | |
| } | |
| if strings.Contains(e.Error(), msg.original) { | |
| processedErrs = append(processedErrs, errors.New(strings.Replace(e.Error(), msg.original, msg.new, 1))) | |
| continue | |
| } | |
| if substringInSlice(e.Error(), redundant) { | |
| continue | |
| } | |
| processedErrs = append(processedErrs, e) |
Or maybe use a switch.
| if strings.Contains(e.Error(), msg.original) { | |
| processedErrs = append(processedErrs, errors.New(strings.Replace(e.Error(), msg.original, msg.new, 1))) | |
| } else if !substringInSlice(e.Error(), redundant) { | |
| processedErrs = append(processedErrs, e) | |
| } | |
| switch { | |
| case strings.Contains(e.Error(), msg.original): | |
| processedErrs = append(processedErrs, errors.New(strings.Replace(e.Error(), msg.original, msg.new, 1))) | |
| case substringInSlice(e.Error(), redundant): | |
| default: | |
| processedErrs = append(processedErrs, e) | |
| } |
There was a problem hiding this comment.
Thanks! I think your first suggestion reads better, I've pushed the change.
## Summary This PR adds support for the new `select` var type in integrations. Context and discussion in related issue: elastic/package-spec#453 Related package-spec PR: elastic/package-spec#486 ### Screenshots #### Before Current `Scope` advanced option in the Elasticsearch metrics settings (free text field): <img width="777" alt="Screenshot 2023-03-08 at 09 37 30" src="https://user-images.githubusercontent.com/23701614/223664474-a5cc5c2b-43c3-451f-9678-30e8c661bfcf.png"> #### After Same option with a select instead: <img width="777" alt="Screenshot 2023-03-08 at 09 36 25" src="https://user-images.githubusercontent.com/23701614/223664552-37c56bff-d6c9-4035-af4c-3a27e355beed.png"> <img width="777" alt="Screenshot 2023-03-08 at 09 36 31" src="https://user-images.githubusercontent.com/23701614/223664581-9e92abfa-6202-433e-b4de-2740fc7c96bc.png"> ### Checklist - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [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 - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
e563700 to
f216adf
Compare
| "data_stream/foo_stream/manifest.yml", | ||
| []string{ | ||
| "field streams.0.vars.1: options is required", | ||
| "field streams.0.vars.2.options: Invalid type. Expected: array, given: null", | ||
| "field streams.0.vars.3: Must not be present", | ||
| }, |
There was a problem hiding this comment.
Perfect, this is more helpful for the developers 👍
f216adf to
85aff87
Compare
What does this PR do?
This PR adds a new
selectvar type for integrations.As integrations need a way to provide a list of options for the select, it also adds an
optionsproperty which is only relevant toselecttypes.The
optionsproperty is conditionally added, such as it is required whentypeisselectand required not to be there for other types. The conditional rule to enforce this was inspired from this post.I also added a requirement for the
optionsarray to contain at least one element.Why is it important?
As detailed in #453, the Elasticsearch integration has an setting with only two valid options. Currently, this option is set in the UI via a text field with a description, which is error prone. Adding a select (dropdown) var type will enhance this UX.
Checklist
- [ ] I have added test packages totest/packagesthat prove my change is effective.spec/changelog.yml.Related issues