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

bugfix#2036 Websocket connections ignore userAgent setting #2151

Merged
merged 11 commits into from
Oct 12, 2021
Merged

bugfix#2036 Websocket connections ignore userAgent setting #2151

merged 11 commits into from
Oct 12, 2021

Conversation

cooliscool
Copy link
Contributor

For fixing the Bug #2036

Changes I have made:

Initializing header variable beforehand to apply the default User-Agent string (example - "k6/0.27.0 (https://k6.io/)") , OR to apply the User-Agent supplied through Options if it exists.

@CLAassistant
Copy link

CLAassistant commented Oct 1, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

Hi @cooliscool,
thanks for your contribution! 🎉

Can you also add a small test for asserting the expected logic with the header assigned, please?

Comment on lines 111 to 114
header := make(http.Header)
tags := state.CloneTags()

header.Set("User-Agent", state.Options.UserAgent.String)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this before CloneTags, please? I would prefer to not have it in the middle between initialization and assignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.! Working on that.

@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2021

Codecov Report

Merging #2151 (6a94f66) into master (42f2e60) will increase coverage by 0.01%.
The diff coverage is 71.42%.

❗ Current head 6a94f66 differs from pull request most recent head 243a3ca. Consider uploading reports for the commit 243a3ca to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2151      +/-   ##
==========================================
+ Coverage   72.71%   72.73%   +0.01%     
==========================================
  Files         184      184              
  Lines       14571    14577       +6     
==========================================
+ Hits        10596    10603       +7     
+ Misses       3333     3331       -2     
- Partials      642      643       +1     
Flag Coverage Δ
ubuntu 72.66% <71.42%> (+0.01%) ⬆️
windows 72.39% <71.42%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cmd/login_cloud.go 0.00% <0.00%> (ø)
cmd/login_influxdb.go 0.00% <0.00%> (ø)
cmd/ui.go 20.61% <0.00%> (ø)
lib/metrics/metrics.go 100.00% <ø> (ø)
ui/form_fields.go 45.71% <0.00%> (ø)
js/modules/k6/ws/ws.go 83.51% <100.00%> (+0.35%) ⬆️
output/csv/config.go 74.00% <100.00%> (+4.23%) ⬆️
output/csv/output.go 67.30% <100.00%> (ø)
output/influxdb/config.go 41.81% <0.00%> (-1.82%) ⬇️
core/engine.go 85.47% <0.00%> (+0.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b068f66...243a3ca. Read the comment docs.

Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

LGTM but I would prefer we have a test(or to expand one) to actually check that it works so we don't break it later

@cooliscool cooliscool requested a review from codebien October 5, 2021 12:30
@cooliscool
Copy link
Contributor Author

cooliscool commented Oct 5, 2021

@codebien @mstoykov

Explanation for the changes made:

I couldn't find a way to retrieve headers of a websocket request that got fired, from within JS environment. ( the actual JS WebSockets API doesn't even have an option to set additional headers. refer this stackoverflow question )
So, I've modified the echo server in httpmultibin.go to send back a Echo-User-Agent header in the response if the User-Agent is set by client. In future this could be expanded add tests for any additional headers sent through k6.

Also kindly let me know if there's a better way to implement this test. I will be happy to make it better.

@cooliscool
Copy link
Contributor Author

I can't figure out why lint is breaking with the message
js/modules/k6/ws/ws_test.go:322:2 paralleltest Function TestSession has missing the call to method parallel in the test run

here:

  1. The same pattern as other sub tests in TestSession is followed in the newly added useragent test.
  2. Tests are running fine.
  3. Putting in a t.Parallel() within t.Run() causes the tests to fail.

@cooliscool cooliscool requested a review from mstoykov October 5, 2021 17:52
@mstoykov
Copy link
Contributor

mstoykov commented Oct 6, 2021

@cooliscool that is because you are adding a test and the linter is now noticing it, while it's not going to complain about old stuff as otherwise it will be complaining constantly :(. We do in general fix linter errors when they start bubbling up, but I think this might be a bit too much.

On the other hand given that I prefer for you to have a custom handler you can just as well move the whole new test in a new Test function instead of creating a subtest for it as well, and add t.Parallel() only for your test :)

@mstoykov mstoykov added this to the v0.35.0 milestone Oct 6, 2021
@cooliscool cooliscool requested a review from mstoykov October 6, 2021 18:53
Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

Apart from moving the changes from httpmultibin to the test that uses them I have no other requests and I think after that we can merge this 🎉

Thanks a lot for all the work 🙇

@cooliscool
Copy link
Contributor Author

Apart from moving the changes from httpmultibin to the test that uses them I have no other requests and I think after that we can merge this tada

Thanks a lot for all the work bow

Thank you!
I have removed modifications made to httpmultibin, and moved test specific code to TestUserAgent.

@cooliscool cooliscool requested a review from mstoykov October 11, 2021 08:24
mstoykov
mstoykov previously approved these changes Oct 11, 2021
Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

LGTM, thanks a lot for all the work 🙇

codebien
codebien previously approved these changes Oct 11, 2021
Copy link
Contributor

@codebien codebien 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
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

LGTM and I have tiny suggestions.

js/modules/k6/ws/ws_test.go Show resolved Hide resolved
js/modules/k6/ws/ws_test.go Outdated Show resolved Hide resolved
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Thanks, I have some minor suggestions.

js/modules/k6/ws/ws_test.go Outdated Show resolved Hide resolved
js/modules/k6/ws/ws_test.go Outdated Show resolved Hide resolved
@cooliscool cooliscool requested a review from inancgumus October 12, 2021 08:47
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

LGTM, thx!

@na-- na-- merged commit 055f794 into grafana:master Oct 12, 2021
@cooliscool
Copy link
Contributor Author

I'd like to thank you all for the quick coordination, code review and suggestions. It was a great deal of learning for me.

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.

7 participants