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

Support wildcards in options.hosts #2724

Closed
tom-miseur opened this issue Oct 12, 2022 · 5 comments
Closed

Support wildcards in options.hosts #2724

tom-miseur opened this issue Oct 12, 2022 · 5 comments
Labels
Milestone

Comments

@tom-miseur
Copy link

Feature Description

It would be useful if it were possible to use wildcards in options.hosts in the same way we can with blockHostnames.

So instead of:

export const options = {
  hosts: {
    'subdomain1.k6.io': '1.2.3.4',
    'subdomain2.k6.io': '1.2.3.4',
  },
}

One could specify any subdomain:

export const options = {
  hosts: {
    '*.k6.io': '1.2.3.4',
  },
}

Suggested Solution (optional)

No response

Already existing or connected issues / PRs (optional)

No response

@eugercek
Copy link
Contributor

May I pick this up?

@na--
Copy link
Member

na-- commented Oct 16, 2022

@eugercek, sure, though please make sure to add plenty of tests and ideally also some benchmarks.

@eugercek
Copy link
Contributor

I have some questions to proceed:

  1. I found the Trie implementation from Add blocking by hostname patterns (--block-hostname) #1532 and used the same approach to handle wildcards. But there's one difference options.hosts need to store a (IP or P:Port), so I created a new type. Since we use, don't use 1.18 can't use generics to create a generic type. Is it ok to introduce a new type? The new type: https://github.com/eugercek/k6/blob/wildcard-host/lib/types/addresstrie.go#L35
  • There are two types:
    • matchTrieNode is a trie node with leaf indication as a value( not empty string).
    • AddressTrie wrapper around matchTrieNode.
  1. Currently, hosts doesn't do hostname validation should I add it?

  2. What are your opinions on moving to iterative trie implementation rather than the current recursive approach?

  3. Because of circular dependency, I can't import go.k6.io/k6/lib from the types package. Ideally, using types.NewAddressTrie() with a lib.Hostaddress argument would be better, but not sure how to proceed.

  • Currently, I get it as a string and will handle it in Dialer
  • Maybe can use net.TCPAddr

@na--
Copy link
Member

na-- commented Dec 6, 2022

Closed by #2747

@na-- na-- closed this as completed Dec 6, 2022
@na-- na-- added this to the v0.42.0 milestone Dec 6, 2022
@tom-miseur
Copy link
Author

Thank you very much for your contribution, @eugercek!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants