Skip to content

Commit 8d6e4c9

Browse files
committed
ccl/sqlproxyccl: avoid tenant lookups if we know the type of connection
Previously, we were performing a tenant lookup call before checking on the type of connection. This can be unnecessary (e.g. doing a lookup call for the private endpoints ACL, even if we knew that the connection was a public one). This commit addresses that. Release note: None Epic: none
1 parent 83ee351 commit 8d6e4c9

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

pkg/ccl/sqlproxyccl/acl/cidr_ranges.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ var _ AccessController = &CIDRRanges{}
2828

2929
// CheckConnection implements the AccessController interface.
3030
func (p *CIDRRanges) CheckConnection(ctx context.Context, conn ConnectionTags) error {
31-
tenantObj, err := p.LookupTenantFn(ctx, conn.TenantID)
32-
if err != nil {
33-
return err
34-
}
35-
3631
// Private connections. This ACL is only responsible for public CIDR ranges.
3732
if conn.EndpointID != "" {
3833
return nil
3934
}
4035

36+
tenantObj, err := p.LookupTenantFn(ctx, conn.TenantID)
37+
if err != nil {
38+
return err
39+
}
40+
4141
// Cluster allows public connections, so we'll check allowed CIDR ranges.
4242
if tenantObj.AllowPublicConn() {
4343
ip := net.ParseIP(conn.IP)

pkg/ccl/sqlproxyccl/acl/private_endpoints.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ var _ AccessController = &PrivateEndpoints{}
3737

3838
// CheckConnection implements the AccessController interface.
3939
func (p *PrivateEndpoints) CheckConnection(ctx context.Context, conn ConnectionTags) error {
40-
tenantObj, err := p.LookupTenantFn(ctx, conn.TenantID)
41-
if err != nil {
42-
return err
43-
}
44-
4540
// Public connections. This ACL is only responsible for private endpoints.
4641
if conn.EndpointID == "" {
4742
return nil
4843
}
4944

45+
tenantObj, err := p.LookupTenantFn(ctx, conn.TenantID)
46+
if err != nil {
47+
return err
48+
}
49+
5050
// Cluster allows private connections, so we'll check allowed endpoints.
5151
if tenantObj.AllowPrivateConn() {
5252
for _, endpoints := range tenantObj.AllowedPrivateEndpoints {

pkg/ccl/sqlproxyccl/acl/private_endpoints_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestPrivateEndpoints(t *testing.T) {
4141
return nil, errors.New("foo")
4242
},
4343
}
44-
err := p.CheckConnection(ctx, makeConn(""))
44+
err := p.CheckConnection(ctx, makeConn("foo"))
4545
require.EqualError(t, err, "foo")
4646
})
4747

0 commit comments

Comments
 (0)