Skip to content

Commit ac5da8f

Browse files
authored
feat(option/internaloption): add more option introspection (#3524)
This provides more visibility around directpath enablement
1 parent ce39b40 commit ac5da8f

2 files changed

Lines changed: 45 additions & 5 deletions

File tree

option/internaloption/unsaferesolver.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,20 @@ func (ur *UnsafeResolver) ResolvedGRPCEndpoint() (string, error) {
6060
func (ur *UnsafeResolver) ResolvedGRPCConnIsCustom() bool {
6161
return ur.ds.GRPCConn != nil
6262
}
63+
64+
// ResolvedEnableDirectPath returns whether DirectPath was explicitly enabled.
65+
// This corresponds to the EnableDirectPath option in this package.
66+
//
67+
// This is an EXPERIMENTAL API and may be changed or removed in the future.
68+
func (ur *UnsafeResolver) ResolvedEnableDirectPath() bool {
69+
return ur.ds.EnableDirectPath
70+
}
71+
72+
// ResolvedEnableDirectPathXds returns whether extensible directory service (xDS)
73+
// support was requested as part of direct path enablement. This corresponds to the
74+
// EnableDirectPathXds option in this package.
75+
//
76+
// This is an EXPERIMENTAL API and may be changed or removed in the future.
77+
func (ur *UnsafeResolver) ResolvedEnableDirectPathXds() bool {
78+
return ur.ds.EnableDirectPathXds
79+
}

option/internaloption/unsaferesolver_test.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func TestNewUnsafeResolver(t *testing.T) {
1919
wantResolvedGRPCEndpointAddress string
2020
wantResolvedGRPCEndpointError bool
2121
wantResolvedGRPCConnIsCustom bool
22+
wantResolvedEnableDirectPath bool
23+
wantResolvedEnableDirectPathXds bool
2224
}{
2325
{
2426
desc: "empty",
@@ -55,15 +57,30 @@ func TestNewUnsafeResolver(t *testing.T) {
5557
},
5658
wantResolvedGRPCConnIsCustom: true,
5759
},
60+
{
61+
desc: "direct path plain",
62+
opts: []option.ClientOption{
63+
EnableDirectPath(true),
64+
},
65+
wantResolvedEnableDirectPath: true,
66+
},
67+
{
68+
desc: "direct path xds",
69+
opts: []option.ClientOption{
70+
EnableDirectPath(true),
71+
EnableDirectPathXds(),
72+
},
73+
wantResolvedEnableDirectPath: true,
74+
wantResolvedEnableDirectPathXds: true,
75+
},
5876
} {
5977
t.Run(tc.desc, func(t *testing.T) {
6078
ur, err := NewUnsafeResolver(tc.opts...)
6179
if err != nil {
6280
t.Fatalf("NewUnsafeResolver errored: %v", err)
6381
}
6482
// check ResolvedGRPCConnPoolSize
65-
got := ur.ResolvedGRPCConnPoolSize()
66-
if got != tc.wantResolvedGRPCConnPoolSize {
83+
if got := ur.ResolvedGRPCConnPoolSize(); got != tc.wantResolvedGRPCConnPoolSize {
6784
t.Errorf("ResolveGRPCConnPoolSize: got %d, want %d", got, tc.wantResolvedGRPCConnPoolSize)
6885
}
6986
// check ResolvedGRPCEndpoint
@@ -81,9 +98,15 @@ func TestNewUnsafeResolver(t *testing.T) {
8198
t.Errorf("ResolvedGRPCEndpoint: address mismatch, got %q want %q", gotAddr, tc.wantResolvedGRPCEndpointAddress)
8299
}
83100
// check ResolvedGRPCConnIsCustom
84-
gotCustom := ur.ResolvedGRPCConnIsCustom()
85-
if gotCustom != tc.wantResolvedGRPCConnIsCustom {
86-
t.Errorf("ResolvedGRPCConnIsCustom: got %T want %T", gotCustom, tc.wantResolvedGRPCConnIsCustom)
101+
if gotCustom := ur.ResolvedGRPCConnIsCustom(); gotCustom != tc.wantResolvedGRPCConnIsCustom {
102+
t.Errorf("ResolvedGRPCConnIsCustom: got %t want %t", gotCustom, tc.wantResolvedGRPCConnIsCustom)
103+
}
104+
// check ResolvedGRPCConnIsCustom
105+
if gotDirectPath := ur.ResolvedEnableDirectPath(); gotDirectPath != tc.wantResolvedEnableDirectPath {
106+
t.Errorf("ResolvedEnableDirectPath: got %t want %t", gotDirectPath, tc.wantResolvedEnableDirectPath)
107+
}
108+
if gotDirectPathXds := ur.ResolvedEnableDirectPathXds(); gotDirectPathXds != tc.wantResolvedEnableDirectPathXds {
109+
t.Errorf("ResolvedEnableDirectPathXds: got %t want %t", gotDirectPathXds, tc.wantResolvedEnableDirectPathXds)
87110
}
88111
})
89112
}

0 commit comments

Comments
 (0)