Skip to content

Commit

Permalink
feat:(observability): fix tracing order after otelsql
Browse files Browse the repository at this point in the history
  • Loading branch information
cchenggit committed Nov 28, 2024
2 parents 79ef232 + c45a38e commit 55b0ef5
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 148 deletions.
1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ version: 2
before:
hooks:
- go mod tidy
- go generate ./...

builds:
- env:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22 AS build-env
FROM golang:1.23 AS build-env

WORKDIR /go/src/webhookx-io/webhookx

Expand Down
4 changes: 4 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func (app *Application) NodeID() string {
return config.NODE
}

func (app *Application) Config() *config.Config {
return app.cfg
}

// Start starts application
func (app *Application) Start() error {
app.mux.Lock()
Expand Down
4 changes: 4 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ database:
username: webhookx
password:
database: webhookx
parameters: 'application_name=webhookx&sslmode=disable&connect_timeout=10' # The connection uri parameters.
# See https://www.postgresql.org/docs/current/libpq-connect.html
max_pool_size: 40 # The maximum number of connections
max_lifetime: 1800 # The maximum lifetime (in seconds) of a connection

redis:
host: localhost
Expand Down
18 changes: 12 additions & 6 deletions config/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"fmt"
"github.com/XSAM/otelsql"
"time"
)

type DatabaseConfig struct {
Expand All @@ -12,17 +13,24 @@ type DatabaseConfig struct {
Username string `yaml:"username" default:"webhookx"`
Password string `yaml:"password" default:""`
Database string `yaml:"database" default:"webhookx"`
Parameters string `yaml:"parameters" default:"application_name=webhookx&sslmode=disable&connect_timeout=10"`
MaxPoolSize uint32 `yaml:"max_pool_size" default:"40" envconfig:"MAX_POOL_SIZE"`
MaxLifetime uint32 `yaml:"max_life_time" default:"1800" envconfig:"MAX_LIFETIME"`
tracingEnabled bool
}

func (cfg DatabaseConfig) GetDSN() string {
return fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=disable",
dsn := fmt.Sprintf("postgres://%s:%s@%s:%d/%s",
cfg.Username,
cfg.Password,
cfg.Host,
cfg.Port,
cfg.Database,
)
if len(cfg.Parameters) > 0 {
dsn = fmt.Sprintf("%s?%s", dsn, cfg.Parameters)
}
return dsn
}

func (cfg DatabaseConfig) Validate() error {
Expand Down Expand Up @@ -53,13 +61,11 @@ func (cfg *DatabaseConfig) InitSqlDB() (*sql.DB, error) {
}

db, err := sql.Open(driverName, cfg.GetDSN())
// db.SetMaxOpenConns(100)
// db.SetMaxIdleConns(100)
// db.SetConnMaxLifetime(time.Hour)
// db.SetConnMaxIdleTime(time.Hour)
if err != nil {
return nil, err
}

Check warning on line 66 in config/database.go

View check run for this annotation

Codecov / codecov/patch

config/database.go#L65-L66

Added lines #L65 - L66 were not covered by tests

db.SetMaxOpenConns(int(cfg.MaxPoolSize))
db.SetMaxIdleConns(int(cfg.MaxPoolSize))
db.SetConnMaxLifetime(time.Second * time.Duration(cfg.MaxLifetime))
return db, nil
}
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
webhookx-migration:
image: "webhookx/webhookx:0.2.1"
image: "webhookx/webhookx:0.3.0"
container_name: webhookx-migration
environment:
WEBHOOKX_DATABASE_HOST: webhookx-database
Expand All @@ -13,7 +13,7 @@ services:
condition: service_healthy

webhookx:
image: "webhookx/webhookx:0.2.1"
image: "webhookx/webhookx:0.3.0"
container_name: webhookx
environment:
WEBHOOKX_DATABASE_HOST: webhookx-database
Expand All @@ -25,6 +25,8 @@ services:
WEBHOOKX_ADMIN_LISTEN: 0.0.0.0:8080
WEBHOOKX_WORKER_ENABLED: true
WEBHOOKX_PROXY_LISTEN: 0.0.0.0:8081
WEBHOOKX_PROXY_QUEUE_REDIS_HOST: redis
WEBHOOKX_PROXY_QUEUE_REDIS_PORT: 6379
ports:
- "8080:8080"
- "8081:8081"
Expand Down
64 changes: 31 additions & 33 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/webhookx-io/webhookx

go 1.22.0
go 1.23

require (
github.com/Masterminds/squirrel v1.5.4
Expand All @@ -13,35 +13,39 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/onsi/ginkgo/v2 v2.21.0
github.com/onsi/gomega v1.35.1
github.com/pkg/errors v0.9.1
github.com/redis/go-redis/v9 v9.6.2
github.com/redis/go-redis/v9 v9.7.0
github.com/satori/go.uuid v1.2.0
github.com/segmentio/ksuid v1.0.4
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/pdata v1.17.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0
go.opentelemetry.io/contrib/propagators/autoprop v0.55.0
go.opentelemetry.io/otel v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0
go.opentelemetry.io/otel/metric v1.31.0
go.opentelemetry.io/otel/sdk v1.31.0
go.opentelemetry.io/otel/sdk/metric v1.31.0
go.opentelemetry.io/otel/trace v1.31.0
go.uber.org/mock v0.4.0
go.opentelemetry.io/contrib/propagators/autoprop v0.57.0
go.opentelemetry.io/otel v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0
go.opentelemetry.io/otel/metric v1.32.0
go.opentelemetry.io/otel/sdk v1.32.0
go.opentelemetry.io/otel/sdk/metric v1.32.0
go.uber.org/mock v0.5.0
go.uber.org/zap v1.27.0
google.golang.org/grpc v1.67.1
gopkg.in/yaml.v3 v3.0.1
)

require github.com/felixge/httpsnoop v1.0.4 // indirect

require (
go.opentelemetry.io/contrib/propagators/aws v1.32.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.32.0 // indirect
go.opentelemetry.io/contrib/propagators/jaeger v1.32.0 // indirect
go.opentelemetry.io/contrib/propagators/ot v1.32.0 // indirect
)

require (
github.com/XSAM/otelsql v0.35.0
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
Expand All @@ -54,35 +58,29 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240910150728-a0b0bb1d4134 // indirect
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opentelemetry.io/contrib/propagators/aws v1.30.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.30.0 // indirect
go.opentelemetry.io/contrib/propagators/jaeger v1.30.0 // indirect
go.opentelemetry.io/contrib/propagators/ot v1.30.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0
go.opentelemetry.io/otel/trace v1.32.0
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/tools v0.25.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.26.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/protobuf v1.35.1 // indirect
)
Loading

0 comments on commit 55b0ef5

Please sign in to comment.