diff --git a/docs/docs/examples-tutorials/recipes/testing-kafka-go-api-with-opentelemetry-tracetest.mdx b/docs/docs/examples-tutorials/recipes/testing-kafka-go-api-with-opentelemetry-tracetest.mdx index 13e8140cad..be8b634ee4 100644 --- a/docs/docs/examples-tutorials/recipes/testing-kafka-go-api-with-opentelemetry-tracetest.mdx +++ b/docs/docs/examples-tutorials/recipes/testing-kafka-go-api-with-opentelemetry-tracetest.mdx @@ -20,12 +20,8 @@ keywords: image: https://res.cloudinary.com/djwdcmwdz/image/upload/v1698686403/docs/Blog_Thumbnail_14_rsvkmo.jpg --- -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; -import CodeBlock from '@theme/CodeBlock'; - :::note -[Check out the source code on GitHub here.](https://github.com/kubeshop/tracetest/tree/main/examples/quick-start-go-and-kafka) +[Check out the source code on GitHub here.](https://github.com/kubeshop/tracetest/tree/main/examples/quick-start-go-and-kafka) ::: [Tracetest](https://tracetest.io/) is a testing tool based on [OpenTelemetry](https://opentelemetry.io/) that allows you to test your distributed application. It allows you to use data from distributed traces generated by OpenTelemetry to validate and assert if your application has the desired behavior defined by your test definitions. @@ -34,19 +30,12 @@ import CodeBlock from '@theme/CodeBlock'; This is a simple quick start on how to configure two Go APIs to communicate via Kafka. They use OpenTelemetry instrumentation with traces, Jaeger as a trace data store, and Tracetest for enhancing your E2E and integration tests with trace-based testing. -```mdx-code-block - - -``` - ## Prerequisites **Tracetest Account**: - Sign up to [`app.tracetest.io`](https://app.tracetest.io) or follow the [get started](/getting-started/installation) docs. -- Create an [environment](/concepts/environments). -- Create an [environment token](/concepts/environment-tokens). -- Have access to the environment's [agent API key](/configuration/agent). +- Have access to the environment's [agent API key](https://app.tracetest.io/retrieve-token). **Docker**: Have [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed on your machine. @@ -64,11 +53,9 @@ cd tracetest/examples/quick-start-go-and-kafka Follow these instructions to run the quick start: 1. Copy the `.env.template` file to `.env`. -2. Log into the [Tracetest app](https://app.tracetest.io/). -3. This example is configured to use the Jaeger Tracing Backend. Ensure the environment you will be utilizing to run this example is also configured to use the Jaeger Tracing Backend by clicking on Settings, Tracing Backend, Jaeger, `endpoint: jaeger:16685`, Save. -4. Fill out the [token](https://docs.tracetest.io/concepts/environment-tokens) and [API key](https://docs.tracetest.io/concepts/agent) details by editing your `.env` file. You can find these values in the Settings area for your environment. -5. Run `docker compose up -d`. -6. Run tests from the Tracetest Web UI by accessing the producer URL `http://producer-api:8080/publish`, and by using a Kafka trigger on URL `kafka:9092` of the consumer. +2. Fill out the [TRACETEST_TOKEN and ENVIRONMENT_ID](https://app.tracetest.io/retrieve-token) details by editing your `.env` file. +3. Run `docker compose run tracetest-run`. +4. Follow the links in the output to view the test results. Follow along with the sections below for an in detail breakdown of what the example you just ran did and how it works. @@ -94,24 +81,24 @@ The server starts by running the `main.go` file as you can see [in the `Dockerfi [The `docker-compose.yaml` contains one service](https://github.com/kubeshop/tracetest/blob/3caff14247d745035f7cbbb68a7208f6da4e51fd/examples/quick-start-go-and-kafka/docker-compose.yaml#L3C3-L21C1) for the Go Producer API. ```yaml - producer-api: - image: quick-start-producer-api - platform: linux/amd64 - build: ./producer-api - extra_hosts: - - "host.docker.internal:host-gateway" - ports: - - 8080:8080 - environment: - - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 - - OTEL_SERVICE_NAME=producer-api - - KAFKA_BROKER_URL=kafka:9092 - - KAFKA_TOPIC=messaging - depends_on: - otel-collector: - condition: service_started - kafka: - condition: service_healthy +producer-api: + image: quick-start-producer-api + platform: linux/amd64 + build: ./producer-api + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - 8080:8080 + environment: + - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 + - OTEL_SERVICE_NAME=producer-api + - KAFKA_BROKER_URL=kafka:9092 + - KAFKA_TOPIC=messaging + depends_on: + otel-collector: + condition: service_started + kafka: + condition: service_healthy ``` ## Go Consumer Worker @@ -130,24 +117,24 @@ The server starts by running the `main.go` file. As you can see [in the `Dockerf [The `docker-compose.yaml` contains one service](https://github.com/kubeshop/tracetest/blob/f5d7cb6747813838623d1a61424788e12f21cece/examples/quick-start-go-and-kafka/docker-compose.yaml#L22-L39) for the Go Producer API. ```yaml - consumer-worker: - image: quick-start-consumer-worker - platform: linux/amd64 - build: ./consumer-worker - extra_hosts: - - "host.docker.internal:host-gateway" - environment: - - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 - - OTEL_SERVICE_NAME=consumer-worker - - KAFKA_BROKER_URL=kafka:9092 - - KAFKA_TOPIC=messaging - depends_on: - otel-collector: - condition: service_started - kafka: - condition: service_healthy - producer-api: - condition: service_started +consumer-worker: + image: quick-start-consumer-worker + platform: linux/amd64 + build: ./consumer-worker + extra_hosts: + - "host.docker.internal:host-gateway" + environment: + - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 + - OTEL_SERVICE_NAME=consumer-worker + - KAFKA_BROKER_URL=kafka:9092 + - KAFKA_TOPIC=messaging + depends_on: + otel-collector: + condition: service_started + kafka: + condition: service_healthy + producer-api: + condition: service_started ``` ## Running the Go Apps, Kafka, and Tracetest @@ -155,372 +142,34 @@ The server starts by running the `main.go` file. As you can see [in the `Dockerf Configure the `.env` like shown below. ```bash -TRACETEST_API_KEY="" +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" ``` To start the full setup, run the following command: ```bash -docker compose up -d +docker compose run tracetest-run ``` -This example is configured to use the Jaeger Tracing Backend. Ensure the environment you're using is configured to use the Jaeger Tracing Backend by clicking on Settings, Tracing Backend, Jaeger, `endpoint: jaeger:16685`, Save. +This will: +1. Start the Node.js app, the OpenTelemetry Collector, and send the traces to Jaeger. +2. Start the Tracetest Agent. +3. Configure the tracing backend and create tests in your environment. +4. Run the tests. -Or, use [the CLI](/cli/cli-installation-reference) and [the `tracetest-tracing-backend.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/tracetest/tracetest-tracing-backend.yaml) sets the tracing backend to Jaeger, and tells Tracetest Agent to poll for traces from Jaeger. - -```yaml title="./tracetest/tracetest-tracing-backend.yaml" ---- -type: DataStore -spec: - name: Jaeger - type: jaeger - default: true - jaeger: - endpoint: jaeger:16685 - tls: - insecure: true -``` - -```bash -tracetest configure -t -tracetest apply datastore -f ./tracetest/tracetest-tracing-backend.yaml -``` - -## Run Tracetest Tests +## Manually Running the Tracetest Tests Open the URL and start creating tests! Make sure to use the `http://producer-api:8080/publish` URL in your test creation, because your Go app and Tracetest Agent are in the same network. And, use the [Kafka trigger](http://localhost:3000/web-ui/creating-tests-kafka) for the Consumer Worker. Here are two sample tests you can get started with quickly. -👉 [Testing the Consumer](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/test-consumer.yaml) +👉 [Testing the Consumer](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/resources/test.yaml) 👉 [Testing the Producer](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/test-producer.yaml) -To trigger tests in the CLI, first [install the CLI](/cli/cli-installation-reference), [configure it](/cli/configuring-your-cli), and [run a test](/cli/running-tests). - -From the root of the quick start directory, run: - -```bash -tracetest configure -t -tracetest run test -f ./test-producer.yaml -tracetest run test -f ./test-consumer.yaml -``` - -```mdx-code-block - - -``` - -## Prerequisites - -You will need [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed on your machine to run this quick start app! - -## Project Structure - -The project is built with Docker Compose. It contains one `docker-compose.yaml` file that configures Tracetest, Jaeger, OpenTelemetry Collector, and both Go apps. - -### 1. Go APIs - -The `docker-compose.yaml` file references two Go apps, and one Kafka stream. - -- Producer API: Builds the `./producer-api/Dockerfile` -- Consumer Worker: Builds the `./consumer-worker/Dockerfile` - -The producer publishes a message to Kafka when receiving a POST request to the `/publish` endpoint. - -The consumer accepts a message through Kafka. - - -### 2. Tracetest - -The `collector.config.yaml`, `tracetest-provision.yaml`, and `tracetest-config.yaml` in the `tracetest` directory are for the setting up Tracetest and the OpenTelemetry Collector. - -### Docker Compose Network - -All `services` in the `docker-compose.yaml` are on the same network and will be reachable by hostname from within other services. E.g. `jaeger:4317` in the `collector.config.yaml` will map to the `jaeger` service, where the port `4317` is the port where Jaeger accepts traces. - -## Go Producer API - -The Go API is a simple HTTP server, [contained in the `main.go` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/producer-api/main.go). - -The OpenTelemetry tracing is [contained in the `./telemetry/telemetry.go` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/producer-api/telemetry/telemetry.go). -Traces will be sent to the OpenTelemetry Collector, and forwarded to Jaeger. - -Traces will be sent to either the `grpc` endpoint. The hostname and port as seen in the env section of the `producer-api` in the `docker-compose.yaml` is: - -- `OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317` - -The server starts by running the `main.go` file. - -As you can see [in the `Dockerfile`](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/producer-api/Dockerfile). - -```Dockerfile -FROM golang:alpine as builder -ENV GO111MODULE=on -RUN apk update && apk add --no-cache git - -WORKDIR /app -COPY go.mod ./ -COPY go.sum ./ -RUN go mod download -COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/main . - -FROM scratch -COPY --from=builder /app/bin/main . -CMD ["./main"] -``` - -And, [the `docker-compose.yaml` contains one service](https://github.com/kubeshop/tracetest/blob/3caff14247d745035f7cbbb68a7208f6da4e51fd/examples/quick-start-go-and-kafka/docker-compose.yaml#L3C3-L21C1) for the Go Producer API. - -```yaml - producer-api: - image: quick-start-producer-api - platform: linux/amd64 - build: ./producer-api - extra_hosts: - - "host.docker.internal:host-gateway" - ports: - - 8080:8080 - environment: - - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 - - OTEL_SERVICE_NAME=producer-api - - KAFKA_BROKER_URL=kafka:9092 - - KAFKA_TOPIC=messaging - depends_on: - otel-collector: - condition: service_started - kafka: - condition: service_healthy -``` - -## Go Consumer Worker - -The Go API is a simple HTTP server, [contained in the `main.go` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/producer-api/main.go). - -The OpenTelemetry tracing is [contained in the `./telemetry/telemetry.go` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/producer-api/telemetry/telemetry.go). -Traces will be sent to the OpenTelemetry Collector, and forwarded to Jaeger. - -Traces will be sent to either the `grpc` endpoint. The hostname and port as seen in the env section of the `producer-api` in the `docker-compose.yaml` is: - -- `OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317` - -The server starts by running the `main.go` file. - -As you can see [in the `Dockerfile`](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/producer-api/Dockerfile). - -```Dockerfile -FROM golang:alpine as builder -ENV GO111MODULE=on -RUN apk update && apk add --no-cache git - -WORKDIR /app -COPY go.mod ./ -COPY go.sum ./ -RUN go mod download -COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/main . - -FROM scratch -COPY --from=builder /app/bin/main . -CMD ["./main"] -``` - -And, [the `docker-compose.yaml` contains one service](https://github.com/kubeshop/tracetest/blob/3caff14247d745035f7cbbb68a7208f6da4e51fd/examples/quick-start-go-and-kafka/docker-compose.yaml#L3C3-L21C1) for the Go Producer API. - -```yaml - producer-api: - image: quick-start-producer-api - platform: linux/amd64 - build: ./producer-api - extra_hosts: - - "host.docker.internal:host-gateway" - ports: - - 8080:8080 - environment: - - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 - - OTEL_SERVICE_NAME=producer-api - - KAFKA_BROKER_URL=kafka:9092 - - KAFKA_TOPIC=messaging - depends_on: - otel-collector: - condition: service_started - kafka: - condition: service_healthy -``` - -## Tracetest - -The `docker-compose.yaml` configures four services more including Tracetest. - -- **Postgres** - Postgres is a prerequisite for Tracetest to work. It stores trace data when running the trace-based tests. -- [**OpenTelemetry Collector**](https://opentelemetry.io/docs/collector/) - A vendor-agnostic implementation of how to receive, process and export telemetry data. -- [**Jaeger**](https://www.jaegertracing.io/) - Open source, distributed tracing platform. Monitor and troubleshoot workflows in complex distributed systems. -- [**Tracetest**](https://tracetest.io/) - Trace-based testing that generates end-to-end tests automatically from traces. - -```yaml - tracetest: - image: kubeshop/tracetest:${TAG:-latest} - platform: linux/amd64 - volumes: - - type: bind - source: ./tracetest/tracetest-config.yaml - target: /app/tracetest.yaml - - type: bind - source: ./tracetest/tracetest-provision.yaml - target: /app/provisioning.yaml - ports: - - 11633:11633 - command: --provisioning-file /app/provisioning.yaml - depends_on: - postgres: - condition: service_healthy - otel-collector: - condition: service_started - jaeger: - condition: service_started - healthcheck: - test: ["CMD", "wget", "--spider", "localhost:11633"] - interval: 1s - timeout: 3s - retries: 60 - environment: - TRACETEST_DEV: ${TRACETEST_DEV} - - postgres: - image: postgres:14 - environment: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - healthcheck: - test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" - interval: 1s - timeout: 5s - retries: 60 - ports: - - 5432:5432 - - otel-collector: - image: otel/opentelemetry-collector-contrib:0.59.0 - command: - - "--config" - - "/otel-local-config.yaml" - volumes: - - ./tracetest/collector.config.yaml:/otel-local-config.yaml - ports: - - 4317:4317 - depends_on: - jaeger: - condition: service_started - - jaeger: - image: jaegertracing/all-in-one:latest - restart: unless-stopped - ports: - - 16686:16686 - - 16685:16685 - environment: - - COLLECTOR_OTLP_ENABLED=true - healthcheck: - test: ["CMD", "wget", "--spider", "localhost:16686"] - interval: 1s - timeout: 3s - retries: 60 -``` - -Tracetest depends on all three services, Postgres, Jaeger, and the OpenTelemetry Collector. Both Tracetest and the OpenTelemetry Collector require config files to be loaded via a volume. The volumes are mapped from the root directory into the `tracetest` directory and the respective config files. - -[The `tracetest-config.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/tracetest/tracetest-config.yaml) contains the basic setup of connecting Tracetest to the Postgres instance. - -```yaml -postgres: - host: postgres - user: postgres - password: postgres - port: 5432 - dbname: postgres - params: sslmode=disable -``` - -[The `tracetest-provision.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/tracetest/tracetest-provision.yaml) provisions the trace data store and polling to store in the Postgres database. The data store is set to OTLP, meaning the traces will be stored in Tracetest itself. - -```yaml ---- -type: PollingProfile -spec: - name: Default - strategy: periodic - default: true - periodic: - retryDelay: 5s - timeout: 10m - ---- -type: DataStore -spec: - name: Jaeger - type: jaeger - default: true - jaeger: - endpoint: jaeger:16685 - tls: - insecure: true -``` - -But how are traces sent to Tracetest? - -[The `collector.config.yaml` explains that](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/tracetest/collector.config.yaml). It receives traces via the `grpc` or `http`. Then, exports them to Jaeger's OLTP endpoint `jaeger:4317`. - -```yaml -receivers: - otlp: - protocols: - grpc: - http: - -processors: - batch: - timeout: 100ms - -exporters: - logging: - loglevel: debug - otlp/jaeger: - endpoint: jaeger:4317 - tls: - insecure: true - -service: - pipelines: - traces/1: - receivers: [otlp] - processors: [batch] - exporters: [otlp/jaeger] -``` - -## Run Both the Go Apps and Tracetest - -To start both Go apps and Tracetest we will run this command: - -```bash -docker compose -f docker-compose.core.yaml up # add --build if the images are not built already -``` - -This will start your Tracetest instance on `http://localhost:11633/`. - -Open the URL and start creating tests! Make sure to use the `http://producer-api:8080/publish` URL in your test creation, because your Go app and Tracetest are in the same network. - -Here are two sample tests you can get started with quickly. - -👉 [Testing the Consumer](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/test-consumer.yaml) - -👉 [Testing the Producer](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-go-and-kafka/test-producer.yaml) - - -```mdx-code-block - - -``` ## Learn More diff --git a/examples/quick-start-go-and-kafka/.env.template b/examples/quick-start-go-and-kafka/.env.template index d780ddb12c..c0437a9d95 100644 --- a/examples/quick-start-go-and-kafka/.env.template +++ b/examples/quick-start-go-and-kafka/.env.template @@ -1,2 +1,4 @@ -TRACETEST_API_KEY="" -TRACETEST_API_TOKEN="" +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" diff --git a/examples/quick-start-go-and-kafka/Dockerfile.tracetest b/examples/quick-start-go-and-kafka/Dockerfile.tracetest new file mode 100644 index 0000000000..883f239155 --- /dev/null +++ b/examples/quick-start-go-and-kafka/Dockerfile.tracetest @@ -0,0 +1,11 @@ +FROM alpine + +WORKDIR /app +ARG TRACETEST_IMAGE_VERSION=v1.4.0 + +RUN apk --update add bash jq curl +RUN curl -L https://raw.githubusercontent.com/kubeshop/tracetest/main/install-cli.sh | bash -s -- $TRACETEST_IMAGE_VERSION + +WORKDIR /resources + +ENTRYPOINT ["echo", "Tracetest CLI installed"] diff --git a/examples/quick-start-go-and-kafka/tracetest/collector.config.yaml b/examples/quick-start-go-and-kafka/collector.config.yaml similarity index 88% rename from examples/quick-start-go-and-kafka/tracetest/collector.config.yaml rename to examples/quick-start-go-and-kafka/collector.config.yaml index a61a770ffd..e4d1c9679f 100644 --- a/examples/quick-start-go-and-kafka/tracetest/collector.config.yaml +++ b/examples/quick-start-go-and-kafka/collector.config.yaml @@ -21,4 +21,4 @@ service: traces/1: receivers: [otlp] processors: [batch] - exporters: [otlp/jaeger] + exporters: [logging, otlp/jaeger] diff --git a/examples/quick-start-go-and-kafka/docker-compose.core.yaml b/examples/quick-start-go-and-kafka/docker-compose.core.yaml deleted file mode 100644 index 1a4ed88fc9..0000000000 --- a/examples/quick-start-go-and-kafka/docker-compose.core.yaml +++ /dev/null @@ -1,130 +0,0 @@ -version: '3' -services: - producer-api: - image: quick-start-producer-api - platform: linux/amd64 - build: ./producer-api - extra_hosts: - - "host.docker.internal:host-gateway" - ports: - - 8080:8080 - environment: - - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 - - OTEL_SERVICE_NAME=producer-api - - KAFKA_BROKER_URL=kafka:9092 - - KAFKA_TOPIC=messaging - depends_on: - otel-collector: - condition: service_started - kafka: - condition: service_healthy - - consumer-worker: - image: quick-start-consumer-worker - platform: linux/amd64 - build: ./consumer-worker - extra_hosts: - - "host.docker.internal:host-gateway" - environment: - - OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 - - OTEL_SERVICE_NAME=consumer-worker - - KAFKA_BROKER_URL=kafka:9092 - - KAFKA_TOPIC=messaging - depends_on: - otel-collector: - condition: service_started - kafka: - condition: service_healthy - producer-api: - condition: service_started - - kafka: - image: quick-start-kafka - build: ./kafka - restart: unless-stopped - environment: - - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,PLAINTEXT_HOST://127.0.0.1:29092 - - OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 - - OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=cumulative - - OTEL_RESOURCE_ATTRIBUTES="service.namespace=quick-start-go-and-kafka" - - OTEL_SERVICE_NAME=kafka - - KAFKA_HEAP_OPTS=-Xmx200m -Xms200m - healthcheck: - test: nc -z kafka 9092 - start_period: 10s - interval: 5s - timeout: 10s - retries: 10 - depends_on: - otel-collector: - condition: service_started - ports: - - 29092:29092 - - tracetest: - image: kubeshop/tracetest:${TAG:-latest} - platform: linux/amd64 - volumes: - - type: bind - source: ./tracetest/tracetest-config.yaml - target: /app/tracetest.yaml - - type: bind - source: ./tracetest/tracetest-provision.yaml - target: /app/provisioning.yaml - ports: - - 11633:11633 - command: --provisioning-file /app/provisioning.yaml - depends_on: - postgres: - condition: service_healthy - otel-collector: - condition: service_started - jaeger: - condition: service_started - healthcheck: - test: ["CMD", "wget", "--spider", "localhost:11633"] - interval: 1s - timeout: 3s - retries: 60 - environment: - TRACETEST_DEV: ${TRACETEST_DEV} - - postgres: - image: postgres:14 - environment: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - healthcheck: - test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" - interval: 1s - timeout: 5s - retries: 60 - ports: - - 5432:5432 - - otel-collector: - image: otel/opentelemetry-collector-contrib:0.59.0 - command: - - "--config" - - "/otel-local-config.yaml" - volumes: - - ./tracetest/collector.config.yaml:/otel-local-config.yaml - ports: - - 4317:4317 - depends_on: - jaeger: - condition: service_started - - jaeger: - image: jaegertracing/all-in-one:latest - restart: unless-stopped - ports: - - 16686:16686 - - 16685:16685 - environment: - - COLLECTOR_OTLP_ENABLED=true - healthcheck: - test: ["CMD", "wget", "--spider", "localhost:16686"] - interval: 1s - timeout: 3s - retries: 60 diff --git a/examples/quick-start-go-and-kafka/docker-compose.yaml b/examples/quick-start-go-and-kafka/docker-compose.yaml index ecab8bf20c..2bf3297c2d 100644 --- a/examples/quick-start-go-and-kafka/docker-compose.yaml +++ b/examples/quick-start-go-and-kafka/docker-compose.yaml @@ -61,20 +61,13 @@ services: ports: - 29092:29092 - # Cloud-based Managed Tracetest - tracetest-agent: - image: kubeshop/tracetest-agent:latest - environment: - # Find the Agent API Key here: https://docs.tracetest.io/configuration/agent - - TRACETEST_API_KEY=${TRACETEST_API_KEY} - otel-collector: - image: otel/opentelemetry-collector-contrib:0.59.0 + image: otel/opentelemetry-collector-contrib:0.100.0 command: - "--config" - "/otel-local-config.yaml" volumes: - - ./tracetest/collector.config.yaml:/otel-local-config.yaml + - ./collector.config.yaml:/otel-local-config.yaml ports: - 4317:4317 depends_on: @@ -94,3 +87,49 @@ services: interval: 1s timeout: 3s retries: 60 + + # Cloud-based Managed Tracetest + tracetest-agent: + image: kubeshop/tracetest-agent:latest + environment: + # Get the required information here: https://app.tracetest.io/retrieve-token + - TRACETEST_API_KEY=${TRACETEST_TOKEN} + - TRACETEST_ENVIRONMENT_ID=${TRACETEST_ENVIRONMENT_ID} + + tracetest-apply: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/apply.sh + networks: + default: null + depends_on: + producer-api: + condition: service_started + consumer-worker: + condition: service_started + tracetest-agent: + condition: service_started + + tracetest-run: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/run.sh + networks: + default: null + depends_on: + tracetest-apply: + condition: service_completed_successfully \ No newline at end of file diff --git a/examples/quick-start-go-and-kafka/resources/apply.sh b/examples/quick-start-go-and-kafka/resources/apply.sh new file mode 100644 index 0000000000..13b878ba47 --- /dev/null +++ b/examples/quick-start-go-and-kafka/resources/apply.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID + +apply() { + echo "Configuring TraceTest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Applying Resources" + tracetest apply datastore -f /resources/datastore.yaml + tracetest apply test -f /resources/test.yaml +} + +apply diff --git a/examples/quick-start-go-and-kafka/tracetest/tracetest-tracing-backend.yaml b/examples/quick-start-go-and-kafka/resources/datastore.yaml similarity index 68% rename from examples/quick-start-go-and-kafka/tracetest/tracetest-tracing-backend.yaml rename to examples/quick-start-go-and-kafka/resources/datastore.yaml index c8b278f9c2..72f8294fcd 100644 --- a/examples/quick-start-go-and-kafka/tracetest/tracetest-tracing-backend.yaml +++ b/examples/quick-start-go-and-kafka/resources/datastore.yaml @@ -1,10 +1,12 @@ ---- type: DataStore spec: - name: Jaeger + id: current + name: jaeger type: jaeger default: true jaeger: endpoint: jaeger:16685 + headers: + "": "" tls: insecure: true diff --git a/examples/quick-start-go-and-kafka/resources/run.sh b/examples/quick-start-go-and-kafka/resources/run.sh new file mode 100644 index 0000000000..05d0f41724 --- /dev/null +++ b/examples/quick-start-go-and-kafka/resources/run.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID + +run() { + echo "Configuring Tracetest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Running Trace-Based Tests..." + tracetest run test -f /resources/test.yaml +} + +run diff --git a/examples/quick-start-go-and-kafka/test-producer.yaml b/examples/quick-start-go-and-kafka/resources/test-producer.yaml similarity index 100% rename from examples/quick-start-go-and-kafka/test-producer.yaml rename to examples/quick-start-go-and-kafka/resources/test-producer.yaml diff --git a/examples/quick-start-go-and-kafka/test-consumer.yaml b/examples/quick-start-go-and-kafka/resources/test.yaml similarity index 99% rename from examples/quick-start-go-and-kafka/test-consumer.yaml rename to examples/quick-start-go-and-kafka/resources/test.yaml index 717fbaadfd..c4de582892 100644 --- a/examples/quick-start-go-and-kafka/test-consumer.yaml +++ b/examples/quick-start-go-and-kafka/resources/test.yaml @@ -18,3 +18,4 @@ spec: name: It processed a message from Kafka assertions: - attr:tracetest.selected_spans.count = 1 + diff --git a/examples/quick-start-go-and-kafka/tracetest/tracetest-config.yaml b/examples/quick-start-go-and-kafka/tracetest/tracetest-config.yaml deleted file mode 100644 index 5e732f6d38..0000000000 --- a/examples/quick-start-go-and-kafka/tracetest/tracetest-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -postgres: - host: postgres - user: postgres - password: postgres - port: 5432 - dbname: postgres - params: sslmode=disable diff --git a/examples/quick-start-go-and-kafka/tracetest/tracetest-provision.yaml b/examples/quick-start-go-and-kafka/tracetest/tracetest-provision.yaml deleted file mode 100644 index bcf9a527e0..0000000000 --- a/examples/quick-start-go-and-kafka/tracetest/tracetest-provision.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -type: PollingProfile -spec: - name: Default - strategy: periodic - default: true - periodic: - retryDelay: 5s - timeout: 10m - ---- -type: DataStore -spec: - name: Jaeger - type: jaeger - default: true - jaeger: - endpoint: jaeger:16685 - tls: - insecure: true