Skip to content

Commit

Permalink
Merge pull request #15 from rudderlabs/chore.improve-error-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
achettyiitr authored Sep 6, 2023
2 parents a467eff + 2a96bc2 commit 5dd39d3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/

.idea
18 changes: 9 additions & 9 deletions compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type containerConfig struct {
Labels map[string]string `json:"Labels"`
}

// Publishers":[{"URL":"","TargetPort":8123,"PublishedPort":0,"Protocol":"tcp"}
// Publishers: {"URL":"","TargetPort":8123,"PublishedPort":0,"Protocol":"tcp"}
type publisher struct {
Protocol string
URL string
Expand All @@ -73,7 +73,7 @@ func (c *Compose) Stop(ctx context.Context) error {
)
o, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("docker compose down: %w: %s", err, string(o))
return fmt.Errorf("docker compose down: output: %s, err: %w", string(o), err)
}

return nil
Expand All @@ -93,12 +93,12 @@ func (c *Compose) Start(ctx context.Context) error {

o, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("docker compose up: %w: %s", err, string(o))
return fmt.Errorf("docker compose up: output: %s, err: %w", string(o), err)
}

err = c.extractServiceInfo(ctx)
if err != nil {
return err
return fmt.Errorf("docker compose up: extract service info: %w", err)
}

return nil
Expand Down Expand Up @@ -134,7 +134,7 @@ func (c *Compose) Exec(ctx context.Context, service string, command ...string) (
cmd := exec.CommandContext(ctx, "docker", args...)
o, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("docker exec: %w: %s", err, string(o))
return "", fmt.Errorf("docker exec: output: %s, err: %w", string(o), err)
}

return string(o), nil
Expand Down Expand Up @@ -216,7 +216,7 @@ func (c *Compose) config(ctx context.Context, id ...string) ([]containerConfig,
cmd.Env = os.Environ() // TODO: remove this
o, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("docker compose ps: %w: %s", err, o)
return nil, fmt.Errorf("docker inspect: output: %s, err: %w", string(o), err)
}

lines := strings.Split(strings.TrimSpace(string(o)), "\n")
Expand All @@ -225,7 +225,7 @@ func (c *Compose) config(ctx context.Context, id ...string) ([]containerConfig,
for i, l := range lines {
err = json.Unmarshal([]byte(l), &configs[i])
if err != nil {
return nil, fmt.Errorf("unmarshal: %w", err)
return nil, fmt.Errorf("docker inspect: unmarshal: config: %s, err: %w", l, err)
}
}

Expand All @@ -242,13 +242,13 @@ func (c *Compose) ps(ctx context.Context) ([]containerInfo, error) {
)
o, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("docker compose ps: %w", err)
return nil, fmt.Errorf("docker compose ps: output: %s, err: %w", string(o), err)
}

var info []containerInfo
err = json.Unmarshal(o, &info)
if err != nil {
return nil, err
return nil, fmt.Errorf("docker compose ps: unmarshal: output: %s, err: %w", string(o), err)
}

return info, nil
Expand Down
6 changes: 4 additions & 2 deletions compose/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

pgx "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5"
"github.com/rudderlabs/compose-test/compose"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -83,7 +83,9 @@ func sanityTest(t *testing.T, c *compose.Compose) {

conn, err := pgx.Connect(context.Background(), dbURL)
require.NoError(t, err)
defer conn.Close(context.Background())
defer func() {
_ = conn.Close(context.Background())
}()

_, err = conn.Exec(context.Background(), "CREATE TABLE test (id int)")
require.NoError(t, err)
Expand Down
29 changes: 0 additions & 29 deletions compose/testdata/docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ services:
image: rudderlabs/develop-rudder-transformer:master
ports:
- "9090"
databricks-connector:
image: rudderstack/rudder-databricks-connector:v1.3.0
ports:
- "50051"
healthcheck:
test: /bin/grpc_health_probe -addr=localhost:50051
interval: 1s
retries: 25
minio:
image: minio/minio:latest
ports:
Expand All @@ -39,27 +31,6 @@ services:
test: curl --fail http://localhost:9000/minio/health/live || exit 1
interval: 1s
retries: 25
# clickhouse:
# image: yandex/clickhouse-server:21-alpine
# environment:
# - CLICKHOUSE_DB=rudderdb
# - CLICKHOUSE_PASSWORD=rudder-password
# - CLICKHOUSE_USER=rudder
# ports:
# - "9000"
# healthcheck:
# test: wget --no-verbose --tries=1 --spider http://localhost:8123/ping || exit 1
# interval: 1s
# retries: 25
# mssql:
# image: rudderstack/azure-sql-edge:1.0.6
# environment:
# - ACCEPT_EULA=Y
# - SA_PASSWORD=reallyStrongPwd123
# - SA_DB=master
# - SA_USER=SA
# ports:
# - "1433"
zookeeper:
image: zookeeper:3.5
hostname: clickhouse-zookeeper
Expand Down
6 changes: 4 additions & 2 deletions testcompose/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

pgx "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5"
"github.com/stretchr/testify/require"

"github.com/rudderlabs/compose-test/compose"
Expand Down Expand Up @@ -43,7 +43,9 @@ func TestComposeTesting(t *testing.T) {

conn, err := pgx.Connect(context.Background(), dbURL)
require.NoError(t, err)
defer conn.Close(context.Background())
defer func() {
_ = conn.Close(context.Background())
}()

_, err = conn.Exec(context.Background(), "CREATE TABLE test (id int)")
require.NoError(t, err)
Expand Down

0 comments on commit 5dd39d3

Please sign in to comment.