From 6abf03c923a6fc18ab8f99db817b2ed0ce4cde25 Mon Sep 17 00:00:00 2001 From: Ryan Martin <51780559+rmrt1n@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:18:58 -0700 Subject: [PATCH] fix: jaeger traces not persisted across container restarts (#82) Closes: WORLD-1208 ## Overview Previously the Jaeger container only stores the spans in memory, which is lost when the container is restarted. This PR fixes this by [configuring Jaeger to use Badger](https://www.jaegertracing.io/docs/1.62/deployment/#span-storage-backends) as the span storage engine with a Docker volume. ## Brief Changelog - Updated the Jaeger container config to use badger ## Testing and Verifying Manually tested and verified. --------- Co-authored-by: Ryan Martin --- .gitignore | 2 +- common/docker/service/evm.go | 2 +- common/docker/service/jaeger.go | 21 +++++++++++++++++++++ common/docker/service/nakama.go | 4 ++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index be28b41..87d60f2 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,4 @@ dist/ /starter-game # Built binary -world +./world diff --git a/common/docker/service/evm.go b/common/docker/service/evm.go index 391b220..a22016f 100644 --- a/common/docker/service/evm.go +++ b/common/docker/service/evm.go @@ -28,7 +28,7 @@ func EVM(cfg *config.Config) Service { faucetEnabled := cfg.DockerEnv["FAUCET_ENABLED"] if faucetEnabled == "" { - faucetEnabled = "false" //nolint:goconst // default values should be local to the service + faucetEnabled = "false" } faucetAddress := cfg.DockerEnv["FAUCET_ADDRESS"] diff --git a/common/docker/service/jaeger.go b/common/docker/service/jaeger.go index 4224f2d..b7a7b83 100644 --- a/common/docker/service/jaeger.go +++ b/common/docker/service/jaeger.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/mount" "pkg.world.dev/world-cli/common/config" ) @@ -19,10 +20,30 @@ func Jaeger(cfg *config.Config) Service { Name: getJaegerContainerName(cfg), Config: container.Config{ Image: "jaegertracing/all-in-one:1.61.0", + // hard-coding this since it won't change much and the defaults work. users most likely + // won't need to change these. note that this storage configuration isn't recommended to + // be used for production environment, but is good enough for local development. + // for more info see: https://www.jaegertracing.io/docs/1.62/deployment/#span-storage-backends + Env: []string{ + "SPAN_STORAGE_TYPE=badger", + "BADGER_EPHEMERAL=false", + "BADGER_DIRECTORY_VALUE=/badger/data", + "BADGER_DIRECTORY_KEY=/badger/key", + "QUERY_ADDITIONAL_HEADERS=Access-Control-Allow-Origin:*", + }, + // running as the default user (uid 10001) doesn't work on mac because the volume is owned by + // root. A way to get around this is to create another container to change the owner of the + // /badger directory. since we're not able to start services following a dependency graph yet, + // we'll just run as root. world cli is also mainly used for local dev, so the security + // benefits of running as non-root doesn't really apply here. + // src: https://github.com/jaegertracing/jaeger/issues/4906 + User: "root", }, HostConfig: container.HostConfig{ PortBindings: newPortMap(exposedPorts), NetworkMode: container.NetworkMode(cfg.DockerEnv["CARDINAL_NAMESPACE"]), + Mounts: []mount.Mount{{Type: mount.TypeVolume, + Source: cfg.DockerEnv["CARDINAL_NAMESPACE"], Target: "/badger"}}, }, } } diff --git a/common/docker/service/nakama.go b/common/docker/service/nakama.go index 0372ca2..3fb60c4 100644 --- a/common/docker/service/nakama.go +++ b/common/docker/service/nakama.go @@ -37,7 +37,7 @@ func Nakama(cfg *config.Config) Service { traceEnabled := cfg.DockerEnv["NAKAMA_TRACE_ENABLED"] if traceEnabled == "" || !cfg.Telemetry { - traceEnabled = "false" + traceEnabled = "true" } traceSampleRate := cfg.DockerEnv["NAKAMA_TRACE_SAMPLE_RATE"] @@ -45,7 +45,7 @@ func Nakama(cfg *config.Config) Service { traceSampleRate = "0.6" } - metricsEnabled := false + metricsEnabled := true if cfg.Telemetry { cfgMetricsEnabled, err := strconv.ParseBool(cfg.DockerEnv["NAKAMA_METRICS_ENABLED"]) if err == nil {