Skip to content

Commit

Permalink
fix malformed bunyan error log
Browse files Browse the repository at this point in the history
  • Loading branch information
negrel committed Aug 29, 2024
1 parent 14f4937 commit e778a73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 12 additions & 2 deletions pkg/clickhouse/ch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ type Ch struct {

// ProvideCh define a wire provider for Ch.
func ProvideCh(logger zerolog.Logger, cfg config.Clickhouse, source source.Driver) Ch {

// Execute migrations.
db := connectSql(logger, cfg, 5)
migrate(logger, db, cfg.Database, source)
sqlLogger := logger.With().
Str("service", "clickhouse_provider").
Str("protocol", "http").
Logger()
db := connectSql(sqlLogger, cfg, 5)
migrate(sqlLogger, db, cfg.Database, source)

logger = logger.With().
Str("service", "clickhouse_provider").
Str("protocol", "native").
Logger()

// Connect using native interface.
conn := Connect(logger, cfg, 5)
Expand Down
7 changes: 4 additions & 3 deletions pkg/clickhouse/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/ClickHouse/clickhouse-go/v2"
_ "github.com/ClickHouse/clickhouse-go/v2"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
"github.com/prismelabs/analytics/pkg/config"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -57,11 +56,13 @@ func Connect(logger zerolog.Logger, cfg config.Clickhouse, maxRetry int) (conn d

conn, err = clickhouse.Open(&options)
if err != nil {
logger.Error().Err(err).Msg("connection failed")
continue
}

err = conn.Ping(context.Background())
if err != nil {
logger.Error().Err(err).Msg("ping failed")
continue
}

Expand Down Expand Up @@ -103,13 +104,13 @@ func connectSql(logger zerolog.Logger, cfg config.Clickhouse, maxRetry int) *sql

db, err = sql.Open("clickhouse", connectionString)
if err != nil {
logger.Error().Err(err).Send()
logger.Error().Err(err).Msg("connection failed")
continue
}

err = db.Ping()
if err != nil {
logger.Error().Err(err).Send()
logger.Error().Err(err).Msg("ping failed")
continue
}

Expand Down

0 comments on commit e778a73

Please sign in to comment.