Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: otel tracing #899

Merged
merged 85 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
aa10d2d
init jaeger
JordanSussman Jun 28, 2023
4301fbe
wip: otel gin and gorm
plyr4 Jun 28, 2023
ced4353
wip: added context to ONLY CreateSchedule
plyr4 Jun 28, 2023
fe6b3eb
update docker compose
JordanSussman Jun 28, 2023
7752be5
attempt to mask gorm values
JordanSussman Jun 28, 2023
817dee1
Merge branch 'feat/otel-tracing' of github.com:go-vela/server into fe…
jbrockopp Jun 28, 2023
0799b91
chore: save work
jbrockopp Jun 28, 2023
453d5bc
fix github creds
JordanSussman Jun 28, 2023
52ce323
add back vault
JordanSussman Jun 28, 2023
208410b
make the serviceName as vela-server
JordanSussman Jun 28, 2023
efd0487
pass around the proper context
JordanSussman Jun 29, 2023
646f64b
cli flag and opt-in enable tracing
plyr4 Jun 29, 2023
e78ff24
Merge branch 'feat/otel-tracing' of github.com:go-vela/server into fe…
plyr4 Jun 29, 2023
6f86666
refactor: move code into tracing package
plyr4 Jun 29, 2023
2b7db12
tweak: order of vars and flags
plyr4 Jun 29, 2023
fedcee4
Merge branch 'main' into feat/otel-tracing
JordanSussman Jun 29, 2023
570d148
fix depends on
JordanSussman Jun 29, 2023
120a5e7
make linter happy
JordanSussman Jun 29, 2023
541025d
fix tests
JordanSussman Jun 29, 2023
4fe0b68
chore: merge with main
plyr4 Aug 16, 2023
b695599
enhance: add context to scm
plyr4 Sep 18, 2023
4d42413
chore: replace TODO with ctx
plyr4 Sep 18, 2023
a043735
chore: merge with main
plyr4 Sep 19, 2023
36a7b60
chore: merge with main
plyr4 Sep 19, 2023
304456f
Merge branch 'main' of github.com:go-vela/server into feat/otel-tracing
plyr4 Sep 19, 2023
d43a49d
chore: merge with main
plyr4 Sep 19, 2023
793f17d
chore: merge with main
plyr4 Aug 1, 2024
f597009
chore: rm launch.json
plyr4 Aug 1, 2024
d9da5a3
chore: headers and misc cleanup
plyr4 Aug 1, 2024
7b4e110
chore: golangci
plyr4 Aug 1, 2024
602c183
Merge branch 'main' of github.com:go-vela/server into feat/otel-tracing
plyr4 Aug 13, 2024
da924d5
enhance: supply parent context to all db calls
plyr4 Aug 13, 2024
ae40a65
fix: lint
plyr4 Aug 13, 2024
72636ba
Merge branch 'main' into enhance/db-ctx
plyr4 Aug 15, 2024
eba4507
Merge branch 'main' of github.com:go-vela/server into feat/otel-tracing
plyr4 Aug 19, 2024
e99b4ce
Merge branch 'main' into enhance/db-ctx
plyr4 Aug 19, 2024
15c8115
chore: merge with main
plyr4 Aug 20, 2024
19703bf
Merge branch 'enhance/db-ctx' of github.com:go-vela/server into feat/…
plyr4 Aug 20, 2024
d921b3e
chore: merge with enhance/db-ctx
plyr4 Aug 20, 2024
e590f23
enhance: simple head samplers for ratio and rate limit
plyr4 Aug 21, 2024
c22be46
Merge branch 'main' of github.com:go-vela/server into feat/otel-tracing
plyr4 Aug 21, 2024
3aa5b8d
enhance: customizable config, code cleanup, middleware
plyr4 Aug 21, 2024
868fa97
fix: lint
plyr4 Aug 21, 2024
02899ae
enhance: customizable resource and span attributes for restrictive co…
plyr4 Aug 26, 2024
14619d2
fix: min tls version
plyr4 Aug 26, 2024
3d273ce
trigger pipeline
plyr4 Aug 26, 2024
0397f5a
fix: compose options
plyr4 Aug 26, 2024
fcc8b23
fix: add disabled tracing config to db test
plyr4 Aug 26, 2024
bac7ab8
Merge branch 'main' into feat/otel-tracing
plyr4 Aug 26, 2024
fba0da2
Merge branch 'main' into feat/otel-tracing
plyr4 Aug 26, 2024
33bf135
fix: remove unused var
plyr4 Aug 26, 2024
50e82aa
Merge branch 'feat/otel-tracing' of github.com:go-vela/server into fe…
plyr4 Aug 26, 2024
093b912
Merge branch 'main' into feat/otel-tracing
plyr4 Sep 4, 2024
069c4d7
chore: go mod tidy
plyr4 Sep 4, 2024
85b67b1
chore: revert compose var
plyr4 Sep 4, 2024
37a6e9b
Merge branch 'main' into feat/otel-tracing
plyr4 Sep 5, 2024
0aa5de5
chore: remove bogus file
plyr4 Sep 5, 2024
938fe6b
Merge branch 'feat/otel-tracing' of github.com:go-vela/server into fe…
plyr4 Sep 5, 2024
e945cd8
Merge branch 'main' into feat/otel-tracing
KellyMerrick Sep 6, 2024
3cb9bb3
Merge branch 'main' into feat/otel-tracing
plyr4 Sep 9, 2024
ee8a03a
feat: tracing middleware tests
plyr4 Sep 9, 2024
cd973d5
chore: lint
plyr4 Sep 9, 2024
c95193b
Merge branch 'main' into feat/otel-tracing
plyr4 Sep 11, 2024
7b27836
enhance: configurable min-tls
plyr4 Sep 11, 2024
0525a14
fix: vela-server default service name
plyr4 Sep 11, 2024
00e22c4
chore: remove default env resource attrs
plyr4 Sep 11, 2024
9e8c026
Merge branch 'main' into feat/otel-tracing
ecrupper Sep 11, 2024
7e5ac7e
enhance: refactored attribute mapping
plyr4 Sep 11, 2024
ebc4427
Merge branch 'feat/otel-tracing' of github.com:go-vela/server into fe…
plyr4 Sep 11, 2024
2339384
chore: cleanup
plyr4 Sep 11, 2024
8379079
chore: lint
plyr4 Sep 11, 2024
e5f3a29
chore: cleanup
plyr4 Sep 11, 2024
f03fa06
chore: cleanup
plyr4 Sep 11, 2024
18ea2c4
chore: cleanup
plyr4 Sep 11, 2024
bb6b59a
fix: better url parsing
plyr4 Sep 11, 2024
2c4fe9e
enhance: docs links and flag clarification
plyr4 Sep 11, 2024
6db9549
enhance: more flag clarification
plyr4 Sep 11, 2024
c604d5f
Merge branch 'main' into feat/otel-tracing
wass3rw3rk Sep 12, 2024
d12f845
fix: conditionally apply scm tracing
plyr4 Sep 12, 2024
eb0d870
chore: tests
plyr4 Sep 12, 2024
7c98676
fix: do not cancel goroutine context used after http response closes
plyr4 Sep 12, 2024
f4a949d
fix: do not cancel goroutine context used after http response closes
plyr4 Sep 12, 2024
2139c9c
fix: avoid double responses
plyr4 Sep 12, 2024
da2bbee
chore: lint...
plyr4 Sep 12, 2024
1e20dd9
fix: scm test client
plyr4 Sep 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/vela-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/go-vela/server/queue"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/secret"
"github.com/go-vela/server/tracing"
"github.com/go-vela/server/version"
"github.com/go-vela/types/constants"
)
Expand Down Expand Up @@ -279,6 +280,9 @@ func main() {
// Add Source Flags
app.Flags = append(app.Flags, scm.Flags...)

// Add Tracing Flags
app.Flags = append(app.Flags, tracing.Flags...)

if err = app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
Expand Down
19 changes: 18 additions & 1 deletion cmd/vela-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/go-vela/server/queue"
"github.com/go-vela/server/router"
"github.com/go-vela/server/router/middleware"
"github.com/go-vela/server/tracing"
)

//nolint:funlen,gocyclo // ignore function length and cyclomatic complexity
Expand Down Expand Up @@ -78,7 +79,21 @@ func server(c *cli.Context) error {
return err
}

database, err := database.FromCLIContext(c)
tc, err := tracing.FromCLIContext(c)
if err != nil {
return err
}

if tc.EnableTracing {
defer func() {
err := tc.TracerProvider.Shutdown(context.Background())
if err != nil {
logrus.Errorf("unable to shutdown tracer provider: %v", err)
}
}()
}

database, err := database.FromCLIContext(c, tc)
if err != nil {
return err
}
Expand Down Expand Up @@ -189,6 +204,8 @@ func server(c *cli.Context) error {
middleware.DefaultRepoEventsMask(c.Int64("default-repo-events-mask")),
middleware.DefaultRepoApproveBuild(c.String("default-repo-approve-build")),
middleware.ScheduleFrequency(c.Duration("schedule-minimum-frequency")),
middleware.TracingClient(tc),
middleware.TracingInstrumentation(tc),
)

addr, err := url.Parse(c.String("server-addr"))
Expand Down
5 changes: 4 additions & 1 deletion database/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"

"github.com/go-vela/server/tracing"
)

const key = "database"
Expand Down Expand Up @@ -38,7 +40,7 @@ func ToContext(c Setter, d Interface) {
}

// FromCLIContext creates and returns a database engine from the urfave/cli context.
func FromCLIContext(c *cli.Context) (Interface, error) {
func FromCLIContext(c *cli.Context, tc *tracing.Client) (Interface, error) {
logrus.Debug("creating database engine from CLI configuration")

return New(
Expand All @@ -54,5 +56,6 @@ func FromCLIContext(c *cli.Context) (Interface, error) {
WithLogSlowThreshold(c.Duration("database.log.slow_threshold")),
WithLogShowSQL(c.Bool("database.log.show_sql")),
WithSkipCreation(c.Bool("database.skip_creation")),
WithTracing(tc),
)
}
4 changes: 3 additions & 1 deletion database/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/gin-gonic/gin"
"github.com/urfave/cli/v2"

"github.com/go-vela/server/tracing"
)

func TestDatabase_FromContext(t *testing.T) {
Expand Down Expand Up @@ -132,7 +134,7 @@ func TestDatabase_FromCLIContext(t *testing.T) {
// run tests
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, err := FromCLIContext(test.context)
_, err := FromCLIContext(test.context, &tracing.Client{Config: tracing.Config{EnableTracing: false}})

if test.failure {
if err == nil {
Expand Down
20 changes: 19 additions & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/sirupsen/logrus"
"github.com/uptrace/opentelemetry-go-extra/otelgorm"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
Expand All @@ -28,6 +29,7 @@ import (
"github.com/go-vela/server/database/step"
"github.com/go-vela/server/database/user"
"github.com/go-vela/server/database/worker"
"github.com/go-vela/server/tracing"
"github.com/go-vela/types/constants"
)

Expand Down Expand Up @@ -70,6 +72,8 @@ type (
ctx context.Context
// sirupsen/logrus logger used in database functions
logger *logrus.Entry
// configurations related to telemetry/tracing
tracing *tracing.Client

settings.SettingsInterface
build.BuildInterface
Expand Down Expand Up @@ -105,7 +109,7 @@ func New(opts ...EngineOpt) (Interface, error) {
e.client = new(gorm.DB)
e.config = new(config)
e.logger = new(logrus.Entry)
e.ctx = context.TODO()
e.ctx = context.Background()

// apply all provided configuration options
for _, opt := range opts {
Expand Down Expand Up @@ -191,6 +195,19 @@ func New(opts ...EngineOpt) (Interface, error) {
return nil, err
}

// initialize otel tracing if enabled
if e.tracing.EnableTracing {
otelPlugin := otelgorm.NewPlugin(
otelgorm.WithTracerProvider(e.tracing.TracerProvider),
otelgorm.WithoutQueryVariables(),
)

err := e.client.Use(otelPlugin)
if err != nil {
return nil, err
}
}

// set the maximum amount of time a connection may be reused
db.SetConnMaxLifetime(e.config.ConnectionLife)
// set the maximum number of connections in the idle connection pool
Expand Down Expand Up @@ -230,5 +247,6 @@ func NewTest() (Interface, error) {
WithLogShowSQL(false),
WithLogSkipNotFound(true),
WithLogSlowThreshold(200*time.Millisecond),
WithTracing(&tracing.Client{Config: tracing.Config{EnableTracing: false}}),
)
}
3 changes: 3 additions & 0 deletions database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
"gorm.io/gorm"

"github.com/go-vela/server/tracing"
)

func TestDatabase_New(t *testing.T) {
Expand Down Expand Up @@ -110,6 +112,7 @@ func TestDatabase_New(t *testing.T) {
WithLogSlowThreshold(test.config.LogSlowThreshold),
WithEncryptionKey(test.config.EncryptionKey),
WithSkipCreation(test.config.SkipCreation),
WithTracing(&tracing.Client{Config: tracing.Config{EnableTracing: false}}),
)

if test.failure {
Expand Down
2 changes: 2 additions & 0 deletions database/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/user"
"github.com/go-vela/server/database/worker"
"github.com/go-vela/server/tracing"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/types/raw"
Expand Down Expand Up @@ -114,6 +115,7 @@ func TestDatabase_Integration(t *testing.T) {
WithDriver(test.config.Driver),
WithEncryptionKey(test.config.EncryptionKey),
WithSkipCreation(test.config.SkipCreation),
WithTracing(&tracing.Client{Config: tracing.Config{EnableTracing: false}}),
)
if err != nil {
t.Errorf("unable to create new database engine for %s: %v", test.name, err)
Expand Down
11 changes: 11 additions & 0 deletions database/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package database
import (
"context"
"time"

"github.com/go-vela/server/tracing"
)

// EngineOpt represents a configuration option to initialize the database engine.
Expand Down Expand Up @@ -130,6 +132,15 @@ func WithSkipCreation(skipCreation bool) EngineOpt {
}
}

// WithTracing sets the shared tracing config in the database engine.
func WithTracing(tracing *tracing.Client) EngineOpt {
return func(e *engine) error {
e.tracing = tracing

return nil
}
}

// WithContext sets the context in the database engine.
func WithContext(ctx context.Context) EngineOpt {
return func(e *engine) error {
Expand Down
34 changes: 26 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ services:
VELA_ENABLE_SECURE_COOKIE: 'false'
VELA_REPO_ALLOWLIST: '*'
VELA_SCHEDULE_ALLOWLIST: '*'
VELA_OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4318
plyr4 marked this conversation as resolved.
Show resolved Hide resolved
VELA_OTEL_TRACING_ENDPOINT: jaeger:4318
VELA_OTEL_TRACING_ENABLE: true
VELA_OTEL_TRACING_SERVICE_NAME: vela-server
VELA_OTEL_TRACING_RESOURCE_ATTRIBUTES: "process.runtime.name=go"
VELA_OTEL_TRACING_RESOURCE_ENV_ATTRIBUTES: "deployment.environment=CLOUD_ENVIRONMENT"
VELA_OTEL_TRACING_SAMPLER_RATELIMIT_PER_SECOND: 0.2
env_file:
- .env
restart: always
Expand Down Expand Up @@ -152,18 +159,29 @@ services:
#
# https://www.vaultproject.io/
vault:
image: hashicorp/vault:latest
container_name: vault
command: server -dev
image: hashicorp/vault:latest
container_name: vault
command: server -dev
networks:
- vela
environment:
VAULT_DEV_LISTEN_ADDRESS: 0.0.0.0:8200
VAULT_DEV_ROOT_TOKEN_ID: vela
ports:
- '8200:8200'
cap_add:
- IPC_LOCK

jaeger:
image: jaegertracing/all-in-one:latest
container_name: jaeger
networks:
- vela
environment:
VAULT_DEV_LISTEN_ADDRESS: 0.0.0.0:8200
VAULT_DEV_ROOT_TOKEN_ID: vela
COLLECTOR_OTLP_ENABLED: true
ports:
- '8200:8200'
cap_add:
- IPC_LOCK
- '16686:16686'
- '4318:4318'

networks:
vela:
38 changes: 28 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@ require (
github.com/redis/go-redis/v9 v9.6.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/afero v1.11.0
github.com/uptrace/opentelemetry-go-extra/otelgorm v0.3.1
github.com/urfave/cli/v2 v2.27.2
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.53.0
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.42.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
go.starlark.net v0.0.0-20240314022150-ee8ed142361c
golang.org/x/crypto v0.25.0
golang.org/x/oauth2 v0.21.0
golang.org/x/sync v0.7.0
golang.org/x/time v0.5.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/postgres v1.5.9
gorm.io/driver/sqlite v1.5.6
Expand All @@ -55,28 +65,32 @@ require (
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic v1.11.9 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cenkalti/backoff/v3 v3.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // indirect
Expand All @@ -93,8 +107,7 @@ require (
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
Expand All @@ -121,14 +134,19 @@ require (
github.com/spf13/cast v1.3.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/uptrace/opentelemetry-go-extra/otelsql v0.3.1 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
Expand Down
Loading
Loading