Skip to content

Commit 7d8180a

Browse files
authored
[db] Setup go db tracing (#16706)
* [installer] Do not pull blobserve implementation into installer * fix * Fix * [db] Setup go db tracing * fix * Fix * fix * Fix
1 parent de7b4a7 commit 7d8180a

File tree

9 files changed

+105
-19
lines changed

9 files changed

+105
-19
lines changed

components/gitpod-db/go/conn.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"gorm.io/driver/mysql"
1919
"gorm.io/gorm"
2020
"gorm.io/gorm/logger"
21+
"gorm.io/plugin/opentelemetry/tracing"
2122
)
2223

2324
type ConnectionParams struct {
@@ -41,7 +42,7 @@ func ConnectionParamsFromEnv() ConnectionParams {
4142
func Connect(p ConnectionParams) (*gorm.DB, error) {
4243
loc, err := time.LoadLocation("UTC")
4344
if err != nil {
44-
return nil, fmt.Errorf("Failed to load UT location: %w", err)
45+
return nil, fmt.Errorf("Failed to load UTC location: %w", err)
4546
}
4647
cfg := driver_mysql.Config{
4748
User: p.User,
@@ -57,7 +58,7 @@ func Connect(p ConnectionParams) (*gorm.DB, error) {
5758
if p.CaCert != "" {
5859
rootCertPool := x509.NewCertPool()
5960
if ok := rootCertPool.AppendCertsFromPEM([]byte(p.CaCert)); !ok {
60-
log.Fatal("Failed to append custom DB CA cert.")
61+
return nil, fmt.Errorf("failed to append custom certificate for database connection")
6162
}
6263

6364
tlsConfigName := "custom"
@@ -66,13 +67,13 @@ func Connect(p ConnectionParams) (*gorm.DB, error) {
6667
MinVersion: tls.VersionTLS12, // semgrep finding: set lower boundary to exclude insecure TLS1.0
6768
})
6869
if err != nil {
69-
return nil, fmt.Errorf("Failed to register custom DB CA cert: %w", err)
70+
return nil, fmt.Errorf("failed to register custom DB CA cert: %w", err)
7071
}
7172
cfg.TLSConfig = tlsConfigName
7273
}
7374

7475
// refer to https://github.com/go-sql-driver/mysql#dsn-data-source-name for details
75-
return gorm.Open(mysql.Open(cfg.FormatDSN()), &gorm.Config{
76+
conn, err := gorm.Open(mysql.Open(cfg.FormatDSN()), &gorm.Config{
7677
Logger: logger.New(log.Log, logger.Config{
7778
SlowThreshold: 200 * time.Millisecond,
7879
Colorful: false,
@@ -89,4 +90,14 @@ func Connect(p ConnectionParams) (*gorm.DB, error) {
8990
})(),
9091
}),
9192
})
93+
if err != nil {
94+
return nil, fmt.Errorf("failed to open db connection: %w", err)
95+
}
96+
97+
err = conn.Use(tracing.NewPlugin())
98+
if err != nil {
99+
return nil, fmt.Errorf("failed to setup db tracing: %w", err)
100+
}
101+
102+
return conn, nil
92103
}

components/gitpod-db/go/go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@ require (
1616
gorm.io/datatypes v1.0.7
1717
gorm.io/driver/mysql v1.4.4
1818
gorm.io/gorm v1.24.1
19+
gorm.io/plugin/opentelemetry v0.1.1
1920
)
2021

2122
require (
2223
github.com/davecgh/go-spew v1.1.1 // indirect
24+
github.com/go-logr/logr v1.2.3 // indirect
25+
github.com/go-logr/stdr v1.2.2 // indirect
2326
github.com/golang/protobuf v1.5.2 // indirect
2427
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
2528
github.com/jinzhu/inflection v1.0.0 // indirect
2629
github.com/jinzhu/now v1.1.5 // indirect
2730
github.com/pmezard/go-difflib v1.0.0 // indirect
31+
go.opentelemetry.io/otel v1.13.0 // indirect
32+
go.opentelemetry.io/otel/metric v0.36.0 // indirect
33+
go.opentelemetry.io/otel/trace v1.13.0 // indirect
2834
golang.org/x/net v0.4.0 // indirect
2935
golang.org/x/sys v0.3.0 // indirect
3036
golang.org/x/text v0.5.0 // indirect

components/gitpod-db/go/go.sum

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/public-api-server/go.mod

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,23 @@ require (
3838
require (
3939
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
4040
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
41+
github.com/go-logr/logr v1.2.3 // indirect
42+
github.com/go-logr/stdr v1.2.2 // indirect
4143
github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64 // indirect
44+
go.opentelemetry.io/otel v1.13.0 // indirect
45+
go.opentelemetry.io/otel/metric v0.36.0 // indirect
46+
go.opentelemetry.io/otel/trace v1.13.0 // indirect
4247
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
4348
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
4449
gorm.io/driver/mysql v1.4.4 // indirect
50+
gorm.io/plugin/opentelemetry v0.1.1 // indirect
4551
)
4652

4753
require (
4854
github.com/alicebob/miniredis/v2 v2.30.0
4955
github.com/beorn7/perks v1.0.1 // indirect
5056
github.com/blang/semver v3.5.1+incompatible // indirect
51-
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
57+
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
5258
github.com/cespare/xxhash/v2 v2.2.0 // indirect
5359
github.com/configcat/go-sdk/v7 v7.6.0 // indirect
5460
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
@@ -79,7 +85,7 @@ require (
7985
github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect
8086
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
8187
github.com/zitadel/logging v0.3.4 // indirect
82-
go.uber.org/atomic v1.6.0 // indirect
88+
go.uber.org/atomic v1.7.0 // indirect
8389
golang.org/x/net v0.4.0 // indirect
8490
golang.org/x/sys v0.3.0 // indirect
8591
golang.org/x/text v0.5.0 // indirect

components/public-api-server/go.sum

Lines changed: 19 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/usage/go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ require (
2323
github.com/beorn7/perks v1.0.1 // indirect
2424
github.com/cespare/xxhash/v2 v2.1.2 // indirect
2525
github.com/davecgh/go-spew v1.1.1 // indirect
26+
github.com/go-logr/logr v1.2.3 // indirect
27+
github.com/go-logr/stdr v1.2.2 // indirect
2628
github.com/go-sql-driver/mysql v1.6.0 // indirect
2729
github.com/golang/protobuf v1.5.2 // indirect
2830
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
@@ -44,7 +46,10 @@ require (
4446
github.com/spf13/pflag v1.0.5 // indirect
4547
github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect
4648
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
47-
go.uber.org/atomic v1.6.0 // indirect
49+
go.opentelemetry.io/otel v1.13.0 // indirect
50+
go.opentelemetry.io/otel/metric v0.36.0 // indirect
51+
go.opentelemetry.io/otel/trace v1.13.0 // indirect
52+
go.uber.org/atomic v1.7.0 // indirect
4853
golang.org/x/net v0.4.0 // indirect
4954
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
5055
golang.org/x/sys v0.3.0 // indirect
@@ -55,6 +60,7 @@ require (
5560
gopkg.in/yaml.v3 v3.0.1 // indirect
5661
gorm.io/datatypes v1.0.7 // indirect
5762
gorm.io/driver/mysql v1.4.4 // indirect
63+
gorm.io/plugin/opentelemetry v0.1.1 // indirect
5864
)
5965

6066
replace github.com/gitpod-io/gitpod/components/gitpod-db/go => ../gitpod-db/go // leeway

0 commit comments

Comments
 (0)