Skip to content

[Synthtrace] Fix wrong url build in the Kibana client#217678

Merged
jennypavlova merged 8 commits intoelastic:mainfrom
jennypavlova:217529-fix-wrong-path-in-fleet-url
Apr 10, 2025
Merged

[Synthtrace] Fix wrong url build in the Kibana client#217678
jennypavlova merged 8 commits intoelastic:mainfrom
jennypavlova:217529-fix-wrong-path-in-fleet-url

Conversation

@jennypavlova
Copy link
Member

@jennypavlova jennypavlova commented Apr 9, 2025

Relates to #217529
#216653
#216844

Summary

The issue was introduced in the PR here: basically, the URL will look like: http:/user:pass@localhost:5620/api/fleet/epm/packages/apm?prerelease=false because Path.join will strip the / which is needed in this case - this URL is also passed to getFetchAgent. This PR will fix this issue.

@jennypavlova jennypavlova added release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. backport:version Backport to applied version labels v9.1.0 v8.19.0 labels Apr 9, 2025
@jennypavlova jennypavlova self-assigned this Apr 9, 2025
@jennypavlova jennypavlova requested a review from a team April 9, 2025 13:22
@jennypavlova jennypavlova requested a review from a team as a code owner April 9, 2025 13:22
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@rmyz rmyz left a comment

Choose a reason for hiding this comment

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

LGTM


fetch<T>(pathname: string, options: KibanaClientFetchOptions): Promise<T> {
const url = Path.join(this.target, pathname);
const url = new URL(`${this.target}${pathname}`).toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

i used Path.join() to prevent double slashes from leaking in - e.g. people sometimes define target with a trailing slash or not. Ideally that would still be the case. I didn't know about Path.join() stripping slashes in the protocol! I'm not sure why this wasn't caught earlier though. Why did this test start failing just now and how is the target configured in the test?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this is the actual issue, because http:/ strangely enough seem to work with both curl and fetch, node-fetch, and axios:

 ~/dev/kibana   node -e ' fetch("http:/example.com").then(res => console.log(res.status));'                                                                                                                                ✔  20.18.2 Node  15:35:01 
200
 ~/dev/kibana   node -e ' require("axios").get("http:/example.com").then(res => console.log(res.status));'                                                                                                             127 ✘  20.18.2 Node  15:36:00 
200
 ~/dev/kibana  curl -sS -D - http:/example.com -o /dev/null                                                                                                                                                               ✔  20.18.2 Node  15:34:46 
HTTP/1.1 200 OK
Content-Type: text/html
ETag: "84238dfc8092e5d9c0dac8ef93371a07:1736799080.121134"
Last-Modified: Mon, 13 Jan 2025 20:11:20 GMT
Cache-Control: max-age=1256
Date: Wed, 09 Apr 2025 13:35:01 GMT
Content-Length: 1256
Connection: keep-alive

Copy link
Member Author

@jennypavlova jennypavlova Apr 9, 2025

Choose a reason for hiding this comment

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

i used Path.join() to prevent double slashes from leaking in - e.g. people sometimes define target with a trailing slash or not.

I see - I saw we put the / in the path but it could be the case, I agree. I will add a logic for that so strip the slash at the beginning of the pathname and set it in the URL 👍

Why did this test start failing just now and how is the target configured in the test?

I don't know why it fails now, I saw that today. Probably because it was not failing to get the prerelease=true and it happened in prerelease=false (locally, the prerelease=true case is passing - I couldn't manage to make it fail in order to fully reproduce this)

Copy link
Contributor

Choose a reason for hiding this comment

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

I did see synthtrace failling locally but that seemed like the usual longstanding issue we have around cutting release branches (which sucks and we should fix it).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if this is the actual issue, because http:/ strangely enough seem to work with both curl and fetch, node-fetch, and axios:

Not enough to build the URL here -> I got an error 'Invalid Url' when I tried to "force" it to fail

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a 500, so I would try to find logs, but honestly, I think the last two tests are an intermittent failure that we always have when we cut a release branch, and Kibana moves to a new version, and it tries to fetch a package that has not been updated in the registry yet.

Thanks for the suggestion! Unfortunately, I couldn't find anything useful in the build logs linked in the issue 😞 I saw that this fallback was created to actually fix some of those failures by using an older version - so it could be that they will fail because this version is not available yet... there's not much we can do in this case, is there? I mean, it doesn't matter which PR broke that flow - it could be that something in the fleet logic changed and this fallback is no longer valid. I just wanted to start fixing potential problems I found when investigating and this was a small thing I decided to fix on the way - if it is not helping, then we can think of something else 🤔

Do we expect the target to also contain parts of the path or only the authority part?

I would expect the target to be http://user:pas@localhost:5620 and nothing after the port, but I think what we try to prevent here is having a target set like http://elastic_serverless:changeme@localhost:5620/ - I wouldn't expect an extra path/search there - right @dgieselaar ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think some people will add a path part, because of basePath. I don't think this needs to be more complicated than joining the strings with a slash and then removing double slashes. But it's also something that I would myself ask an LLM to confirm

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this needs to be more complicated than joining the strings with a slash and then removing double slashes.

@dgieselaar Thanks for the answer! That's fair, considering the way it's used. Having a path there will work with the current join I added here, so we are good. I don't see a reason to include search parameters as a consumer in the target TBH. I wouldn't complicate it more either by handling the search params logic.

Based on GitHub copilot, the target might include also search params as we receive the target as param here and the consumer could send any URL as kibana URL (if kibanaServerUrlWithAuth and kibanaUrlWithAuth include a path and query parameters they will be in the target as well, however I couldn't find any case with params based on the usage the copilot mentioned and I don't think this is an actual use case).

So is this solution OK in this case or do we want to change it?
cc @weltenwort

Copy link
Contributor

Choose a reason for hiding this comment

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

assuming we don't care about search params (which I think is the case), then we can use:

return new URL(pathname, target).toString();

e.g.:

 $ node -e 'console.log(new URL("/foo/bar?prerelease=true", URL.parse("http://example.com:8043/kbn/?blah")).toString());'
 http://example.com:8043/foo/bar?prerelease=true

as you can see it drops the search from the base url, but it handles double slashes

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem was that if you have the base path in the target the pathname will override it. I updated the solution to use a normalization function on top of the initial solution

@weltenwort weltenwort self-requested a review April 9, 2025 13:40
@jennypavlova jennypavlova force-pushed the 217529-fix-wrong-path-in-fleet-url branch from 9501a90 to e7ac2b4 Compare April 9, 2025 13:42

fetch<T>(pathname: string, options: KibanaClientFetchOptions): Promise<T> {
const url = Path.join(this.target, pathname);
const pathnameWithoutLeadingSlash = pathname.startsWith('/') ? pathname.slice(1) : pathname;
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to replace // in the final URL, because this doesn't work if target has a trailing slash

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, thanks - I was not expecting that in the target but it doesn't hurt to have it 👍

@jennypavlova jennypavlova force-pushed the 217529-fix-wrong-path-in-fleet-url branch 3 times, most recently from aa92a64 to bae7bdc Compare April 9, 2025 13:51
@jennypavlova jennypavlova force-pushed the 217529-fix-wrong-path-in-fleet-url branch from bae7bdc to 165d1b6 Compare April 9, 2025 14:18
@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🎉 All tests passed! - kibana-flaky-test-suite-runner#8161

[✅] x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.apm.serverless.config.ts: 25/25 tests passed.
[✅] x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.apm.stateful.config.ts: 25/25 tests passed.

see run history

@jennypavlova jennypavlova requested a review from dgieselaar April 9, 2025 17:18
@jennypavlova jennypavlova force-pushed the 217529-fix-wrong-path-in-fleet-url branch from f588f0d to 8ea3315 Compare April 10, 2025 12:31
@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🟠 Some tests failed. - kibana-flaky-test-suite-runner#8169

[❌] x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.apm.serverless.config.ts: 0/25 tests passed.
[❌] x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.apm.stateful.config.ts: 0/25 tests passed.

see run history

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

1 similar comment
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

8 similar comments
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

15 similar comments
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @jennypavlova

kibanamachine added a commit that referenced this pull request May 28, 2025
…#217877)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Synthtrace] Fix wrong url build in the Kibana client
(#217678)](#217678)

<!--- Backport version: 9.6.6 -->

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

<!--BACKPORT
[{"author":{"name":"jennypavlova","email":"dzheni.pavlova@elastic.co"},"sourceCommit":{"committedDate":"2025-04-10T15:49:50Z","message":"[Synthtrace]
Fix wrong url build in the Kibana client (#217678)\n\nRelates to #217529
\n#216653\n#216844\n\n## Summary\n\nThe issue was introduced in the
[PR\nhere](https://github.com/elastic/kibana/pull/212120/files#diff-34f8e7299930135fd708d98018fc6f4141d6e7c25df7e5fdb90f3472ad0e2948R36):\nbasically,
the URL will look like:
`\nhttp:/user:pass@localhost:5620/api/fleet/epm/packages/apm?prerelease=false`\nbecause
`Path.join` will strip the `/` which is needed in this case -\nthis URL
is also passed to `getFetchAgent`. This PR will fix this
issue.","sha":"7f0a625d6659000c8c50801554c8f618b46cf22a","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:obs-ux-infra_services","backport:version","v9.1.0","v8.19.0"],"title":"[Synthtrace]
Fix wrong url build in the Kibana
client","number":217678,"url":"https://github.com/elastic/kibana/pull/217678","mergeCommit":{"message":"[Synthtrace]
Fix wrong url build in the Kibana client (#217678)\n\nRelates to #217529
\n#216653\n#216844\n\n## Summary\n\nThe issue was introduced in the
[PR\nhere](https://github.com/elastic/kibana/pull/212120/files#diff-34f8e7299930135fd708d98018fc6f4141d6e7c25df7e5fdb90f3472ad0e2948R36):\nbasically,
the URL will look like:
`\nhttp:/user:pass@localhost:5620/api/fleet/epm/packages/apm?prerelease=false`\nbecause
`Path.join` will strip the `/` which is needed in this case -\nthis URL
is also passed to `getFetchAgent`. This PR will fix this
issue.","sha":"7f0a625d6659000c8c50801554c8f618b46cf22a"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217678","number":217678,"mergeCommit":{"message":"[Synthtrace]
Fix wrong url build in the Kibana client (#217678)\n\nRelates to #217529
\n#216653\n#216844\n\n## Summary\n\nThe issue was introduced in the
[PR\nhere](https://github.com/elastic/kibana/pull/212120/files#diff-34f8e7299930135fd708d98018fc6f4141d6e7c25df7e5fdb90f3472ad0e2948R36):\nbasically,
the URL will look like:
`\nhttp:/user:pass@localhost:5620/api/fleet/epm/packages/apm?prerelease=false`\nbecause
`Path.join` will strip the `/` which is needed in this case -\nthis URL
is also passed to `getFetchAgent`. This PR will fix this
issue.","sha":"7f0a625d6659000c8c50801554c8f618b46cf22a"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: jennypavlova <dzheni.pavlova@elastic.co>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants