Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add tracetesting event driven system example #3286

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/quick-start-go-and-kafka/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ This is a simple quick start on how to configure two Go lang apps that interacts

If you want to run this example, just execute `docker compose up` on this folder.

To execute a Trace-based test with Tracetest against this structure just run `tracetest run test -f test.yaml`.
To execute a Trace-based test with Tracetest against this structure just run `tracetest run test -f test-producer.yaml` or `tracetest run test -f test-consumer.yaml`.

Feel free to check out the [docs](https://docs.tracetest.io/), and join our [Discord Community](https://discord.gg/8MtcMrQNbX) for more info!
2 changes: 0 additions & 2 deletions examples/quick-start-java/quick_start_api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#based on https://github.com/open-telemetry/opentelemetry-demo/blob/main/src/adservice/Dockerfile

FROM eclipse-temurin:17-jdk AS builder

WORKDIR /usr/src/app/
Expand Down
Binary file not shown.
Binary file not shown.
11 changes: 0 additions & 11 deletions examples/quick-start-java/quick_start_api/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ dependencies {
implementation("io.opentelemetry.instrumentation:opentelemetry-runtime-telemetry-java8")
implementation("io.opentelemetry.instrumentation:opentelemetry-log4j-appender-2.17")
implementation("io.opentelemetry.instrumentation:opentelemetry-spring-webmvc-6.0")

// implementation(platform("io.opentelemetry:opentelemetry-bom:1.31.0"))
// implementation("io.opentelemetry:opentelemetry-api:1.31.0")
// implementation("io.opentelemetry:opentelemetry-sdk:1.31.0")
// implementation("io.opentelemetry:opentelemetry-sdk-metrics:1.31.0")
// implementation("io.opentelemetry.semconv:opentelemetry-semconv:1.21.0-alpha")
// implementation("io.opentelemetry:opentelemetry-exporter-otlp:1.31.0")
// implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.31.0")
// implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:1.31.0")

// implementation("io.opentelemetry.instrumentation:opentelemetry-spring-webmvc-6.0")
}

java {
Expand Down
1 change: 1 addition & 0 deletions examples/tracetesting-event-driven-systems/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
45 changes: 45 additions & 0 deletions examples/tracetesting-event-driven-systems/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Tracetesting Event-driven systems

> [Read the detailed recipe for setting up OpenTelemetry Collector with Tractest in our documentation.](https://docs.tracetest.io/examples-tutorials/recipes/running-tracetest-without-a-trace-data-store)

This is a simple example from the article "Testing Event-driven Systems with OpenTelemetry" showing how to test an event-driven system using [Apache Kafka](https://kafka.apache.org/) as a event backbone.

If you want to run this example, just execute `docker compose up` on this folder.

Feel free to check out the [docs](https://docs.tracetest.io/), and join our [Discord Community](https://discord.gg/8MtcMrQNbX) for more info!

## Test Scenarios

We can test four different scenarios with this example:

### **Scenario 1**: Add order though Rest API

Here, we send a message as a regular user and check if all components are called as intended:

```sh
tracetest run test -f test-payment-order-submit-with-rest-api.yaml
```

### **Scenario 2**: Add order directly on Kafka

On this scenario, we want to validate only the event consumers and check if they are properly working:

```sh
tracetest run test -f test-payment-order-submit-with-message.yaml
```

### **Scenario 3**: Validate Risk Analysis for high value orders

This scenario checks if the Risk Analysis consumer flags a order sent into Kafka as risky and check if it was persisted correctly:

```sh
tracetest run test -f test-risk-analysis-using-order-with-high-value.yaml
```

### **Scenario 4**: Validate Risk Analysis for low value orders

This scenario checks if the Risk Analysis consumer flags a order sent into Kafka as normal and check if it was persisted correctly:

```sh
tracetest run test -f test-risk-analysis-using-order-with-low-value.yaml
```
157 changes: 157 additions & 0 deletions examples/tracetesting-event-driven-systems/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
version: '3'
services:
payment-order-api:
image: payment-order-api
platform: linux/amd64
build: ./payment-order-api
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- 8080:8080
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317
- OTEL_SERVICE_NAME=payment-order-api
- KAFKA_BROKER_URL=kafka:9092
- KAFKA_TOPIC=paymentOrders
depends_on:
otel-collector:
condition: service_started
kafka:
condition: service_healthy

payment-storage-worker:
image: payment-storage-worker
platform: linux/amd64
build: ./payment-storage-worker
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317
- OTEL_SERVICE_NAME=payment-storage-worker
- KAFKA_BROKER_URL=kafka:9092
- KAFKA_TOPIC=paymentOrders
depends_on:
otel-collector:
condition: service_started
kafka:
condition: service_healthy
payment-order-api:
condition: service_started

risk-analysis-worker:
image: risk-analysis-worker
platform: linux/amd64
build: ./risk-analysis-worker
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
- OTEL_SERVICE_NAME=risk-analysis-worker
- OTEL_TRACES_EXPORTER=otlp
- OTEL_METRICS_EXPORTER=none
- OTEL_LOGS_EXPORTER=none
- KAFKA_BROKER_URL=kafka:9092
- KAFKA_TOPIC=paymentOrders
depends_on:
otel-collector:
condition: service_started
kafka:
condition: service_healthy
payment-order-api:
condition: service_started

kafka:
image: confluentinc/cp-kafka:latest-ubi8
ports:
- 29092:29092
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,PLAINTEXT_HOST://127.0.0.1:29092
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093,PLAINTEXT_HOST://:29092
- KAFKA_CONTROLLER_QUORUM_VOTERS=1@0.0.0.0:9093
- KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
- KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=0
- KAFKA_PROCESS_ROLES=controller,broker
- KAFKA_NODE_ID=1
- KAFKA_METADATA_LOG_SEGMENT_MS=15000
- KAFKA_METADATA_MAX_RETENTION_MS=60000
- KAFKA_METADATA_LOG_MAX_RECORD_BYTES_BETWEEN_SNAPSHOTS=2800
- KAFKA_AUTO_CREATE_TOPICS_ENABLE=true
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
- KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1
- KAFKA_HEAP_OPTS=-Xmx200m -Xms200m
- CLUSTER_ID=ckjPoprWQzOf0-FuNkGfFQ
healthcheck:
test: nc -z kafka 9092
start_period: 10s
interval: 5s
timeout: 10s
retries: 10

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package config

import "os"

type Config struct {
OtelExporterEndpoint string
OtelServiceName string
KafkaBrokerUrl string
KafkaTopic string
}

func Current() *Config {
return &Config{
OtelExporterEndpoint: os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"),
OtelServiceName: os.Getenv("OTEL_SERVICE_NAME"),
KafkaBrokerUrl: os.Getenv("KAFKA_BROKER_URL"),
KafkaTopic: os.Getenv("KAFKA_TOPIC"),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module github.com/kubeshop/tracetest/examples/tracetesting-event-driven-systems/payment-order-api

go 1.20

require (
github.com/Shopify/sarama v1.38.1
go.opentelemetry.io/contrib/instrumentation/github.com/Shopify/sarama/otelsarama v0.42.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
go.opentelemetry.io/otel/trace v1.16.0
go.uber.org/zap v1.24.0
google.golang.org/grpc v1.56.2
)

require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/eapache/go-resiliency v1.3.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230111030713-bf00bc1b83b6 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.3 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/klauspost/compress v1.15.14 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)