Skip to content

Add select var type#486

Merged
jillguyonnet merged 10 commits intoelastic:mainfrom
jillguyonnet:jillguyonnet/add-select-var-type
Mar 21, 2023
Merged

Add select var type#486
jillguyonnet merged 10 commits intoelastic:mainfrom
jillguyonnet:jillguyonnet/add-select-var-type

Conversation

@jillguyonnet
Copy link
Contributor

@jillguyonnet jillguyonnet commented Mar 2, 2023

What does this PR do?

This PR adds a new select var type for integrations.

As integrations need a way to provide a list of options for the select, it also adds an options property which is only relevant to select types.

The options property is conditionally added, such as it is required when type is select and 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 options array 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 to test/packages that prove my change is effective.

Related issues

@elasticmachine
Copy link

elasticmachine commented Mar 2, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-03-21T14:43:01.869+0000

  • Duration: 9 min 18 sec

Test stats 🧪

Test Results
Failed 0
Passed 716
Skipped 0
Total 716

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine
Copy link

elasticmachine commented Mar 2, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (7/7) 💚
Files 69.231% (18/26) 👍
Classes 77.143% (27/35) 👍
Methods 56.757% (63/111) 👍 0.793
Lines 42.727% (564/1320) 👍 0.622
Conditionals 100.0% (0/0) 💚

Copy link
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

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

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

func TestValidateFile(t *testing.T) {

@jillguyonnet
Copy link
Contributor Author

@mrodm I pushed a change with conditional subschema thanks to your suggestion and help 🙂

jillguyonnet added a commit to elastic/kibana that referenced this pull request Mar 9, 2023
## 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:
Copy link
Member

Choose a reason for hiding this comment

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

Oh nice, maybe we can use if/then in more cases where we are validating with go now.

Comment on lines +82 to +98
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)
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit. I tend to prefer to avoid elses and have each exception on its own if:

Suggested change
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.

Suggested change
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)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I think your first suggestion reads better, I've pushed the change.

bmorelli25 pushed a commit to bmorelli25/kibana that referenced this pull request Mar 10, 2023
## 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>
@jillguyonnet jillguyonnet force-pushed the jillguyonnet/add-select-var-type branch from e563700 to f216adf Compare March 20, 2023 14:10
jsoriano
jsoriano previously approved these changes Mar 21, 2023
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

👍

mrodm
mrodm previously approved these changes Mar 21, 2023
Copy link
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +123 to +129
"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",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect, this is more helpful for the developers 👍

@jillguyonnet jillguyonnet dismissed stale reviews from mrodm and jsoriano via 85aff87 March 21, 2023 14:42
@jillguyonnet jillguyonnet force-pushed the jillguyonnet/add-select-var-type branch from f216adf to 85aff87 Compare March 21, 2023 14:42
@jillguyonnet
Copy link
Contributor Author

Thank you for the review @jsoriano and @mrodm 👍 I've rebased the branch to update spec/changelog.yml.

@jillguyonnet jillguyonnet merged commit 6e1c4be into elastic:main Mar 21, 2023
@jillguyonnet jillguyonnet deleted the jillguyonnet/add-select-var-type branch March 21, 2023 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants