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

Fix blacklistIPs JS configuration #1004

Merged
merged 4 commits into from
Apr 25, 2019
Merged

Conversation

THoelzel
Copy link
Contributor

Net.IPNet does not support JSON unmarshalling, causing the blacklistIPs
configuration to fail when set through JS.
Fixed by wrapping net.IPNet for the purpose of JSON unmarshalling.

Fixes #973

Net.IPNet does not support JSON unmarshalling, causing the blacklistIPs
configuration to fail when set through JS.
Fixed by wrapping net.IPNet for the purpose of JSON unmarshalling.

Fixes grafana#973
@CLAassistant
Copy link

CLAassistant commented Apr 21, 2019

CLA assistant check
All committers have signed the CLA.

cmd/options.go Outdated Show resolved Hide resolved
lib/options.go Outdated Show resolved Hide resolved
js/runner_test.go Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Apr 21, 2019

Codecov Report

Merging #1004 into master will decrease coverage by 0.15%.
The diff coverage is 85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1004      +/-   ##
==========================================
- Coverage   72.31%   72.16%   -0.16%     
==========================================
  Files         132      131       -1     
  Lines        9703     9635      -68     
==========================================
- Hits         7017     6953      -64     
+ Misses       2272     2268       -4     
  Partials      414      414
Impacted Files Coverage Δ
cmd/options.go 66.37% <0%> (ø) ⬆️
lib/netext/dialer.go 94.36% <100%> (ø) ⬆️
lib/options.go 92.67% <100%> (+0.57%) ⬆️
lib/netext/httpext/tracer.go 96.42% <0%> (-1.79%) ⬇️
core/engine.go 92.99% <0%> (-0.94%) ⬇️
js/modules/k6/http/request.go 79.78% <0%> (-0.71%) ⬇️
lib/netext/httpext/request.go 88.17% <0%> (-0.17%) ⬇️
lib/netext/httpext/error_codes.go 100% <0%> (ø) ⬆️
lib/netext/httpext/compression_type_gen.go

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 3fc300c...820ff7c. Read the comment docs.

@codecov
Copy link

codecov bot commented Apr 21, 2019

Codecov Report

Merging #1004 into master will decrease coverage by 0.2%.
The diff coverage is 65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1004      +/-   ##
==========================================
- Coverage   72.31%   72.11%   -0.21%     
==========================================
  Files         132      131       -1     
  Lines        9703     9640      -63     
==========================================
- Hits         7017     6952      -65     
+ Misses       2272     2271       -1     
- Partials      414      417       +3
Impacted Files Coverage Δ
lib/netext/dialer.go 94.36% <ø> (ø) ⬆️
cmd/options.go 66.37% <0%> (ø) ⬆️
lib/options.go 89.79% <68.42%> (-2.3%) ⬇️
lib/netext/httpext/tracer.go 96.42% <0%> (-1.79%) ⬇️
core/engine.go 92.99% <0%> (-0.94%) ⬇️
js/modules/k6/http/request.go 79.78% <0%> (-0.71%) ⬇️
lib/netext/httpext/request.go 88.17% <0%> (-0.17%) ⬇️
lib/netext/httpext/error_codes.go 100% <0%> (ø) ⬆️
lib/netext/httpext/compression_type_gen.go

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 3fc300c...3c90d08. Read the comment docs.

2 similar comments
@codecov
Copy link

codecov bot commented Apr 21, 2019

Codecov Report

Merging #1004 into master will decrease coverage by 0.2%.
The diff coverage is 65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1004      +/-   ##
==========================================
- Coverage   72.31%   72.11%   -0.21%     
==========================================
  Files         132      131       -1     
  Lines        9703     9640      -63     
==========================================
- Hits         7017     6952      -65     
+ Misses       2272     2271       -1     
- Partials      414      417       +3
Impacted Files Coverage Δ
lib/netext/dialer.go 94.36% <ø> (ø) ⬆️
cmd/options.go 66.37% <0%> (ø) ⬆️
lib/options.go 89.79% <68.42%> (-2.3%) ⬇️
lib/netext/httpext/tracer.go 96.42% <0%> (-1.79%) ⬇️
core/engine.go 92.99% <0%> (-0.94%) ⬇️
js/modules/k6/http/request.go 79.78% <0%> (-0.71%) ⬇️
lib/netext/httpext/request.go 88.17% <0%> (-0.17%) ⬇️
lib/netext/httpext/error_codes.go 100% <0%> (ø) ⬆️
lib/netext/httpext/compression_type_gen.go

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 3fc300c...3c90d08. Read the comment docs.

@codecov
Copy link

codecov bot commented Apr 21, 2019

Codecov Report

Merging #1004 into master will decrease coverage by 0.2%.
The diff coverage is 65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1004      +/-   ##
==========================================
- Coverage   72.31%   72.11%   -0.21%     
==========================================
  Files         132      131       -1     
  Lines        9703     9640      -63     
==========================================
- Hits         7017     6952      -65     
+ Misses       2272     2271       -1     
- Partials      414      417       +3
Impacted Files Coverage Δ
lib/netext/dialer.go 94.36% <ø> (ø) ⬆️
cmd/options.go 66.37% <0%> (ø) ⬆️
lib/options.go 89.79% <68.42%> (-2.3%) ⬇️
lib/netext/httpext/tracer.go 96.42% <0%> (-1.79%) ⬇️
core/engine.go 92.99% <0%> (-0.94%) ⬇️
js/modules/k6/http/request.go 79.78% <0%> (-0.71%) ⬇️
lib/netext/httpext/request.go 88.17% <0%> (-0.17%) ⬇️
lib/netext/httpext/error_codes.go 100% <0%> (ø) ⬆️
lib/netext/httpext/compression_type_gen.go

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 3fc300c...3c90d08. Read the comment docs.

lib/options_test.go Outdated Show resolved Hide resolved
lib/options_test.go Show resolved Hide resolved
lib/options_test.go Show resolved Hide resolved
lib/options_test.go Show resolved Hide resolved
lib/options.go Outdated Show resolved Hide resolved
@THoelzel THoelzel force-pushed the fix/blacklistips-js branch from af2100f to 9ec56c8 Compare April 21, 2019 23:24
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.

Thanks very much for this PR.
It looks awesome and I just have a comment about the not using "ipnet" directly in ParseCIDR.

I was also wondering if we shouldn't be a little bit more backwards compatible as previously ipnet was definitely marshallable and unmarshalable it was just very inconvenient. although I don't know if anyone has actually used it and whether it is worth it. @na-- ?

lib/options.go Outdated
}

return &IPNet{
IPNet: net.IPNet{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this not just ipnet ?

@na--
Copy link
Member

na-- commented Apr 23, 2019

@mstoykov I'm not sure if we need to support the previous (unintentional) ways of encoding and decoding values... I'm not sure if anyone used it, since this bug wasn't reported before I accidentally found it. And in the docs we clearly state that blacklisted IPs have the following JS config format:

export let options = {
    blacklistIPs: ["10.0.0.0/8"]
};

So that was definitely a bug. My only concern is that someone could have used the CLI --blacklist-ip flag and then executed k6 cloud (which bundles the script and all options in a .tar archive like k6 archive). In that case, the tar archive's metadata.json file would have contained something like this:

{
  // ...
  blacklistIPs: [
    {"IP":"10.0.0.0","Mask":"/wAAAA=="}
  ],
  //...
}

Which could have actually worked: https://play.golang.org/p/ZHq6_Rs6YsZ

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.

Thanks for this fix, LGTM, besides that minor simplification of having IPNet be directly type IPNet net.IPNet.

As mentioned in the main thread, we might have to expand the UnmarshalJSON() function a little, to support both strings like "10.0.0.0/8" and JS objects like {"IP":"10.0.0.0","Mask":"/wAAAA=="}, if it turns out that a lot of users used the --blacklist-ip CLI flag before this. However, I think we can do that in a separate PR later, after we find out how many users used this in the cloud execution.

lib/options.go Outdated Show resolved Hide resolved
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.

LGTM

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

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.

blacklistIPs JS configuration isn't parsed correctly
5 participants