Skip to content

Commit

Permalink
feat(examples): Adding Tracetest Typescript Example
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar committed Jan 24, 2024
1 parent 1c22e62 commit 58e26cc
Show file tree
Hide file tree
Showing 12 changed files with 736 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/quick-start-typescript/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TRACETEST_API_TOKEN=
POKESHOP_DEMO_URL=http://localhost:8081
TRACETEST_AGENT_API_KEY=
3 changes: 3 additions & 0 deletions examples/quick-start-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
dist
3 changes: 3 additions & 0 deletions examples/quick-start-typescript/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
31 changes: 31 additions & 0 deletions examples/quick-start-typescript/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM node as builder

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json ./

RUN npm ci

COPY . .

RUN npm run build

FROM node:slim

ENV NODE_ENV production
USER node

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json ./

RUN npm ci --production

COPY --from=builder /usr/src/app/dist ./dist

EXPOSE 8080
CMD [ "node", "dist/index.js" ]
35 changes: 35 additions & 0 deletions examples/quick-start-typescript/collector.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
receivers:
otlp:
protocols:
grpc:
http:
cors:
allowed_origins:
- "http://*"
- "https://*"

processors:
batch:

exporters:
logging:
loglevel: debug
jaeger:
endpoint: ${JAEGER_ENDPOINT}
tls:
insecure: true
otlp/trace:
endpoint: tracetest-agent:4317
tls:
insecure: true

service:
pipelines:
traces:
receivers: [otlp]
processors: []
exporters: [logging, jaeger]
traces/1:
receivers: [otlp]
processors: [batch]
exporters: [otlp/trace]
85 changes: 85 additions & 0 deletions examples/quick-start-typescript/definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { TestResource } from '@tracetest/core/dist/modules/openapi-client';

export const importDefinition: TestResource = {
type: 'Test',
spec: {
id: '99TOHzpSR',
name: 'Typescript: Import a Pokemon',
trigger: {
type: 'http',
httpRequest: {
method: 'POST',
url: '${var:BASE_URL}/import',
body: '{"id": ${var:POKEMON_ID}}',
headers: [
{
key: 'Content-Type',
value: 'application/json',
},
],
},
},
specs: [
{
selector: 'span[tracetest.span.type="general" name = "validate request"] span[tracetest.span.type="http"]',
name: 'All HTTP Spans: Status code is 200',
assertions: ['attr:http.status_code = 200'],
},
{
selector: 'span[tracetest.span.type="http" name="GET" http.method="GET"]',
assertions: ['attr:http.route = "/api/v2/pokemon/${var:POKEMON_ID}"'],
},
{
selector: 'span[tracetest.span.type="database"]',
name: 'All Database Spans: Processing time is less than 1s',
assertions: ['attr:tracetest.span.duration < 1s'],
},
],
outputs: [
{
name: 'DATABASE_POKEMON_ID',
selector:
'span[tracetest.span.type="database" name="create pokeshop.pokemon" db.system="postgres" db.name="pokeshop" db.user="ashketchum" db.operation="create" db.sql.table="pokemon"]',
value: "attr:db.result | json_path '$.id'",
},
],
},
};

export const deleteDefinition: TestResource = {
type: 'Test',
spec: {
id: 'C2gwdktIR',
name: 'Typescript: Delete a Pokemon',
trigger: {
type: 'http',
httpRequest: {
method: 'DELETE',
url: '${var:BASE_URL}/${var:POKEMON_ID}',
headers: [
{
key: 'Content-Type',
value: 'application/json',
},
],
},
},
specs: [
{
selector:
'span[tracetest.span.type="database" db.system="redis" db.operation="del" db.redis.database_index="0"]',
assertions: ['attr:db.payload = \'{"key":"pokemon-${var:POKEMON_ID}"}\''],
},
{
selector:
'span[tracetest.span.type="database" name="delete pokeshop.pokemon" db.system="postgres" db.name="pokeshop" db.user="ashketchum" db.operation="delete" db.sql.table="pokemon"]',
assertions: ['attr:db.result = 1'],
},
{
selector: 'span[tracetest.span.type="database"]',
name: 'All Database Spans: Processing time is less than 100ms',
assertions: ['attr:tracetest.span.duration < 100ms'],
},
],
},
};
168 changes: 168 additions & 0 deletions examples/quick-start-typescript/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
version: '3.5'
name: pokeshop

services:
app:
build: .
environment:
TRACETEST_API_TOKEN: ${TRACETEST_API_TOKEN}
POKESHOP_DEMO_URL: ${POKESHOP_DEMO_URL}
TRACETEST_AGENT_API_KEY: ${TRACETEST_AGENT_API_KEY}
db:
image: postgres:14
ports:
- 5434:5432
environment:
POSTGRES_USER: ashketchum
POSTGRES_PASSWORD: squirtle123
POSTGRES_DB: pokeshop
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB']
interval: 1s
timeout: 5s
retries: 60

cache:
image: redis:6
ports:
- 6379:6379
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 1s
timeout: 3s
retries: 60

queue:
image: rabbitmq:3.12
restart: unless-stopped
ports:
- 5672:5672
- 15672:15672
healthcheck:
test: rabbitmq-diagnostics -q check_running
interval: 1s
timeout: 5s
retries: 60

jaeger:
image: jaegertracing/all-in-one:latest
ports:
- 14250:14250
- 16685:16685
- 16686:16686
environment:
- COLLECTOR_ZIPKIN_HOST_PORT=:9411
- COLLECTOR_OTLP_ENABLED=true
healthcheck:
test: ['CMD', 'wget', '--spider', 'localhost:16686']
interval: 1s
timeout: 3s
retries: 60

otel-collector:
image: otel/opentelemetry-collector-contrib:0.59.0
restart: unless-stopped
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- 55679:55679
- 8888:8888
- 4317:4317
- 4318:4318
command:
- '--config'
- '/otel-local-config.yaml'
volumes:
- ./collector.config.yaml:/otel-local-config.yaml
environment:
- JAEGER_ENDPOINT=jaeger:14250
depends_on:
jaeger:
condition: service_healthy

api:
build: .
environment:
REDIS_URL: cache
DATABASE_URL: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public
RABBITMQ_HOST: queue
POKE_API_BASE_URL: https://pokeapi.co/api/v2
COLLECTOR_ENDPOINT: http://otel-collector:4317
ZIPKIN_URL: http://localhost:9411
healthcheck:
test: ['CMD', 'wget', '--spider', 'localhost:8081/pokemon/healthcheck']
interval: 1s
timeout: 3s
retries: 60
ports:
- 8081:8081
depends_on:
db:
condition: service_healthy
cache:
condition: service_healthy
queue:
condition: service_healthy
jaeger:
condition: service_healthy
otel-collector:
condition: service_started
rpc:
build: .
environment:
REDIS_URL: cache
DATABASE_URL: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public
RABBITMQ_HOST: queue
POKE_API_BASE_URL: https://pokeapi.co/api/v2
COLLECTOR_ENDPOINT: http://otel-collector:4317
ZIPKIN_URL: http://localhost:9411
NPM_RUN_COMMAND: rpc
healthcheck:
test: ['CMD', 'wget', '--spider', 'localhost:8081/pokemon/healthcheck']
interval: 1s
timeout: 3s
retries: 60
ports:
- 8082:8082
depends_on:
db:
condition: service_healthy
cache:
condition: service_healthy
queue:
condition: service_healthy
jaeger:
condition: service_healthy
otel-collector:
condition: service_started

worker:
build: .
environment:
REDIS_URL: cache
DATABASE_URL: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public
RABBITMQ_HOST: queue
POKE_API_BASE_URL: https://pokeapi.co/api/v2
COLLECTOR_ENDPOINT: http://otel-collector:4317
ZIPKIN_URL: http://localhost:9411
NPM_RUN_COMMAND: worker
depends_on:
db:
condition: service_healthy
cache:
condition: service_healthy
queue:
condition: service_healthy
jaeger:
condition: service_healthy
otel-collector:
condition: service_started

tracetest-agent:
environment:
TRACETEST_DEV: ${TRACETEST_DEV}
TRACETEST_API_KEY: ${TRACETEST_AGENT_API_KEY}
TRACETEST_SERVER_URL: ${TRACETEST_SERVER_URL}
image: kubeshop/tracetest-agent:latest
networks:
default: null
Loading

0 comments on commit 58e26cc

Please sign in to comment.