-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add tracetesting event driven system example (#3286)
* chore: add tracetesting event driver systems example * update: test cases for event-driven systems * update README * removing binaries from repo * removing java binaries from quick-start-java
- Loading branch information
1 parent
900f483
commit 4e51f27
Showing
39 changed files
with
2,692 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
.gradle | ||
./app/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
157
examples/tracetesting-event-driven-systems/docker-compose.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
- [email protected]: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 |
14 changes: 14 additions & 0 deletions
14
examples/tracetesting-event-driven-systems/payment-order-api/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
19 changes: 19 additions & 0 deletions
19
examples/tracetesting-event-driven-systems/payment-order-api/config/config.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
examples/tracetesting-event-driven-systems/payment-order-api/go.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.