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

Update Sobek and fix http.File to not use []byte #4009

Merged
merged 2 commits into from
Oct 24, 2024
Merged

Conversation

mstoykov
Copy link
Contributor

@mstoykov mstoykov commented Oct 23, 2024

What?

Update Sobek

Why?

Sobek updates bring fixes from goja for:

  • nesting of destructuring with arrays
  • using slices from go code in js code

Also fix for async errors in modules triggering the promise rejection tracker as well, which will be needed for top-level-await

The changes to handling of slices did break some tests and showcased that k6 was handling http.File().data badly. Previously it was []byte which it really shouldn't be.

This fix makes certain that the provided input is string or ArrayBuffer and keeps it that way until it needs to be written.

This aligns with the documentation as well as removes a source of pure []byte in js code which there shouldn't be any.

Separate PR should be made to drop being able to use common.ToBytes with []byte as that should never happen and should be 100% a bug.

Also made the go code return a pointer as that just makes sense instead of a struct that will get copied.

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

Sobek updates bring fixes from goja for:
- nesting of destructuring with arrays
- using slices from go code in js code

Also fix for async errors in modules triggering the promise rejection
tracker as well, which will be needed for top-level-await

The changes to handling of slices did break some tests and showcased
that k6 was handling `http.File().data` badly. Previously it was
`[]byte` which it really shouldn't be.

This fix makes certain that the provided input is `string` or
`ArrayBuffer` and keeps it that way until it needs to be written.

This aligns with the documentation as well as removes a source of pure
`[]byte` in js code which there shouldn't be any.

Separate PR should be made to drop being able to use `common.ToBytes`
with `[]byte` as that should never happen and should be 100% a bug.

Also made the go code return a pointer as that just makes sense instead
of a struct that will get copied.
@mstoykov mstoykov added breaking change for PRs that need to be mentioned in the breaking changes section of the release notes dependencies Pull requests that update a dependency file labels Oct 23, 2024
@mstoykov mstoykov added this to the v0.55.0 milestone Oct 23, 2024
@mstoykov mstoykov requested a review from a team as a code owner October 23, 2024 15:41
@mstoykov mstoykov requested review from oleiade and olegbespalov and removed request for a team October 23, 2024 15:41
Copy link
Member

@oleiade oleiade left a comment

Choose a reason for hiding this comment

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

Cheers for the detailled explanation 🙇🏻

@mstoykov mstoykov merged commit c6526f1 into master Oct 24, 2024
23 checks passed
@mstoykov mstoykov deleted the updateSobek branch October 24, 2024 13:38
oleiade added a commit that referenced this pull request Nov 11, 2024
oleiade added a commit that referenced this pull request Nov 11, 2024
* Initialize v0.55.0 release notes

* Update release notes for browser 1448

* Update release notes for browser page.on generalization

* Update release notes for browser 1439

* Update release notes for browser 1461

* Update release notes for browser 1496

I'm not yet sure if we should add this PR as it's a part of a bigger
functionality that we expect to have in k6 v0.56.

See the issue for more details:
/~https://github.com/grafana/xk6-browser/issues/1289

* Replace issue 1461 with PR 1462

* release notes: webcrypto RSA support

* release notes: statsd output removal

* release notes: outputs changes

* Add browser related changes to release notes

* Remove template examples from release notes

* Add browser#1457 to release notes

* release notes: updates check recommendation

* Add initial page.on('metric') release note change

* Add issues to the page.on('metric') release note

* release notes: add TLA support section

* release notes: add tracing breaking change and future open ones

* auto-assigner changelog

* check recommendation apply feedback

* fixup! release notes: add tracing breaking change and future open ones

* Apply release notes clean-ups and fillers

* Address wrong formulation of tracing removal

* Update release notes/v0.55.0.md

Co-authored-by: Oleg Bespalov <oleg.bespalov@grafana.com>

* Apply suggestions from code review

Co-authored-by: Ankur <ankur.agarwal@grafana.com>

* Apply suggestions from code review

Co-authored-by: Ankur <ankur.agarwal@grafana.com>

* Apply pull request review suggestions

* Update the page.on('metric') description

* Update release notes/v0.55.0.md

Co-authored-by: Ankur <ankur.agarwal@grafana.com>

* Update page.on example as an expandable detail

* Align last sections format with template

* Update ControlOrMeta description

* Update wording of page.on example

* Apply pull request review suggestions

* Document #4017 bug fix

* Update release notes/v0.55.0.md

Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com>

* Bring minor improvement to #4009

---------

Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
Co-authored-by: Oleg Bespalov <oleg.bespalov@grafana.com>
Co-authored-by: ankur22 <ankur.agarwal@grafana.com>
Co-authored-by: Mihail Stoykov <M.Stoikov@gmail.com>
Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com>
@manjunadh5369
Copy link

manjunadh5369 commented Nov 14, 2024

import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js'

Let documentFile = http.get( )

const fd = new FormData();
fd.append('file', http.file(documentFile.body, ${<file Name>}, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'));

let response = http.put(, fd.body(), {headers: {Content-Type': 'multipart/form-data; boundary=' + fd.boundary}})

The documentFile.body is fetched from the first API, then passed as a file using http.file() in the FormData for the second API request.

While this approach works as expected in the open-source k6 environment, it fails in Grafana Cloud with the error message indicating that the document file appears corrupted and cannot be loaded. Error: {"statusCode":406,"error":"Not Acceptable","message":"The document appears to be corrupted and cannot be loaded."}

It appears that there may be a discrepancy in how file uploads are handled between the open-source version of k6 and Grafana Cloud, particularly after the recent release. Any guidance or updates regarding this issue would be greatly appreciated.

@mstoykov
Copy link
Contributor Author

@manjunadh5369 does it work locally with the latest k6 version v0.55.0 ?

@manjunadh5369
Copy link

manjunadh5369 commented Nov 14, 2024

@mstoykov Oh, I just verified that my local k6 version was not upgraded as I initially thought—it’s still running on v0.51.0. I’ve since upgraded it to the latest version, v0.55.0, and unfortunately, the issue persists locally as well.

Could you please assist me with steps or guidance on how to make this work as it did with the older version? Any help would be greatly appreciated!

@mstoykov
Copy link
Contributor Author

My expectation is that if you set the response to be binary on the request getting the document it will work again.

Can you try it?

You need to set the request params to have responseType equal to binary

@manjunadh5369
Copy link

Thank you very much @mstoykov! It's working now.

@mstoykov
Copy link
Contributor Author

Glad I could help.

To be honest I expect that before that thsi request was jsut a touch corrupted as going to string and back to binary as you did before this last change likely broke the file underneed.

I guess your API either doesn't check the send API that carefully, you were very lucky for the transition to be lossless, or the response is actually text and your API just expects it as binary data for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change for PRs that need to be mentioned in the breaking changes section of the release notes dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants