diff --git a/go.mod b/go.mod index 6a6b70ce251c..1b7893475ab6 100644 --- a/go.mod +++ b/go.mod @@ -72,18 +72,15 @@ require ( github.com/whyrusleeping/go-sysinfo v0.0.0-20190219211824-4a357d4b90b1 github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 go.opencensus.io v0.24.0 - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0 + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0 go.opentelemetry.io/otel v1.14.0 go.opentelemetry.io/otel/exporters/jaeger v1.14.0 - go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0 go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0 go.opentelemetry.io/otel/exporters/zipkin v1.14.0 go.opentelemetry.io/otel/sdk v1.14.0 go.opentelemetry.io/otel/trace v1.14.0 - go.opentelemetry.io/proto/otlp v0.19.0 // indirect go.uber.org/dig v1.15.0 go.uber.org/fx v1.18.2 go.uber.org/zap v1.24.0 @@ -113,7 +110,7 @@ require ( github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect github.com/emirpasic/gods v1.18.1 // indirect - github.com/felixge/httpsnoop v1.0.2 // indirect + github.com/felixge/httpsnoop v1.0.3 // indirect github.com/flynn/noise v1.0.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect github.com/gabriel-vasile/mimetype v1.4.1 // indirect @@ -208,7 +205,10 @@ require ( github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa // indirect github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect - go.opentelemetry.io/otel/metric v0.30.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0 // indirect + go.opentelemetry.io/otel/metric v0.37.0 // indirect + go.opentelemetry.io/proto/otlp v0.19.0 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.9.0 // indirect go4.org v0.0.0-20200411211856-f5505b9728dd // indirect diff --git a/go.sum b/go.sum index 9aaa5edb4753..858e368504c0 100644 --- a/go.sum +++ b/go.sum @@ -170,8 +170,8 @@ github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 h1:BBso6MBKW github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5/go.mod h1:JpoxHjuQauoxiFMl1ie8Xc/7TfLuMZ5eOCONd1sUBHg= github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= -github.com/felixge/httpsnoop v1.0.2 h1:+nS9g82KMXccJ/wp0zyRW9ZBHFETmMGtkk+2CTTrW4o= -github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= +github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= @@ -291,7 +291,6 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= @@ -922,9 +921,8 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0 h1:mac9BKRqwaX6zxHPDe3pvmWpwuuIM0vuXv2juCnQevE= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0/go.mod h1:5eCOqeGphOyz6TsY3ZDNjE33SM/TFAK3RGuCL2naTgY= -go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0 h1:lE9EJyw3/JhrjWH/hEy9FptnalDQgj7vpbgC2KCCCxE= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0/go.mod h1:pcQ3MM3SWvrA71U4GDqv9UFDJ3HQsW7y5ZO3tDTlUdI= go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM= go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU= go.opentelemetry.io/otel/exporters/jaeger v1.14.0 h1:CjbUNd4iN2hHmWekmOqZ+zSCU+dzZppG8XsV+A3oc8Q= @@ -941,11 +939,10 @@ go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0 h1:sEL90JjOO/4yhqu go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0/go.mod h1:oCslUcizYdpKYyS9e8srZEqM6BB8fq41VJBjLAE6z1w= go.opentelemetry.io/otel/exporters/zipkin v1.14.0 h1:reEVE1upBF9tcujgvSqLJS0SrI7JQPaTKP4s4rymnSs= go.opentelemetry.io/otel/exporters/zipkin v1.14.0/go.mod h1:RcjvOAcvhzcufQP8aHmzRw1gE9g/VEZufDdo2w+s4sk= -go.opentelemetry.io/otel/metric v0.30.0 h1:Hs8eQZ8aQgs0U49diZoaS6Uaxw3+bBE3lcMUKBFIk3c= -go.opentelemetry.io/otel/metric v0.30.0/go.mod h1:/ShZ7+TS4dHzDFmfi1kSXMhMVubNoP0oIaBp70J6UXU= +go.opentelemetry.io/otel/metric v0.37.0 h1:pHDQuLQOZwYD+Km0eb657A25NaRzy0a+eLyKfDXedEs= +go.opentelemetry.io/otel/metric v0.37.0/go.mod h1:DmdaHfGt54iV6UKxsV9slj2bBRJcKC1B1uvDLIioc1s= go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY= go.opentelemetry.io/otel/sdk v1.14.0/go.mod h1:bwIC5TjrNG6QDCHNWvW4HLHtUQ4I+VQDsnjhvyZCALM= -go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU= go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M= go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= diff --git a/test/cli/harness/node.go b/test/cli/harness/node.go index 4d9ed965c237..625a01fb6c16 100644 --- a/test/cli/harness/node.go +++ b/test/cli/harness/node.go @@ -211,19 +211,29 @@ func (n *Node) Init(ipfsArgs ...string) *Node { return n } -func (n *Node) StartDaemon(ipfsArgs ...string) *Node { +// StartDaemonWithReq runs a Kubo daemon with the given request. +// This overwrites the request Path with the Kubo bin path. +// +// For example, if you want to run the daemon and see stderr and stdout to debug: +// +// node.StartDaemonWithReq(harness.RunRequest{ +// CmdOpts: []harness.CmdOpt{ +// harness.RunWithStderr(os.Stdout), +// harness.RunWithStdout(os.Stdout), +// }, +// }) +func (n *Node) StartDaemonWithReq(req RunRequest) *Node { alive := n.IsAlive() if alive { log.Panicf("node %d is already running", n.ID) } + newReq := req + newReq.Path = n.IPFSBin + newReq.Args = append([]string{"daemon"}, req.Args...) + newReq.RunFunc = (*exec.Cmd).Start - daemonArgs := append([]string{"daemon"}, ipfsArgs...) log.Debugf("starting node %d", n.ID) - res := n.Runner.MustRun(RunRequest{ - Path: n.IPFSBin, - Args: daemonArgs, - RunFunc: (*exec.Cmd).Start, - }) + res := n.Runner.MustRun(newReq) n.Daemon = res @@ -232,6 +242,12 @@ func (n *Node) StartDaemon(ipfsArgs ...string) *Node { return n } +func (n *Node) StartDaemon(ipfsArgs ...string) *Node { + return n.StartDaemonWithReq(RunRequest{ + Args: ipfsArgs, + }) +} + func (n *Node) signalAndWait(watch <-chan struct{}, signal os.Signal, t time.Duration) bool { err := n.Daemon.Cmd.Process.Signal(signal) if err != nil { diff --git a/test/cli/harness/run.go b/test/cli/harness/run.go index c2a3662be8bd..75c07bcc2cff 100644 --- a/test/cli/harness/run.go +++ b/test/cli/harness/run.go @@ -142,3 +142,15 @@ func RunWithStdin(reader io.Reader) CmdOpt { func RunWithStdinStr(s string) CmdOpt { return RunWithStdin(strings.NewReader(s)) } + +func RunWithStdout(writer io.Writer) CmdOpt { + return func(cmd *exec.Cmd) { + cmd.Stdout = io.MultiWriter(writer, cmd.Stdout) + } +} + +func RunWithStderr(writer io.Writer) CmdOpt { + return func(cmd *exec.Cmd) { + cmd.Stderr = io.MultiWriter(writer, cmd.Stdout) + } +} diff --git a/test/cli/tracing_test.go b/test/cli/tracing_test.go new file mode 100644 index 000000000000..ef717716eaa5 --- /dev/null +++ b/test/cli/tracing_test.go @@ -0,0 +1,89 @@ +package cli + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/ipfs/kubo/test/cli/harness" + "github.com/ipfs/kubo/test/cli/testutils" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +var otelCollectorConfigYAML = ` +receivers: + otlp: + protocols: + grpc: + +processors: + batch: + +exporters: + file: + path: /traces/traces.json + +service: + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [file] +` + +func TestTracing(t *testing.T) { + testutils.RequiresDocker(t) + t.Parallel() + node := harness.NewT(t).NewNode().Init() + + node.WriteBytes("collector-config.yaml", []byte(otelCollectorConfigYAML)) + + // touch traces.json and give it 777 perms in case Docker runs as a different user + node.WriteBytes("traces.json", nil) + err := os.Chmod(filepath.Join(node.Dir, "traces.json"), 0777) + require.NoError(t, err) + + dockerBin, err := exec.LookPath("docker") + require.NoError(t, err) + node.Runner.MustRun(harness.RunRequest{ + Path: dockerBin, + Args: []string{ + "run", + "--rm", + "--detach", + "--volume", fmt.Sprintf("%s:/config.yaml", filepath.Join(node.Dir, "collector-config.yaml")), + "--volume", fmt.Sprintf("%s:/traces", node.Dir), + "--net", "host", + "--name", "ipfs-test-otel-collector", + "otel/opentelemetry-collector-contrib:0.52.0", + "--config", "/config.yaml", + }, + }) + + t.Cleanup(func() { + node.Runner.MustRun(harness.RunRequest{ + Path: dockerBin, + Args: []string{"stop", "ipfs-test-otel-collector"}, + }) + }) + + node.Runner.Env["OTEL_TRACES_EXPORTER"] = "otlp" + node.Runner.Env["OTEL_EXPORTER_OTLP_PROTOCOL"] = "grpc" + node.Runner.Env["OTEL_EXPORTER_OTLP_ENDPOINT"] = "http://localhost:4317" + node.StartDaemon() + + assert.Eventually(t, + func() bool { + b, err := os.ReadFile(filepath.Join(node.Dir, "traces.json")) + require.NoError(t, err) + return strings.Contains(string(b), "go-ipfs") + }, + 5*time.Minute, + 10*time.Millisecond, + ) +} diff --git a/test/sharness/t0310-tracing.sh b/test/sharness/t0310-tracing.sh deleted file mode 100755 index 96d07ae8da27..000000000000 --- a/test/sharness/t0310-tracing.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2022 Protocol Labs -# MIT/Apache-2.0 Licensed; see the LICENSE file in this repository. -# - -test_description="Test tracing" - -. lib/test-lib.sh - -test_init_ipfs - -export OTEL_TRACES_EXPORTER=otlp -export OTEL_EXPORTER_OTLP_PROTOCOL=grpc -export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 - -cat < collector-config.yaml -receivers: - otlp: - protocols: - grpc: - -processors: - batch: - -exporters: - file: - path: /traces/traces.json - -service: - pipelines: - traces: - receivers: [otlp] - processors: [batch] - exporters: [file] -EOF - -# touch traces.json and give it 777 perms, in case docker runs as a different user -rm -rf traces.json && touch traces.json && chmod 777 traces.json - -test_expect_success "run opentelemetry collector" ' - docker run --rm -d -v "$PWD/collector-config.yaml":/config.yaml -v "$PWD":/traces --net=host --name=ipfs-test-otel-collector otel/opentelemetry-collector-contrib:0.52.0 --config /config.yaml -' - -test_launch_ipfs_daemon - -test_expect_success "check that a swarm span eventually appears in exported traces" ' - until cat traces.json | grep CoreAPI.SwarmAPI >/dev/null; do sleep 0.1; done -' - -test_expect_success "kill docker container" ' - docker kill ipfs-test-otel-collector -' - -test_kill_ipfs_daemon - -test_done