-
Notifications
You must be signed in to change notification settings - Fork 4.6k
internal/resolver: introduce a new delegating resolver to handle both target URI and proxy address resolution #7857
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
Merged
Merged
Changes from 67 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
bccef6b
delegating resolver
eshitachandwani 6b89e0d
correct comments
eshitachandwani 7c2fb21
correct comments
eshitachandwani e8bb6bc
use env from envconfig
eshitachandwani 36d0573
use env from envconfig
eshitachandwani 5a87284
improve comment and var
eshitachandwani e05a895
add comment
eshitachandwani e724a9a
add newaddress function
eshitachandwani 975e235
add target resolution option and test
eshitachandwani 4b8ade9
correct NewAddress function
eshitachandwani 4ba3578
improve style and comments
eshitachandwani fa55e5b
change variable name
eshitachandwani df11d7c
change variable name
eshitachandwani 8bcf2b6
test example
eshitachandwani a5aeb9a
revert commit
eshitachandwani 47e7936
cleanup test and address comments
eshitachandwani a2e1415
address comments
eshitachandwani df87a68
address comments
eshitachandwani ed3d577
add comment
eshitachandwani dd5bdb3
add comment
eshitachandwani d24ec8b
address comments
eshitachandwani 74c6cd0
address comments
eshitachandwani 31d8c2c
address comments
eshitachandwani 1643768
mae unexported key
eshitachandwani 4a5ab5b
add backoff
eshitachandwani fd061c7
add backoff
eshitachandwani c6dbcbc
Revert "add backoff"
eshitachandwani 2be9db3
revert backoff
eshitachandwani 67e3799
add attributes package
eshitachandwani f5e1d37
correct atrributes
eshitachandwani 019f621
address comments
eshitachandwani 8348b1f
change tests
eshitachandwani f0d5b7b
correct comment
eshitachandwani 4ac31f9
improve code
eshitachandwani ed413f6
improve code
eshitachandwani 402316c
add endpt support
eshitachandwani dea9ddd
improve
eshitachandwani 40f1035
add comment
eshitachandwani 95d98b9
Merge branch 'grpc:master' into delegating_pr
eshitachandwani d5f4d8f
address comments
eshitachandwani e743cbf
add endpnt support
eshitachandwani e008feb
improve endpt
eshitachandwani 4aea07d
add test for endpoints
eshitachandwani ed345a1
add test for endpoints
eshitachandwani 7f416b0
condition and comment for endpoint
eshitachandwani e68d5de
remove condition
eshitachandwani 8848105
refactors
eshitachandwani 61edca1
correct
eshitachandwani a01cc7a
change endpoint support
eshitachandwani 845680d
correct endpoint behvaiour for DNS
eshitachandwani c752bd8
correct endpoint behvaiour for DNS
eshitachandwani d53100c
address comments
eshitachandwani 99292ea
improve
eshitachandwani 74b3cf6
improve
eshitachandwani c745144
improve
eshitachandwani 628a2a4
test for addresses
eshitachandwani eeae936
correct var names
eshitachandwani bc0adeb
rerun test
eshitachandwani 9c2ce28
address comments
eshitachandwani 4482e51
address comments
eshitachandwani 2bafe77
improve comment
eshitachandwani a0a2e50
address comments
eshitachandwani ca2cc24
remove internal
eshitachandwani 1f1e7f5
add no op res
eshitachandwani 402badf
comments
eshitachandwani 163ad20
improve
eshitachandwani db8b92c
Merge branch 'grpc:master' into delegating_pr
eshitachandwani 6623eb5
Merge branch 'grpc:master' into delegating_pr
eshitachandwani c4bde98
address comments
eshitachandwani 1c4b416
change target resolver state to pointer
eshitachandwani 5dc893c
tests
eshitachandwani 69253c7
pointer
eshitachandwani c5f8d6f
address comments
eshitachandwani bbea8c4
formatting
eshitachandwani fc2c41f
address comments
eshitachandwani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * | ||
| * Copyright 2024 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| // Package proxyattributes contains functions for getting and setting proxy | ||
| // attributes like the CONNECT address and user info. | ||
| package proxyattributes | ||
|
|
||
| import ( | ||
| "net/url" | ||
|
|
||
| "google.golang.org/grpc/resolver" | ||
| ) | ||
|
|
||
| type keyType string | ||
|
|
||
| const proxyOptionsKey = keyType("grpc.resolver.delegatingresolver.proxyOptions") | ||
|
|
||
| // Options holds the proxy connection details needed during the CONNECT | ||
| // handshake. It includes the user information and the connect address. | ||
| type Options struct { | ||
| User url.Userinfo | ||
| ConnectAddr string | ||
| } | ||
|
|
||
| // Set returns a copy of addr with attributes containing the provided user | ||
| // and connect address, which are needed during the CONNECT handshake for a | ||
| // proxy connection. | ||
dfawley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| func Set(addr resolver.Address, opts Options) resolver.Address { | ||
| addr.Attributes = addr.Attributes.WithValue(proxyOptionsKey, opts) | ||
| return addr | ||
| } | ||
|
|
||
| // Get returns the Options for the proxy [resolver.Address] and a boolean | ||
| // value representing if the attribute is present or not. | ||
| func Get(addr resolver.Address) (Options, bool) { | ||
| if a := addr.Attributes.Value(proxyOptionsKey); a != nil { | ||
| return a.(Options), true | ||
| } | ||
| return Options{}, false | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * | ||
| * Copyright 2024 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package proxyattributes | ||
|
|
||
| import ( | ||
| "net/url" | ||
| "testing" | ||
|
|
||
| "google.golang.org/grpc/attributes" | ||
| "google.golang.org/grpc/internal/grpctest" | ||
| "google.golang.org/grpc/resolver" | ||
| ) | ||
|
|
||
| type s struct { | ||
| grpctest.Tester | ||
| } | ||
|
|
||
| func Test(t *testing.T) { | ||
| grpctest.RunSubTests(t, s{}) | ||
| } | ||
|
|
||
| // Tests that Get returns a valid proxy attribute. | ||
| func (s) TestGet(t *testing.T) { | ||
| user := url.UserPassword("username", "password") | ||
| tests := []struct { | ||
| name string | ||
| addr resolver.Address | ||
| wantConnectAddr string | ||
| wantUser url.Userinfo | ||
| wantAttrPresent bool | ||
| }{ | ||
| { | ||
| name: "connect_address_in_attribute", | ||
| addr: resolver.Address{ | ||
| Addr: "test-address", | ||
| Attributes: attributes.New(proxyOptionsKey, Options{ | ||
| ConnectAddr: "proxy-address", | ||
| }), | ||
| }, | ||
| wantConnectAddr: "proxy-address", | ||
| wantAttrPresent: true, | ||
| }, | ||
| { | ||
| name: "user_in_attribute", | ||
| addr: resolver.Address{ | ||
| Addr: "test-address", | ||
| Attributes: attributes.New(proxyOptionsKey, Options{ | ||
| User: *user, | ||
| }), | ||
| }, | ||
| wantUser: *user, | ||
| wantAttrPresent: true, | ||
| }, | ||
| { | ||
| name: "no_attribute", | ||
| addr: resolver.Address{Addr: "test-address"}, | ||
| wantAttrPresent: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| gotOption, attrPresent := Get(tt.addr) | ||
| if attrPresent != tt.wantAttrPresent { | ||
| t.Errorf("Get(%v) = %v, want %v", tt.addr, attrPresent, tt.wantAttrPresent) | ||
| } | ||
|
|
||
| if gotOption.ConnectAddr != tt.wantConnectAddr { | ||
| t.Errorf("ConnectAddr(%v) = %v, want %v", tt.addr, gotOption.ConnectAddr, tt.wantConnectAddr) | ||
| } | ||
|
|
||
| if gotOption.User != tt.wantUser { | ||
| t.Errorf("User(%v) = %v, want %v", tt.addr, gotOption.User, tt.wantUser) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Tests that Set returns a copy of addr with attributes containing correct | ||
| // user and connect address. | ||
| func (s) TestSet(t *testing.T) { | ||
| addr := resolver.Address{Addr: "test-address"} | ||
| pOpts := Options{ | ||
| User: *url.UserPassword("username", "password"), | ||
| ConnectAddr: "proxy-address", | ||
| } | ||
|
|
||
| // Call Set and validate attributes | ||
| populatedAddr := Set(addr, pOpts) | ||
| gotOption, attrPresent := Get(populatedAddr) | ||
| if !attrPresent { | ||
| t.Errorf("Get(%v) = %v, want %v ", populatedAddr, attrPresent, true) | ||
| } | ||
| if got, want := gotOption.ConnectAddr, pOpts.ConnectAddr; got != want { | ||
| t.Errorf("Unexpected ConnectAddr proxy atrribute = %v, want %v", got, want) | ||
| } | ||
| if got, want := gotOption.User, pOpts.User; got != want { | ||
| t.Errorf("unexpected User proxy attribute = %v, want %v", got, want) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.