diff --git a/pkg/ccl/sqlproxyccl/backend_dialer.go b/pkg/ccl/sqlproxyccl/backend_dialer.go index 1e0bc5db34e8..a8aff0f7dea2 100644 --- a/pkg/ccl/sqlproxyccl/backend_dialer.go +++ b/pkg/ccl/sqlproxyccl/backend_dialer.go @@ -38,7 +38,7 @@ var BackendDial = func( if err != nil { return nil, withCode( errors.Wrap(err, "unable to reach backend SQL server"), - codeBackendDown) + codeBackendDialFailed) } // Ensure that conn is closed whenever BackendDial returns an error. @@ -54,18 +54,18 @@ var BackendDial = func( if err := binary.Write(conn, binary.BigEndian, pgSSLRequest); err != nil { return nil, withCode( errors.Wrap(err, "sending SSLRequest to target server"), - codeBackendDown) + codeBackendDialFailed) } response := make([]byte, 1) if _, err = io.ReadFull(conn, response); err != nil { return nil, withCode( errors.New("reading response to SSLRequest"), - codeBackendDown) + codeBackendDialFailed) } if response[0] != pgAcceptSSLRequest { return nil, withCode( errors.New("target server refused TLS connection"), - codeBackendRefusedTLS) + codeBackendDialFailed) } conn = tls.Client(conn, tlsConfig.Clone()) } @@ -74,7 +74,7 @@ var BackendDial = func( if _, err := conn.Write(msg.Encode(nil)); err != nil { return nil, withCode( errors.Wrapf(err, "relaying StartupMessage to target server %v", serverAddress), - codeBackendDown) + codeBackendDialFailed) } return conn, nil } diff --git a/pkg/ccl/sqlproxyccl/backend_dialer_test.go b/pkg/ccl/sqlproxyccl/backend_dialer_test.go index affffd31c2f6..35c3f2c20acb 100644 --- a/pkg/ccl/sqlproxyccl/backend_dialer_test.go +++ b/pkg/ccl/sqlproxyccl/backend_dialer_test.go @@ -94,22 +94,22 @@ func TestBackendDialTLS(t *testing.T) { name: "tenant10To11", addr: sql11.SQLAddr(), tenantID: 10, - errCode: codeBackendDown, + errCode: codeBackendDialFailed, }, { name: "tenant11To10", addr: sql10.SQLAddr(), tenantID: 11, - errCode: codeBackendDown, + errCode: codeBackendDialFailed, }, { name: "tenant10ToStorage", addr: storageServer.ServingSQLAddr(), tenantID: 10, - errCode: codeBackendDown, + errCode: codeBackendDialFailed, }, { name: "tenantWithNodeIDToStoage", addr: storageServer.ServingSQLAddr(), tenantID: uint64(storageServer.NodeID()), - errCode: codeBackendDown, + errCode: codeBackendDialFailed, }} for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/ccl/sqlproxyccl/connector.go b/pkg/ccl/sqlproxyccl/connector.go index 3c5470c052a5..66d70655e15d 100644 --- a/pkg/ccl/sqlproxyccl/connector.go +++ b/pkg/ccl/sqlproxyccl/connector.go @@ -365,7 +365,7 @@ func (c *connector) dialSQLServer( conn, err := BackendDial(c.StartupMsg, serverAssignment.Addr(), tlsConf) if err != nil { - if getErrorCode(err) == codeBackendDown { + if getErrorCode(err) == codeBackendDialFailed { return nil, markAsRetriableConnectorError(err) } return nil, err diff --git a/pkg/ccl/sqlproxyccl/connector_test.go b/pkg/ccl/sqlproxyccl/connector_test.go index 5c7a3f968cfe..7e170037079d 100644 --- a/pkg/ccl/sqlproxyccl/connector_test.go +++ b/pkg/ccl/sqlproxyccl/connector_test.go @@ -888,14 +888,14 @@ func TestConnector_dialSQLServer(t *testing.T) { require.Equal(t, c.StartupMsg, msg) require.Equal(t, "127.0.0.2:4567", serverAddress) require.Nil(t, tlsConfig) - return nil, withCode(errors.New("bar"), codeBackendDown) + return nil, withCode(errors.New("bar"), codeBackendDialFailed) }, )() sa := balancer.NewServerAssignment(tenantID, tracker, nil, "127.0.0.2:4567") defer sa.Close() conn, err := c.dialSQLServer(sa) - require.EqualError(t, err, "codeBackendDown: bar") + require.EqualError(t, err, "codeBackendDialFailed: bar") require.True(t, isRetriableConnectorError(err)) require.Nil(t, conn) }) diff --git a/pkg/ccl/sqlproxyccl/error.go b/pkg/ccl/sqlproxyccl/error.go index 0586f9dbdde1..3c03fefccab5 100644 --- a/pkg/ccl/sqlproxyccl/error.go +++ b/pkg/ccl/sqlproxyccl/error.go @@ -50,13 +50,9 @@ const ( // on the client's session parameters. codeParamsRoutingFailed - // codeBackendDown indicates an error establishing or maintaining a connection - // to the backend SQL server. - codeBackendDown - - // codeBackendRefusedTLS indicates that the backend SQL server refused a TLS- - // enabled SQL connection. - codeBackendRefusedTLS + // codeBackendDialFailed indicates an error establishing a connection + // between the proxy and the backend SQL server. + codeBackendDialFailed // codeBackendDisconnected indicates that the backend disconnected (with a // connection error) while serving client traffic. diff --git a/pkg/ccl/sqlproxyccl/errorcode_string.go b/pkg/ccl/sqlproxyccl/errorcode_string.go index 59edaaaf85c4..9896fcc70913 100644 --- a/pkg/ccl/sqlproxyccl/errorcode_string.go +++ b/pkg/ccl/sqlproxyccl/errorcode_string.go @@ -17,13 +17,12 @@ func _() { _ = x[codeUnexpectedInsecureStartupMessage-6] _ = x[codeUnexpectedStartupMessage-7] _ = x[codeParamsRoutingFailed-8] - _ = x[codeBackendDown-9] - _ = x[codeBackendRefusedTLS-10] - _ = x[codeBackendDisconnected-11] - _ = x[codeClientDisconnected-12] - _ = x[codeProxyRefusedConnection-13] - _ = x[codeExpiredClientConnection-14] - _ = x[codeUnavailable-15] + _ = x[codeBackendDialFailed-9] + _ = x[codeBackendDisconnected-10] + _ = x[codeClientDisconnected-11] + _ = x[codeProxyRefusedConnection-12] + _ = x[codeExpiredClientConnection-13] + _ = x[codeUnavailable-14] } func (i errorCode) String() string { @@ -46,10 +45,8 @@ func (i errorCode) String() string { return "codeUnexpectedStartupMessage" case codeParamsRoutingFailed: return "codeParamsRoutingFailed" - case codeBackendDown: - return "codeBackendDown" - case codeBackendRefusedTLS: - return "codeBackendRefusedTLS" + case codeBackendDialFailed: + return "codeBackendDialFailed" case codeBackendDisconnected: return "codeBackendDisconnected" case codeClientDisconnected: diff --git a/pkg/ccl/sqlproxyccl/metrics.go b/pkg/ccl/sqlproxyccl/metrics.go index 28d9ad426847..84cc56ded643 100644 --- a/pkg/ccl/sqlproxyccl/metrics.go +++ b/pkg/ccl/sqlproxyccl/metrics.go @@ -292,11 +292,13 @@ func (metrics *metrics) updateForError(err error) { metrics.ClientDisconnectCount.Inc(1) case codeProxyRefusedConnection: metrics.RefusedConnCount.Inc(1) - metrics.BackendDownCount.Inc(1) case codeParamsRoutingFailed, codeUnavailable: metrics.RoutingErrCount.Inc(1) - metrics.BackendDownCount.Inc(1) - case codeBackendDown: + case codeBackendDialFailed: + // NOTE: Historically, we had the code named codeBackendDown instead of + // codeBackendDialFailed. This has been renamed to codeBackendDialFailed + // for accuracy, and to prevent confusion by developers. We don't rename + // the metrics here as that may break downstream consumers. metrics.BackendDownCount.Inc(1) case codeAuthFailed: metrics.AuthFailedCount.Inc(1) diff --git a/pkg/ccl/sqlproxyccl/metrics_test.go b/pkg/ccl/sqlproxyccl/metrics_test.go index 1cb3fc29b323..adbfdc974273 100644 --- a/pkg/ccl/sqlproxyccl/metrics_test.go +++ b/pkg/ccl/sqlproxyccl/metrics_test.go @@ -35,12 +35,12 @@ func TestMetricsUpdateForError(t *testing.T) { {codeExpiredClientConnection, []*metric.Counter{m.ExpiredClientConnCount}}, - {codeProxyRefusedConnection, []*metric.Counter{m.RefusedConnCount, m.BackendDownCount}}, + {codeProxyRefusedConnection, []*metric.Counter{m.RefusedConnCount}}, - {codeParamsRoutingFailed, []*metric.Counter{m.RoutingErrCount, m.BackendDownCount}}, - {codeUnavailable, []*metric.Counter{m.RoutingErrCount, m.BackendDownCount}}, + {codeParamsRoutingFailed, []*metric.Counter{m.RoutingErrCount}}, + {codeUnavailable, []*metric.Counter{m.RoutingErrCount}}, - {codeBackendDown, []*metric.Counter{m.BackendDownCount}}, + {codeBackendDialFailed, []*metric.Counter{m.BackendDownCount}}, {codeAuthFailed, []*metric.Counter{m.AuthFailedCount}}, } diff --git a/pkg/ccl/sqlproxyccl/proxy.go b/pkg/ccl/sqlproxyccl/proxy.go index a12d8f0726a0..760d29ed0938 100644 --- a/pkg/ccl/sqlproxyccl/proxy.go +++ b/pkg/ccl/sqlproxyccl/proxy.go @@ -34,7 +34,7 @@ func toPgError(err error) *pgproto3.ErrorResponse { switch getErrorCode(err) { // These are send as is. case codeExpiredClientConnection, - codeBackendDown, + codeBackendDialFailed, codeParamsRoutingFailed, codeClientDisconnected, codeBackendDisconnected, diff --git a/pkg/ccl/sqlproxyccl/proxy_handler_test.go b/pkg/ccl/sqlproxyccl/proxy_handler_test.go index 4ee04b3b2a79..43520db04d2c 100644 --- a/pkg/ccl/sqlproxyccl/proxy_handler_test.go +++ b/pkg/ccl/sqlproxyccl/proxy_handler_test.go @@ -595,7 +595,7 @@ func TestBackendDownRetry(t *testing.T) { if callCount >= 3 { directoryServer.DeleteTenant(roachpb.MustMakeTenantID(28)) } - return nil, withCode(errors.New("SQL pod is down"), codeBackendDown) + return nil, withCode(errors.New("SQL pod is down"), codeBackendDialFailed) })() // Valid connection, but no backend server running. @@ -1358,7 +1358,7 @@ func TestDirectoryConnect(t *testing.T) { if countFailures >= 3 { return nil, withCode(errors.New("backend disconnected"), codeBackendDisconnected) } - return nil, withCode(errors.New("backend down"), codeBackendDown) + return nil, withCode(errors.New("backend down"), codeBackendDialFailed) })() // Ensure that Directory.ReportFailure is being called correctly.