Skip to content

Commit

Permalink
Merge pull request #1038 from saschagrunert/tracing
Browse files Browse the repository at this point in the history
Add tracing integration test
  • Loading branch information
openshift-merge-robot authored Jan 26, 2023
2 parents 8eed2af + 74a19af commit b99cc76
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 23 deletions.
22 changes: 0 additions & 22 deletions contrib/tracing/docker-compose.yaml

This file was deleted.

16 changes: 16 additions & 0 deletions contrib/tracing/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -uo pipefail

cd "$(dirname "$0")"

CONTAINER_RUNTIME=$(which podman 2>/dev/null) || CONTAINER_RUNTIME=$(which docker 2>/dev/null)
if [[ -z "$CONTAINER_RUNTIME" ]]; then
echo "Neither docker nor podman found in \$PATH"
exit 1
fi

set -e

export OTLP_CTR=otlp
export JAEGER_CTR=jaeger
export CONTAINER_RUNTIME
8 changes: 8 additions & 0 deletions contrib/tracing/logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -uo pipefail

# Global vars to be used
# shellcheck source=env
source "$(dirname "${BASH_SOURCE[0]}")"/env

"$CONTAINER_RUNTIME" logs "$OTLP_CTR" 2>&1
2 changes: 1 addition & 1 deletion contrib/tracing/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exporters:
loglevel: debug

jaeger:
endpoint: jaeger-all-in-one:14250
endpoint: localhost:14250
tls:
insecure: true

Expand Down
49 changes: 49 additions & 0 deletions contrib/tracing/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
set -uo pipefail

# Global vars to be used
# shellcheck source=stop
source "$(dirname "${BASH_SOURCE[0]}")"/stop

JAEGER_IMG="jaegertracing/all-in-one:1.41.0"
OTLP_IMG="otel/opentelemetry-collector:0.70.0"

echo "Starting $JAEGER_CTR"
"$CONTAINER_RUNTIME" run -d --rm --network host --name "$JAEGER_CTR" "$JAEGER_IMG"

PORT=14250
MAX_CNT=100
for ((i = 0; i <= "$MAX_CNT"; i++)); do
if netstat -tuplen 2>/dev/null | grep -q "$PORT .* LISTEN"; then
break
fi

if [[ $i == "$MAX_CNT" ]]; then
echo "Giving up"
exit 1
fi

echo "Waiting for gRPC port $PORT to listen… ($i)"
sleep 3
done

echo "Starting $OTLP_CTR"
"$CONTAINER_RUNTIME" run -d --rm --network host --name "$OTLP_CTR" \
-v ./otel-collector-config.yaml:/etc/otel-collector-config.yaml \
"$OTLP_IMG" --config=/etc/otel-collector-config.yaml

for ((i = 0; i <= "$MAX_CNT"; i++)); do
if ./logs | grep -q '"jaeger", "state": "READY"'; then
break
fi

if [[ $i == "$MAX_CNT" ]]; then
echo "Giving up"
exit 1
fi

echo "Waiting for OTLP to become ready… ($i)"
sleep 3
done

echo "Everything is ready"
11 changes: 11 additions & 0 deletions contrib/tracing/stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -uo pipefail

# Global vars to be used
# shellcheck source=env
source "$(dirname "${BASH_SOURCE[0]}")"/env

echo "Stopping $JAEGER_CTR and $OTLP_CTR containers"
for CTR in "$JAEGER_CTR" "$OTLP_CTR"; do
"$CONTAINER_RUNTIME" stop "$CTR" >/dev/null 2>&1 || true
done
49 changes: 49 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package client_test

import (
"bytes"
"context"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -467,4 +470,50 @@ var _ = Describe("ConmonClient", func() {
})
}
})

Describe("Tracing", func() {
const contribTracingPath = "../../contrib/tracing/"

BeforeEach(func() {
cmd := exec.Command(contribTracingPath + "start")
fmt.Fprintln(os.Stdout)
cmd.Stdout = os.Stdout
Expect(cmd.Run()).To(BeNil())
})

getLog := func() string {
cmd := exec.Command(contribTracingPath + "logs")
var stdout bytes.Buffer
cmd.Stdout = &stdout
Expect(cmd.Run()).To(BeNil())

return stdout.String()
}

It("should succeed", func() {
tr = newTestRunner()
tr.createRuntimeConfig(false)
tr.enableTracing = true

sut = tr.configGivenEnv()
tr.createContainer(sut, false)
tr.startContainer(sut)

for i := 0; i < 100; i++ {
log := getLog()

if strings.Contains(log, "service.name: Str(conmonrs)") {
break
}

time.Sleep(time.Second)
}
})

AfterEach(func() {
cmd := exec.Command(contribTracingPath + "stop")
cmd.Stdout = os.Stdout
Expect(cmd.Run()).To(BeNil())
})
})
})
5 changes: 5 additions & 0 deletions pkg/client/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var _ = AfterSuite(func() {

type testRunner struct {
tmpDir, tmpRootfs, ctrID string
enableTracing bool
rr *RuntimeRunner
}

Expand Down Expand Up @@ -213,6 +214,10 @@ func (tr *testRunner) configGivenEnv() *client.ConmonClient {
logger.Level = logrus.TraceLevel
cfg.ClientLogger = logger

if tr.enableTracing {
cfg.Tracing = &client.Tracing{Enabled: true}
}

sut, err := client.New(cfg)
Expect(err).To(BeNil())
Expect(sut).NotTo(BeNil())
Expand Down

0 comments on commit b99cc76

Please sign in to comment.