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

Feature/476 multiple nics #757

Closed
wants to merge 15 commits into from

Conversation

ofauchon
Copy link
Contributor

@ofauchon ofauchon commented Sep 6, 2018

This branch enables a new option "--nic" option

When using this flag eg: --nic eth0" , all the ips of the given interface will be used randomly when running injection scripts.

I have tested this feature with interfaces having 100+ IPv4 addresses.
IPv6 needs more testing though.

Support for multiple nics ( --nic eth0, eth1,eth2...etc) will come on a second time

@codecov-io
Copy link

codecov-io commented Sep 6, 2018

Codecov Report

Merging #757 into master will decrease coverage by 0.2%.
The diff coverage is 9.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #757      +/-   ##
==========================================
- Coverage   72.12%   71.91%   -0.21%     
==========================================
  Files         131      131              
  Lines        9621     9653      +32     
==========================================
+ Hits         6939     6942       +3     
- Misses       2268     2295      +27     
- Partials      414      416       +2
Impacted Files Coverage Δ
lib/options.go 91.06% <0%> (-1.03%) ⬇️
cmd/options.go 66.94% <100%> (+0.56%) ⬆️
js/runner.go 77.25% <3.44%> (-8.29%) ⬇️

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 3506ee1...c6fc6fb. Read the comment docs.

Copy link
Member

@na-- na-- left a comment

Choose a reason for hiding this comment

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

Sorry for the super late review... I found a few issues that I've mentioned in the in-line code comments. Also, I'm not sure how easy this would be to test with some sort of automated tests, but hopefully there's a way to do that.

js/runner.go Outdated Show resolved Hide resolved
js/runner.go Outdated
// Select given interface
targetIf, err := net.InterfaceByName(ifaceName)
if err != nil {
return nil
Copy link
Member

Choose a reason for hiding this comment

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

This type of error suppression throughout the whole function probably isn't the best way to go about things. If some user gives a wrong interface name, then I'd expect k6 to emit an error, not silently continue working without using the specified interface

js/runner.go Outdated Show resolved Hide resolved
js/runner.go Outdated
localTCPAddr := net.TCPAddr{
IP: a.IP,
}
r.BaseDialer.LocalAddr = &localTCPAddr
Copy link
Member

Choose a reason for hiding this comment

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

This seems problematic... Take a look at the k6 architecture - the Runner (r here) is the thing that spawns VUs, so if you change the LocalAddr of its BaseDialer every time, you're just changing the BaseDialer all VUs would use. I think that with the current code all VUs will end up having the same LocalAddr configured, instead the thing that should be changed is probably the VU-local Dialer that's configured a few lines below this.

js/runner.go Outdated Show resolved Hide resolved
js/runner.go Outdated Show resolved Hide resolved
@ofauchon
Copy link
Contributor Author

Hi na,

I agree this contribution is much more a proof of concept than a finished implementation .
I appreciate your detailed review specially the focus on architecture.

I'll clean up the code and PR again as soon as possible.

Thanks

Olivier Fauchon

dialer := &netext.Dialer{
Dialer: r.BaseDialer,
Resolver: r.Resolver,
Blacklist: r.Bundle.Options.BlacklistIPs,
Hosts: r.Bundle.Options.Hosts,
}
if r.Bundle.Options.Nic.Valid {
randAddr, err := getRandomIP(r.Bundle.Options.Nic.ValueOrZero())

Choose a reason for hiding this comment

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

declaration of "err" shadows declaration at js/runner.go:157 (from govet)

cmd/options.go Outdated Show resolved Hide resolved
@@ -113,6 +115,43 @@ func (r *Runner) NewVU(samplesOut chan<- stats.SampleContainer) (lib.VU, error)
return lib.VU(vu), nil
}

func getRandomIP(ifacesList string) (*net.IPAddr, error) {

var addresses []net.Addr

Choose a reason for hiding this comment

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

Consider preallocating addresses (from prealloc)

cmd/options.go Outdated Show resolved Hide resolved
@na--
Copy link
Member

na-- commented Mar 22, 2019

Hey, @ofauchon, if you're picking this up again, you might want to merge master in your branch, since there have been quite a few changes there. You can also rebase your commits on top of master and force-push, though I'd prefer the merge, so we don't mangle the code review.

cmd/options.go Outdated Show resolved Hide resolved
@CLAassistant
Copy link

CLAassistant commented Aug 4, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ofauchon
Copy link
Contributor Author

ofauchon commented Sep 8, 2020

Hi,

In september 2018, I published the initial multi-nic patch.

Thanks to @srguglielmo contributions, more enhancement and fixes were done.

But I'm surprised this PR could not be merged since Sep. 2018.

Do you think it would be possible to spend more time @k6 to help contributors finish these zombies PR.

Thanks in advance.

Olivier

@na--
Copy link
Member

na-- commented Sep 8, 2020

@ofauchon, hi, and sorry for the long delays here 😞 IIRC this PR was a victim of our focus on #1007... 😞 And it probably should have been closed when #1293 was opened, so I'm going to do so now.

The current consensus is that k6 shouldn't accept --nic at all, but source IP ranges instead: #1293 (comment). That offers a better UX, cross-platform support, and more flexibility. If you or @srguglielmo are not interested in making that change, we've internally decided that someone from the k6 team is going to implement it, since we also want to finally have this functionality in k6 v0.29.0 (slated for release mid-November). We'll still give the both of you and @divfor credit in the release notes, for working on this feature.

@na-- na-- closed this Sep 8, 2020
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.

5 participants