From 2a107d8774a2d995660b035f9890629285f96d69 Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Mon, 25 Nov 2024 09:35:24 -0800 Subject: [PATCH] reduce db connection test timeout (#49384) --- integration/conntest/database_test.go | 8 ++++---- lib/client/conntest/database.go | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/integration/conntest/database_test.go b/integration/conntest/database_test.go index 4455cdb79f26f..15cecef794cac 100644 --- a/integration/conntest/database_test.go +++ b/integration/conntest/database_test.go @@ -131,12 +131,12 @@ func TestDiagnoseConnectionForPostgresDatabases(t *testing.T) { { Type: types.ConnectionDiagnosticTrace_RBAC_DATABASE, Status: types.ConnectionDiagnosticTrace_SUCCESS, - Details: "A Database Agent is available to proxy the connection to the Database.", + Details: "A Teleport Database Service is available to proxy the connection to the Database.", }, { Type: types.ConnectionDiagnosticTrace_CONNECTIVITY, Status: types.ConnectionDiagnosticTrace_SUCCESS, - Details: "Database is accessible from the Database Agent.", + Details: "Database is accessible from the Teleport Database Service.", }, { Type: types.ConnectionDiagnosticTrace_RBAC_DATABASE_LOGIN, @@ -172,8 +172,8 @@ func TestDiagnoseConnectionForPostgresDatabases(t *testing.T) { Status: types.ConnectionDiagnosticTrace_FAILED, Details: "Database not found. " + "Ensure your role grants access by adding it to the 'db_labels' property. " + - "This can also happen when you don't have a Database Agent proxying the database - " + - "you can fix that by adding the database labels to the 'db_service.resources.labels' in 'teleport.yaml' file of the database agent.", + "This can also happen when you don't have a Teleport Database Service proxying the database - " + + "you can fix that by adding the database labels to the 'db_service.resources.labels' in 'teleport.yaml' file of the Database Service.", }, }, }, diff --git a/lib/client/conntest/database.go b/lib/client/conntest/database.go index 3aa3284718768..40d2a9785c21c 100644 --- a/lib/client/conntest/database.go +++ b/lib/client/conntest/database.go @@ -31,6 +31,7 @@ import ( apiclient "github.com/gravitational/teleport/api/client" "github.com/gravitational/teleport/api/client/proto" + apidefaults "github.com/gravitational/teleport/api/defaults" "github.com/gravitational/teleport/api/types" "github.com/gravitational/teleport/lib/client" "github.com/gravitational/teleport/lib/client/conntest/database" @@ -136,8 +137,8 @@ func (s *DatabaseConnectionTester) TestConnection(ctx context.Context, req TestC types.ConnectionDiagnosticTrace_RBAC_DATABASE, "Database not found. "+ "Ensure your role grants access by adding it to the 'db_labels' property. "+ - "This can also happen when you don't have a Database Agent proxying the database - "+ - "you can fix that by adding the database labels to the 'db_service.resources.labels' in 'teleport.yaml' file of the database agent.", + "This can also happen when you don't have a Teleport Database Service proxying the database - "+ + "you can fix that by adding the database labels to the 'db_service.resources.labels' in 'teleport.yaml' file of the Database Service.", trace.NotFound("%s not found", req.ResourceName), ) if err != nil { @@ -167,7 +168,7 @@ func (s *DatabaseConnectionTester) TestConnection(ctx context.Context, req TestC if _, err := s.appendDiagnosticTrace(ctx, connectionDiagnosticID, types.ConnectionDiagnosticTrace_RBAC_DATABASE, - "A Database Agent is available to proxy the connection to the Database.", + "A Teleport Database Service is available to proxy the connection to the Database.", nil, ); err != nil { return nil, trace.Wrap(err) @@ -184,7 +185,9 @@ func (s *DatabaseConnectionTester) TestConnection(ctx context.Context, req TestC return nil, trace.Wrap(err) } - if pingErr := databasePinger.Ping(ctx, ping); pingErr != nil { + pingCtx, cancel := context.WithTimeout(ctx, apidefaults.DefaultIOTimeout) + defer cancel() + if pingErr := databasePinger.Ping(pingCtx, ping); pingErr != nil { connDiag, err := s.handlePingError(ctx, connectionDiagnosticID, pingErr, databasePinger) return connDiag, trace.Wrap(err) } @@ -273,7 +276,7 @@ func newPing(alpnProxyAddr, databaseUser, databaseName string) (database.PingPar func (s DatabaseConnectionTester) handlePingSuccess(ctx context.Context, connectionDiagnosticID string) (types.ConnectionDiagnostic, error) { if _, err := s.appendDiagnosticTrace(ctx, connectionDiagnosticID, types.ConnectionDiagnosticTrace_CONNECTIVITY, - "Database is accessible from the Database Agent.", + "Database is accessible from the Teleport Database Service.", nil, ); err != nil { return nil, trace.Wrap(err) @@ -341,12 +344,12 @@ func (s DatabaseConnectionTester) handlePingError(ctx context.Context, connectio return connDiag, nil } - if databasePinger.IsConnectionRefusedError(pingErr) { + if databasePinger.IsConnectionRefusedError(pingErr) || strings.Contains(pingErr.Error(), "context deadline exceeded") { connDiag, err := s.appendDiagnosticTrace(ctx, connectionDiagnosticID, types.ConnectionDiagnosticTrace_CONNECTIVITY, - "There was a connection problem between the Database Agent and the Database. "+ - "Ensure the Database is running and accessible from the Database Agent.", + "There was a connection problem between the Teleport Database Service and the database. "+ + "Ensure the database is running and accessible from the Database Service over the network.", pingErr, ) if err != nil {