From ae5b24e40b39fd431d24234cd2a16ef4f6d516c0 Mon Sep 17 00:00:00 2001 From: Gus Eggert Date: Fri, 17 Mar 2023 10:24:17 -0400 Subject: [PATCH 1/3] test: make test prereqs like Docker, plugins, etc. opt-in This is so that by default, you can run tests without having to set up any of these things and without having to set env vars on the test runner. This makes it easier to run the CLI tests in your IDE without having to setup special env vars to skip the Docker, plugin, and fuse tests. --- .github/workflows/build.yml | 12 ++++++------ .github/workflows/gobuild.yml | 6 +++--- .github/workflows/golint.yml | 4 ++-- .github/workflows/gotest.yml | 4 ++-- .github/workflows/sharness.yml | 6 +++--- Rules.mk | 2 +- coverage/Rules.mk | 2 +- test/cli/testutils/requires.go | 6 +++--- test/sharness/Rules.mk | 2 +- test/sharness/lib/test-lib.sh | 12 ++++++------ 10 files changed, 28 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ddb3382c699..50889613bea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,8 +20,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 env: - TEST_NO_DOCKER: 1 - TEST_NO_FUSE: 1 + TEST_DOCKER: 0 + TEST_FUSE: 0 TEST_VERBOSE: 1 TRAVIS: 1 GIT_PAGER: cat @@ -86,8 +86,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 env: - TEST_NO_DOCKER: 1 - TEST_NO_FUSE: 1 + TEST_DOCKER: 0 + TEST_FUSE: 0 TEST_VERBOSE: 1 TRAVIS: 1 GIT_PAGER: cat @@ -126,8 +126,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 env: - TEST_NO_DOCKER: 1 - TEST_NO_FUSE: 1 + TEST_DOCKER: 0 + TEST_FUSE: 0 TEST_VERBOSE: 1 TRAVIS: 1 GIT_PAGER: cat diff --git a/.github/workflows/gobuild.yml b/.github/workflows/gobuild.yml index 26dc66777f3..f1e3a60b776 100644 --- a/.github/workflows/gobuild.yml +++ b/.github/workflows/gobuild.yml @@ -20,7 +20,7 @@ jobs: runs-on: ${{ fromJSON(needs.go-build-runner.outputs.config).labels }} timeout-minutes: 20 env: - TEST_NO_DOCKER: 1 + TEST_DOCKER: 0 TEST_VERBOSE: 1 TRAVIS: 1 GIT_PAGER: cat @@ -38,7 +38,7 @@ jobs: name: ${{ github.job }} - run: make cmd/ipfs-try-build env: - TEST_NO_FUSE: 0 + TEST_FUSE: 1 - run: make cmd/ipfs-try-build env: - TEST_NO_FUSE: 1 + TEST_FUSE: 0 diff --git a/.github/workflows/golint.yml b/.github/workflows/golint.yml index ae3683ff49b..216573a468e 100644 --- a/.github/workflows/golint.yml +++ b/.github/workflows/golint.yml @@ -17,8 +17,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 env: - TEST_NO_DOCKER: 1 - TEST_NO_FUSE: 1 + TEST_DOCKER: 0 + TEST_FUSE: 0 TEST_VERBOSE: 1 TRAVIS: 1 GIT_PAGER: cat diff --git a/.github/workflows/gotest.yml b/.github/workflows/gotest.yml index ab35ec3a798..81c39fd5e51 100644 --- a/.github/workflows/gotest.yml +++ b/.github/workflows/gotest.yml @@ -20,8 +20,8 @@ jobs: runs-on: ${{ fromJSON(needs.go-test-runner.outputs.config).labels }} timeout-minutes: 20 env: - TEST_NO_DOCKER: 1 - TEST_NO_FUSE: 1 + TEST_DOCKER: 0 + TEST_FUSE: 0 TEST_VERBOSE: 1 TRAVIS: 1 GIT_PAGER: cat diff --git a/.github/workflows/sharness.yml b/.github/workflows/sharness.yml index 04779d15f40..012a6a9826e 100644 --- a/.github/workflows/sharness.yml +++ b/.github/workflows/sharness.yml @@ -49,9 +49,9 @@ jobs: test/sharness/test-results/sharness.xml working-directory: kubo env: - TEST_NO_DOCKER: 0 - TEST_NO_PLUGIN: 1 - TEST_NO_FUSE: 1 + TEST_DOCKER: 1 + TEST_PLUGIN: 0 + TEST_FUSE: 0 TEST_VERBOSE: 1 TEST_JUNIT: 1 TEST_EXPENSIVE: 1 diff --git a/Rules.mk b/Rules.mk index 3d3d9c13951..cec34cef7f7 100644 --- a/Rules.mk +++ b/Rules.mk @@ -19,7 +19,7 @@ include mk/golang.mk # extra properties # # -------------------- # -ifeq ($(TEST_NO_FUSE),1) +ifeq ($(TEST_FUSE),0) GOTAGS += nofuse endif export LIBP2P_TCP_REUSEPORT=false diff --git a/coverage/Rules.mk b/coverage/Rules.mk index 7770ed69b5d..48fce28568c 100644 --- a/coverage/Rules.mk +++ b/coverage/Rules.mk @@ -45,7 +45,7 @@ endif export IPFS_COVER_DIR:= $(realpath $(d))/sharnesscover/ -$(d)/sharness_tests.coverprofile: export TEST_NO_PLUGIN=1 +$(d)/sharness_tests.coverprofile: export TEST_PLUGIN=0 $(d)/sharness_tests.coverprofile: $(d)/ipfs cmd/ipfs/ipfs-test-cover $(d)/coverage_deps test_sharness (cd $(@D)/sharnesscover && find . -type f | gocovmerge -list -) > $@ diff --git a/test/cli/testutils/requires.go b/test/cli/testutils/requires.go index d4b88cd6dfe..1462b7fee90 100644 --- a/test/cli/testutils/requires.go +++ b/test/cli/testutils/requires.go @@ -7,13 +7,13 @@ import ( ) func RequiresDocker(t *testing.T) { - if os.Getenv("TEST_NO_DOCKER") == "1" { + if os.Getenv("TEST_DOCKER") != "1" { t.SkipNow() } } func RequiresFUSE(t *testing.T) { - if os.Getenv("TEST_NO_FUSE") == "1" { + if os.Getenv("TEST_FUSE") != "1" { t.SkipNow() } } @@ -25,7 +25,7 @@ func RequiresExpensive(t *testing.T) { } func RequiresPlugins(t *testing.T) { - if os.Getenv("TEST_NO_PLUGIN") == "1" { + if os.Getenv("TEST_PLUGIN") != "1" { t.SkipNow() } } diff --git a/test/sharness/Rules.mk b/test/sharness/Rules.mk index f95aee15e0d..0dcd8d2e4ae 100644 --- a/test/sharness/Rules.mk +++ b/test/sharness/Rules.mk @@ -21,7 +21,7 @@ $(PLUGINS_$(d)): $(ORGIN_PLUGINS_$(d)) @mkdir -p $(@D) cp -f plugin/plugins/$(@F) $@ -ifneq ($(TEST_NO_PLUGIN),1) +ifneq ($(TEST_PLUGIN),0) DEPS_$(d) += $(PLUGINS_$(d)) endif endif diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index f135cdd7940..bd8f7de9b90 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -94,10 +94,10 @@ export TERM=dumb TEST_OS="$(uname -s | tr '[a-z]' '[A-Z]')" # grab + output options -test "$TEST_NO_FUSE" != 1 && test_set_prereq FUSE +test "$TEST_FUSE" = 1 && test_set_prereq FUSE test "$TEST_EXPENSIVE" = 1 && test_set_prereq EXPENSIVE -test "$TEST_NO_DOCKER" != 1 && type docker >/dev/null 2>&1 && groups | egrep "\bdocker\b" && test_set_prereq DOCKER -test "$TEST_NO_PLUGIN" != 1 && test "$TEST_OS" = "LINUX" && test_set_prereq PLUGIN +test "$TEST_DOCKER" = 1 && type docker >/dev/null 2>&1 && groups | egrep "\bdocker\b" && test_set_prereq DOCKER +test "$TEST_PLUGIN" = 1 && test "$TEST_OS" = "LINUX" && test_set_prereq PLUGIN # this may not be available, skip a few dependent tests type socat >/dev/null 2>&1 && test_set_prereq SOCAT @@ -110,9 +110,9 @@ expr "$TEST_OS" : "CYGWIN_NT" >/dev/null || test_set_prereq STD_ERR_MSG if test "$TEST_VERBOSE" = 1; then echo '# TEST_VERBOSE='"$TEST_VERBOSE" echo '# TEST_IMMEDIATE='"$TEST_IMMEDIATE" - echo '# TEST_NO_FUSE='"$TEST_NO_FUSE" - echo '# TEST_NO_DOCKER='"$TEST_NO_DOCKER" - echo '# TEST_NO_PLUGIN='"$TEST_NO_PLUGIN" + echo '# TEST_FUSE='"$TEST_FUSE" + echo '# TEST_DOCKER='"$TEST_DOCKER" + echo '# TEST_PLUGIN='"$TEST_PLUGIN" echo '# TEST_EXPENSIVE='"$TEST_EXPENSIVE" echo '# TEST_OS='"$TEST_OS" echo '# TEST_JUNIT='"$TEST_JUNIT" From 587506f21b71f35c98016838c5ee5d453795f519 Mon Sep 17 00:00:00 2001 From: Gus Eggert Date: Sat, 18 Mar 2023 07:47:20 -0400 Subject: [PATCH 2/3] test: port tracing tests to Go --- go.mod | 12 ++--- go.sum | 15 +++--- test/cli/harness/node.go | 30 +++++++++--- test/cli/harness/run.go | 12 +++++ test/cli/tracing_test.go | 89 ++++++++++++++++++++++++++++++++++ test/sharness/t0310-tracing.sh | 57 ---------------------- 6 files changed, 136 insertions(+), 79 deletions(-) create mode 100644 test/cli/tracing_test.go delete mode 100755 test/sharness/t0310-tracing.sh diff --git a/go.mod b/go.mod index 6a6b70ce251..1b7893475ab 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 9aaa5edb475..858e368504c 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 4d9ed965c23..625a01fb6c1 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 c2a3662be8b..75c07bcc2cf 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 00000000000..ef717716eaa --- /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 96d07ae8da2..00000000000 --- 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 From df53c736d3a67459e104fe92e69952088d8618ca Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 5 Apr 2023 13:35:32 +0200 Subject: [PATCH 3/3] fix: sharness test header --- test/sharness/t0230-channel-streaming-http-content-type.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/sharness/t0230-channel-streaming-http-content-type.sh b/test/sharness/t0230-channel-streaming-http-content-type.sh index 055b342d1ea..be23d8151c0 100755 --- a/test/sharness/t0230-channel-streaming-http-content-type.sh +++ b/test/sharness/t0230-channel-streaming-http-content-type.sh @@ -23,7 +23,6 @@ test_ls_cmd() { printf "HTTP/1.1 200 OK\r\n" >expected_output && printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length\r\n" >>expected_output && printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length\r\n" >>expected_output && - printf "Connection: close\r\n" >>expected_output && printf "Content-Type: text/plain\r\n" >>expected_output && printf "Server: kubo/%s\r\n" $(ipfs version -n) >>expected_output && printf "Trailer: X-Stream-Error\r\n" >>expected_output && @@ -47,7 +46,6 @@ test_ls_cmd() { printf "HTTP/1.1 200 OK\r\n" >expected_output && printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length\r\n" >>expected_output && printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length\r\n" >>expected_output && - printf "Connection: close\r\n" >>expected_output && printf "Content-Type: application/json\r\n" >>expected_output && printf "Server: kubo/%s\r\n" $(ipfs version -n) >>expected_output && printf "Trailer: X-Stream-Error\r\n" >>expected_output &&