Skip to content

Commit

Permalink
Better error logging in postgres connector (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik authored Apr 22, 2024
1 parent 2004837 commit 42e838c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flow/alerting/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (a *Alerter) sendTelemetryMessage(ctx context.Context, flowName string, mor
_, err := a.telemetrySender.SendMessage(ctx, details, details, telemetry.Attributes{
Level: level,
DeploymentUID: peerdbenv.PeerDBDeploymentUID(),
Tags: []string{flowName},
Tags: []string{flowName, peerdbenv.PeerDBDeploymentUID()},
Type: flowName,
})
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion flow/connectors/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ReplState struct {
}

func NewPostgresConnector(ctx context.Context, pgConfig *protos.PostgresConfig) (*PostgresConnector, error) {
logger := logger.LoggerFromCtx(ctx)
connectionString := shared.GetPGConnectionString(pgConfig)

// create a separate connection pool for non-replication queries as replication connections cannot
Expand All @@ -68,11 +69,13 @@ func NewPostgresConnector(ctx context.Context, pgConfig *protos.PostgresConfig)

tunnel, err := NewSSHTunnel(ctx, pgConfig.SshConfig)
if err != nil {
logger.Error("failed to create ssh tunnel", slog.Any("error", err))
return nil, fmt.Errorf("failed to create ssh tunnel: %w", err)
}

conn, err := tunnel.NewPostgresConnFromConfig(ctx, connConfig)
if err != nil {
logger.Error("failed to create connection", slog.Any("error", err))
return nil, fmt.Errorf("failed to create connection: %w", err)
}

Expand All @@ -82,6 +85,7 @@ func NewPostgresConnector(ctx context.Context, pgConfig *protos.PostgresConfig)

customTypeMap, err := shared.GetCustomDataTypes(ctx, conn)
if err != nil {
logger.Error("failed to get custom type map", slog.Any("error", err))
return nil, fmt.Errorf("failed to get custom type map: %w", err)
}

Expand All @@ -101,7 +105,7 @@ func NewPostgresConnector(ctx context.Context, pgConfig *protos.PostgresConfig)
customTypesMapping: customTypeMap,
metadataSchema: metadataSchema,
hushWarnOID: make(map[uint32]struct{}),
logger: logger.LoggerFromCtx(ctx),
logger: logger,
relationMessageMapping: make(model.RelationMessageMapping),
}, nil
}
Expand Down

0 comments on commit 42e838c

Please sign in to comment.