-
Notifications
You must be signed in to change notification settings - Fork 1.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
Add Wildcard to Hosts
#2747
Add Wildcard to Hosts
#2747
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2747 +/- ##
==========================================
+ Coverage 75.59% 76.16% +0.57%
==========================================
Files 202 210 +8
Lines 15992 16496 +504
==========================================
+ Hits 12089 12565 +476
- Misses 3151 3157 +6
- Partials 752 774 +22
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Hi @eugercek,
Which check would you suggest? Can you point to me an example, please?
I think it would be a good idea.
As requested in the issue, can you include a benchmark comparison between the old and the current version, please?
We are building k6 binaries using Go 1.19 so generics are already supported. Anyway, generics aren't the unique way of doing abstraction in Go. Which part of Generally speaking, we should share the code between |
My pleasure 😊
We can check if the key is a valid hostname or hostname:port and if the value is valid IP or IP:port. We do this check in Lines 112 to 128 in 8a74171
Moving it.
Sorry forgot that. Adding it.
I noticed that I could use use |
6ef3225
to
863938c
Compare
Hi @codebien, it's ready for your review 🙂 Trie ImplementationI used BenchmarkI couldn't run benchmarks on the master because of a bug, which I fixed in b97e14e, that's the only difference between the real master and the master I used. Also, maybe we can add a benchmark test to GitHub actions just to make sure it's correct atm. A simple Benchmark command git checkout master && go test -v ./... -run=^$ -bench=. -benchmem > old.txt
git checkout wildcard-host && go test -v ./... -run=^$ -bench=. -benchmem > new.txt
benchstat old.txt new.txt > diff.txt Benchmark values diff.txt EDIT: Fixed some minor lint errors. |
It would be also helpful if you could rebase and squash the current commit history and move to something with dedicated commits for:
In this way, reviewing the current code would be easier. But before doing something like this wait for @mstoykov's review because maybe he would ask for a different general idea. |
Yeah - it will be nicer if at least the movement of the HostAddress is done separately. I personally even think you can open a PR for that on it's own and base this one on top of that. On first pass I have a bunch of small questions here and there, but it seems most of them are related to the trie implementation that is in practice the same as before 🤔
We definitely can bump the go version - we do already only build with 1.18+. But I am not certain that it will make that much of a difference. Can you also elaborate on the envconfig issue you are hitting? THere are a couple of comments in the code about it |
Hi @mstoykov Trie ImplementationChanges:
I didn't change any logic in GenericSorry for the generic noise, at first I thought I need to use generics but it's not a must, the current implementation has no problem. envconfigEven though there's no environment variable for the I'll do the following if I understood correctly:
Also, I couldn't get which benchmarks I should run, or if should I create new ones. Can you elaborate on this? |
Hi @eugercek,
This would be great, yes.
If you change the current implementation, I suggest two things:
So, ideally, I expect 3 commits:
The original benchmark request is for creating a comparison between the current way ( |
Hi @codebien I listed what I'll do, I'll update this message when I progress
|
To unit test future commits we need to move `HostAddress` to prevent circular dependency
I'm rebasing this on master and squashing commits to a readable way. Also added Hosts benchmark. |
90fb064
to
cd82d0d
Compare
Benchmark result is sad 😔
Also you can see #2747 (comment) for all benchmarks Benchmark script
|
cd82d0d
to
67782fb
Compare
67782fb
to
120436b
Compare
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.
Excellent work 👏🏻 👏🏻 👏🏻 Really well done!
I've added a bunch of comments. Although I wouldn't consider any of them blocking, I still set them in request changes to ensure they're considered 🙇🏻
lib/types/addresstrie_test.go
Outdated
func TestAddressTrie(t *testing.T) { | ||
t.Parallel() | ||
|
||
at := NewAddressTrie(map[string]HostAddress{ |
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.
Quick uninformed question, do we want to support compound wildcards *.hello.*
. Does it even make sense? I'm not sure. If this is nonsensical or has not added value, please disregard this 👍🏻
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 think there's no practical purpose for it, given DNS is hierarchichal. There would be no reason for someone testing one.hello.com
to use a pattern of *.hello.*
to override resolution of both all subdomains of hello.com
and all possible TLDs matching *.hello.*
. It would complicate the implementation, maybe not by a lot, but still, I don't think this would be needed or worth it.
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.
Ah, one use case I think a second asterisk as suffix would be convenient is for ports. You can already specify a port along with the hostname, e.g. 'test.k6.io:443': '1.2.3.4:8443'
. So maybe someone would find it useful to override only specific ports, like '*.k6.io:24*': '1.2.3.4:8443'
. But I think this would be very niche and complicate the implementation, so let's invoke YAGNI for the second asterisk. :)
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.
IIRC in #1532, only one wildcard is chosen. that's why I implemented it like that. YAGNI is my best friend 😆
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.
Fair enough, thanks a lot for the pointers folks. If everyone's okay with it, let's disregard my question indeed, and reevaluate it a later point if we do end up needing it then 👍🏻 🙇🏻
A question from my side, as I just joined the review. I'm a bit unclear as to what we're benchmarking and what is the underlying objective? |
Hi @oleiade thanks for your detailed review and compliment 🙏🏻 On the benchmark @codebien requested it. I don't have any idea how the information is used 😅 But we're benchmarking previous |
Hey @eugercek @codebien brought me up to speed. From my perspective, and I think @codebien agrees, judging by the numbers the benchmark exhibits, we're good to go with the new trie API that your PR introduces. We judged a 1% performance difference acceptable if we're trading it for convenience and maintainability 👍🏻 |
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.
Great work again @eugercek! 👏 Everything is very comprehensible. 👍
I just left some minor comments, but they're not really blockers.
Apologies for the delay and back and forth with reviewing this. We definitely would like to make it part of the upcoming v0.42.0 release, if you have time to wrap up the minor changes we raised here by early next week. 🙏
I'll push your requested changes today. Thanks for your reviews. 🙏🏻 |
1b1c328
to
bed7cc9
Compare
bed7cc9
to
240b055
Compare
I added all resolved and unresolved changes, waiting for your review 🙇🏻 One criticism from me, new names |
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.
Thanks for the recent changes and your work on this PR @eugercek 🙇 Outstanding work! 👏
Just noticed some tiny nitpicks, but no real blockers from me.
I added the requested changes, sorry for them. Thanks for all of your efforts on this PR 🙏🏻 , I learned a lot on the journey 😄 Hope to see you soon 👋🏻 |
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.
Thanks a lot for your work great work, much appreciated 🙇🏻
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.
Thank you again! 🙇
This documents support for using a wildcard with the `hosts` option, which was recently added in v0.42.0. See grafana/k6#2747.
This documents support for using a wildcard with the `hosts` option, which was recently added in v0.42.0. See grafana/k6#2747.
Implements #2724
The current implementation works and passes all the tests. But I'm not sure about some of the parts, we can discuss them.
Hosts
keys and values before execution? Currently, it fails at runtime.matchTrieNode.match
is a mess 😞 I didn't want to mergeif
s because IMO this is cleaner.HostAddress
because of circular dependency, usednet.TCPAddr
if we moveHostAddress
to types, we can use that instead ofnet.TCPAddr
trieNode
to use it asmatchTrieNode