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

[Synthetics] Allow Synthetics global params to include dashes #178054

Conversation

justinkambic
Copy link
Contributor

@justinkambic justinkambic commented Mar 5, 2024

Summary

Resolves #178053.

Includes - in the regex to filter param names.

Testing

Repro instructions

Testing this is straightforward. You can verify the issue in main or on a cloud instance. If you spin up an ESS that is the most straightforward way.

  1. In Synthetics UI, go to Settings > Global Parameters.
image
  1. Create a param with some dashes in the key, i.e. TEST-PARAMS.

  2. After saving, create an HTTP monitor. In the create form, you can scroll down and expand Advanced options. Include a check for Request headers, specify a header name and for the value, reference your global param using Beats env syntax.

image

You can either use Test Now or wait for it to fail, and you'll see issues get logged similar to what is documented in the attached issue.

Testing the fix

I will create an ESS deployment from this PR that will allow you to follow the same steps above. You should be able to see your monitor either succeed (if the response headers you check for are actually there), or fail for legitimate reasons. But you should not see the error documented in the attached issue, with a message like io:job could not be initialized....

@justinkambic justinkambic added bug Fixes for quality problems that affect the customer experience Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team v8.13.0 v8.14.0 labels Mar 5, 2024
@justinkambic justinkambic self-assigned this Mar 5, 2024
@justinkambic justinkambic requested a review from a team as a code owner March 5, 2024 21:43
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@justinkambic
Copy link
Contributor Author

/oblt-deploy

@@ -51,7 +51,7 @@ export const replaceStringWithParams = (
};

export const hasNoParams = (strVal: string) => {
const shellParamsRegex = /\$\{[a-zA-Z_][a-zA-Z0-9_]*\}/g;
const shellParamsRegex = /\$\{[a-zA-Z_][a-zA-Z0-9_-]*\}/g;
Copy link
Member

Choose a reason for hiding this comment

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

nit: why not keep it simple as \w+|[-_]?

Are we missing any other substution other than _ and - for parameters. Are dots used in beats config? There seems to be :, . used as well - https://www.elastic.co/guide/en/beats/libbeat/current/config-gile-format-refs.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vigneshshanmugam looking at the docs it appears that ? is also possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vigneshshanmugam the : case is already covered by what we have today, you can see a a unit test to this effect in the same file.

Regarding the ?, it pertains to giving a custom error message for beats to output. I don't know if this is a feature we support or not, but doesn't seem super important here.

\w+|[-_] is not a drop-in fix, several of our covered usages fail whereas what I already added works for all of them. Frankly, I do not enjoy fiddling with regex so I am inclined to keep it as it is, to my eye it doesn't really reduce the overall complexity of the code much. I'm happy to put in something cleaner if all the tests keep passing though 😃.

I did add a \. to the character class to indicate the intention that we will support the . character per the case you linked above; I also included a new unit test. LMK if you have any further thoughts, thanks for the feedback 👍.

Copy link
Member

Choose a reason for hiding this comment

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

case is already covered by what we have today,

That is for substituion I beleieve, what if we set the key to test:param in the global params? If it works all good.

I am not sure if params would end up including any characters other than - and _. Just wanted to call out. I am fine with either way. Thanks for taking a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is for substituion I beleieve, what if we set the key to test:param in the global params?

I'll investigate this a bit more 👍. Although, if you choose that as your param name.. I also feel like that is a bad naming strategy.

@justinkambic justinkambic force-pushed the 178053/dashes-are-not-supported-in-global-params-keys branch from 57837c3 to a78a8a5 Compare March 5, 2024 22:34
Copy link
Member

@vigneshshanmugam vigneshshanmugam left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@cauemarcondes cauemarcondes left a comment

Choose a reason for hiding this comment

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

LGTM

@justinkambic justinkambic force-pushed the 178053/dashes-are-not-supported-in-global-params-keys branch from a78a8a5 to 2a02e32 Compare March 6, 2024 16:08
@@ -50,9 +50,10 @@ export const replaceStringWithParams = (
return value as string | null;
};

export const SHELL_PARAMS_REGEX = /\$\{[a-zA-Z_][a-zA-Z0-9\._\-?:]*\}/g;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you export it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the moment thinking of unit testing use case where someone writing a test would want to import it.. but now that I'm typing it I agree it's not needed, as it's encapsulated in the function.

@justinkambic justinkambic force-pushed the 178053/dashes-are-not-supported-in-global-params-keys branch from 2a02e32 to 8992a7a Compare March 7, 2024 03:12
@justinkambic justinkambic enabled auto-merge (squash) March 7, 2024 03:12
@justinkambic justinkambic force-pushed the 178053/dashes-are-not-supported-in-global-params-keys branch from 8992a7a to ac0f551 Compare March 7, 2024 22:04
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

cc @justinkambic

@justinkambic justinkambic merged commit d69045b into elastic:main Mar 7, 2024
18 checks passed
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 7, 2024
…c#178054)

## Summary

Resolves elastic#178053.

Includes `-` in the regex to filter param names.

## Testing

### Repro instructions

Testing this is straightforward. You can verify the issue in `main` or
on a cloud instance. If you spin up an ESS that is the most
straightforward way.

1. In Synthetics UI, go to Settings > Global Parameters.
<img width="831" alt="image"
src="https://github.com/elastic/kibana/assets/18429259/f6dc78f6-6e0c-4b84-a114-9e88266327e9">

2. Create a param with some dashes in the key, i.e. `TEST-PARAMS`.

3. After saving, create an HTTP monitor. In the create form, you can
scroll down and expand `Advanced options`. Include a check for `Request
headers`, specify a header name and for the value, reference your global
param using [Beats env
syntax](https://www.elastic.co/guide/en/beats/libbeat/current/config-file-format-env-vars.html#_examples).
<img width="831" alt="image"
src="https://github.com/elastic/kibana/assets/18429259/bcf3c495-1db8-499c-a394-781564744679">

You can either use Test Now or wait for it to fail, and you'll see
issues get logged similar to what is documented in the attached issue.

### Testing the fix

I will create an ESS deployment from this PR that will allow you to
follow the same steps above. You should be able to see your monitor
either succeed (if the response headers you check for are actually
there), or fail for legitimate reasons. But you should not see the error
documented in the attached issue, with a message like `io:job could not
be initialized...`.

(cherry picked from commit d69045b)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.13

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 8, 2024
…178054) (#178268)

# Backport

This will backport the following commits from `main` to `8.13`:
- [[Synthetics] Allow Synthetics global params to include dashes
(#178054)](#178054)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Justin
Kambic","email":"jk@elastic.co"},"sourceCommit":{"committedDate":"2024-03-07T23:11:59Z","message":"[Synthetics]
Allow Synthetics global params to include dashes (#178054)\n\n##
Summary\r\n\r\nResolves #178053.\r\n\r\nIncludes `-` in the regex to
filter param names.\r\n\r\n## Testing\r\n\r\n### Repro
instructions\r\n\r\nTesting this is straightforward. You can verify the
issue in `main` or\r\non a cloud instance. If you spin up an ESS that is
the most\r\nstraightforward way.\r\n\r\n1. In Synthetics UI, go to
Settings > Global Parameters.\r\n<img width=\"831\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/18429259/f6dc78f6-6e0c-4b84-a114-9e88266327e9\">\r\n\r\n2.
Create a param with some dashes in the key, i.e.
`TEST-PARAMS`.\r\n\r\n3. After saving, create an HTTP monitor. In the
create form, you can\r\nscroll down and expand `Advanced options`.
Include a check for `Request\r\nheaders`, specify a header name and for
the value, reference your global\r\nparam using [Beats
env\r\nsyntax](https://www.elastic.co/guide/en/beats/libbeat/current/config-file-format-env-vars.html#_examples).\r\n<img
width=\"831\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/18429259/bcf3c495-1db8-499c-a394-781564744679\">\r\n\r\nYou
can either use Test Now or wait for it to fail, and you'll see\r\nissues
get logged similar to what is documented in the attached
issue.\r\n\r\n### Testing the fix\r\n\r\nI will create an ESS deployment
from this PR that will allow you to\r\nfollow the same steps above. You
should be able to see your monitor\r\neither succeed (if the response
headers you check for are actually\r\nthere), or fail for legitimate
reasons. But you should not see the error\r\ndocumented in the attached
issue, with a message like `io:job could not\r\nbe
initialized...`.","sha":"d69045bd4d1b013cf92daf4992c836ea623a4968","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:obs-ux-infra_services","v8.13.0","v8.14.0"],"title":"[Synthetics]
Allow Synthetics global params to include
dashes","number":178054,"url":"#178054
Allow Synthetics global params to include dashes (#178054)\n\n##
Summary\r\n\r\nResolves #178053.\r\n\r\nIncludes `-` in the regex to
filter param names.\r\n\r\n## Testing\r\n\r\n### Repro
instructions\r\n\r\nTesting this is straightforward. You can verify the
issue in `main` or\r\non a cloud instance. If you spin up an ESS that is
the most\r\nstraightforward way.\r\n\r\n1. In Synthetics UI, go to
Settings > Global Parameters.\r\n<img width=\"831\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/18429259/f6dc78f6-6e0c-4b84-a114-9e88266327e9\">\r\n\r\n2.
Create a param with some dashes in the key, i.e.
`TEST-PARAMS`.\r\n\r\n3. After saving, create an HTTP monitor. In the
create form, you can\r\nscroll down and expand `Advanced options`.
Include a check for `Request\r\nheaders`, specify a header name and for
the value, reference your global\r\nparam using [Beats
env\r\nsyntax](https://www.elastic.co/guide/en/beats/libbeat/current/config-file-format-env-vars.html#_examples).\r\n<img
width=\"831\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/18429259/bcf3c495-1db8-499c-a394-781564744679\">\r\n\r\nYou
can either use Test Now or wait for it to fail, and you'll see\r\nissues
get logged similar to what is documented in the attached
issue.\r\n\r\n### Testing the fix\r\n\r\nI will create an ESS deployment
from this PR that will allow you to\r\nfollow the same steps above. You
should be able to see your monitor\r\neither succeed (if the response
headers you check for are actually\r\nthere), or fail for legitimate
reasons. But you should not see the error\r\ndocumented in the attached
issue, with a message like `io:job could not\r\nbe
initialized...`.","sha":"d69045bd4d1b013cf92daf4992c836ea623a4968"}},"sourceBranch":"main","suggestedTargetBranches":["8.13"],"targetPullRequestStates":[{"branch":"8.13","label":"v8.13.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"#178054
Allow Synthetics global params to include dashes (#178054)\n\n##
Summary\r\n\r\nResolves #178053.\r\n\r\nIncludes `-` in the regex to
filter param names.\r\n\r\n## Testing\r\n\r\n### Repro
instructions\r\n\r\nTesting this is straightforward. You can verify the
issue in `main` or\r\non a cloud instance. If you spin up an ESS that is
the most\r\nstraightforward way.\r\n\r\n1. In Synthetics UI, go to
Settings > Global Parameters.\r\n<img width=\"831\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/18429259/f6dc78f6-6e0c-4b84-a114-9e88266327e9\">\r\n\r\n2.
Create a param with some dashes in the key, i.e.
`TEST-PARAMS`.\r\n\r\n3. After saving, create an HTTP monitor. In the
create form, you can\r\nscroll down and expand `Advanced options`.
Include a check for `Request\r\nheaders`, specify a header name and for
the value, reference your global\r\nparam using [Beats
env\r\nsyntax](https://www.elastic.co/guide/en/beats/libbeat/current/config-file-format-env-vars.html#_examples).\r\n<img
width=\"831\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/18429259/bcf3c495-1db8-499c-a394-781564744679\">\r\n\r\nYou
can either use Test Now or wait for it to fail, and you'll see\r\nissues
get logged similar to what is documented in the attached
issue.\r\n\r\n### Testing the fix\r\n\r\nI will create an ESS deployment
from this PR that will allow you to\r\nfollow the same steps above. You
should be able to see your monitor\r\neither succeed (if the response
headers you check for are actually\r\nthere), or fail for legitimate
reasons. But you should not see the error\r\ndocumented in the attached
issue, with a message like `io:job could not\r\nbe
initialized...`.","sha":"d69045bd4d1b013cf92daf4992c836ea623a4968"}}]}]
BACKPORT-->

Co-authored-by: Justin Kambic <jk@elastic.co>
eokoneyo pushed a commit to eokoneyo/kibana that referenced this pull request Mar 19, 2024
…c#178054)

## Summary

Resolves elastic#178053.

Includes `-` in the regex to filter param names.

## Testing

### Repro instructions

Testing this is straightforward. You can verify the issue in `main` or
on a cloud instance. If you spin up an ESS that is the most
straightforward way.

1. In Synthetics UI, go to Settings > Global Parameters.
<img width="831" alt="image"
src="https://github.com/elastic/kibana/assets/18429259/f6dc78f6-6e0c-4b84-a114-9e88266327e9">

2. Create a param with some dashes in the key, i.e. `TEST-PARAMS`.

3. After saving, create an HTTP monitor. In the create form, you can
scroll down and expand `Advanced options`. Include a check for `Request
headers`, specify a header name and for the value, reference your global
param using [Beats env
syntax](https://www.elastic.co/guide/en/beats/libbeat/current/config-file-format-env-vars.html#_examples).
<img width="831" alt="image"
src="https://github.com/elastic/kibana/assets/18429259/bcf3c495-1db8-499c-a394-781564744679">

You can either use Test Now or wait for it to fail, and you'll see
issues get logged similar to what is documented in the attached issue.

### Testing the fix

I will create an ESS deployment from this PR that will allow you to
follow the same steps above. You should be able to see your monitor
either succeed (if the response headers you check for are actually
there), or fail for legitimate reasons. But you should not see the error
documented in the attached issue, with a message like `io:job could not
be initialized...`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience release_note:fix Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team v8.13.0 v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Synthetics] Params containing dashes in their key do not parse correctly
7 participants