-
-
Notifications
You must be signed in to change notification settings - Fork 214
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 upstream strategy strict
#1093
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1093 +/- ##
==========================================
+ Coverage 93.63% 93.94% +0.30%
==========================================
Files 66 68 +2
Lines 5345 5513 +168
==========================================
+ Hits 5005 5179 +174
+ Misses 265 260 -5
+ Partials 75 74 -1
☔ View full report in Codecov by Sentry. |
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 skimmed the code changes and it looks pretty good so far. 👍
I didn't test it yet, but I'll do it next time. Please check my comments 🤝
This sounds reasonable to me. We should document the order in the documentation to avoid confusions. |
53a1a59
to
bba6369
Compare
Great. I'll add it to the docs 👍 How should we handle my last concern regarding this:
For now, I think it would be sufficient to add this to the docs. In the future we could validate the config and check for colliding CIDRs & clientNames at startup. WDYT? |
I think it would also be reasonable to also log it as a warning. It would speed up support cases where users report unexpected behavior(in my opinion). |
82bb831
to
4879980
Compare
I tested different configs and it worked fine 👍 Please resolve open points from discussions above. @kwitsch Do you have any comments regarding this implementation? |
I'm currently unable to test it but I've read it and it looks ok so far. My only cretic would be the change of return types from struct pointers to interfaces as you also mentioned. |
Haven't been able to look at this since I don't have any computer time ATM and for a couple more weeks.
Instinctively I'd expect the client names to override CIDR since it seems more specific, so could be used to override a CIDR. |
Same as me. Without the GitHub App on my phone I couldn't participate at all right now...
Would have said the same but I also don't use it. 🤷♂️ |
Makes sense. Client names should have higher priority. 👍 |
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.
Open changes as discussed:
- Change return types to struct pointers
- Hostnames should have priority over CIDR
6377628
to
c87e6ea
Compare
c87e6ea
to
3de2e0c
Compare
I've refactored every resolver (except upstream_tree & rewriter as they can also return a different type) to return a struct pointer |
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'm still unable to test it but I've read the code and cross checked against the previous behavior.
The changes are reasonable, documented and covered with unit tests.
👍
@DerRockWolf: Great job, thank you! |
This PR contains a lot of changes (sorry for that 😅)
and closes:
Summary of changes:
upstreams.strategy
fieldstrict
upstream resolver (with tests & docs)upstreamTreeResolver
(as suggested by @ThinkChaos in Split ParallelBest into "client groups" and "parallel" #1001)Chained(Resolver)
and use type assertion in tests if neededDetails regarding the
upstremTreeResolver
and the "select group by client"The
upstreamTreeResolver
contains branches (map[string]Resolver
), each branch represents a groups upstream resolver. TheupstreamTreeResolver
just callsResolve
of the respective branch/group upstream resolver determined by theupstreamGroupByClient
func.Currently a client can "belong" to multiple groups and therefore would use all configured upstream servers (including possible duplicates) where the group name is matching clientName, IP or CIDR.
This behavior is IMO is really confusing and also not really documented or ensured via tests.
I've therefore replaced the "select upstream servers by client" to a "select group by client". It follows a strict order (currently: 1. exact IP, 2. CIDR, 3. clientNames). This would maybe be a breaking change for setups where clients are currently matching multiple groups and would use servers from the matching groups.
What do you think about my proposed change?
Additionally if someone would use e.g. two CIDR groups where an IP matches both, we can't ensure that really the first (as specified in the config file) is used as the
config.upstreams.groups
field is a map. Same applies forclientNames
.Do you want me to also extend the
server.go
and/or e2e tests? If so please tell me where and to what extend.TODOs: