-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] Ensure correct encoding of body in callApi #51600
Conversation
// Need an empty body to pass route validation | ||
const body = isGet | ||
const bodyObject = isGet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should bodies in GET requests not be stringified?
btw. What do you think about a small rename:
const bodyObject = isGet | |
const bodyObject = isGetRequest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIR, body
is not allowed in GET requests per NP requirements. All of this is to work around schema limitations, so hopefully we can get rid of it when #50179 is addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIR, body is not allowed in GET requests per NP requirements
In that case we'll never send body
with GET requests, right? So having this check won't matter afaict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eg. we could always just JSON.stringify(body)
afaict - or will that cause validation issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might not be understanding what you mean. This code adds { body: { ... } }
to all non-GET requests (either empty or whatever it was given). We need at least an empty body
value to pass the current NP request validation. Do you see a way we can do this without checking the request method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking something like this. So not depending in the http verb but only whether there is a body or not:
return {
...rest,
...(fetchOptions.body ? JSON.stringify(body) : {}),
query: {
...fetchOptions.query,
...(debugEnabled ? { _debug: true } : {})
}
But if NP requires a body
for all requests then that's not possible (although that sounds like an odd requirement)
x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts
Outdated
Show resolved
Hide resolved
💚 Build Succeeded
|
Fixes issue with the ML and Watcher integrations where the body ended up being encoded to JSON twice. Introduced in 06bee60.
Co-Authored-By: Søren Louv-Jansen <sorenlouv@gmail.com>
dcb2fc0
to
d2f6c34
Compare
💚 Build Succeeded |
Going to close this in favor of an incoming PR that addresses some other issues as well. |
Fixes issue with the ML and Watcher integrations where the body ended up being encoded to JSON twice. Introduced in 06bee60.