Skip to content

Commit

Permalink
feat(docs): artillery integration example (#3664)
Browse files Browse the repository at this point in the history
* feat(docs): artillery integration example

* fix testFile key

* remove token

* --wip-- [skip ci]

* --wip-- [skip ci]

* set basic flow

* adding shared context

* fix examples

* .

* cleanup

* adding recipies and examples

* cleanup

* chore(examples): Adding Artillery + Playwright + Tracetest example (#3709)

* chore(examples): Adding Artillery + Playwright + Tracetest example

* docs(recipes): add pw + artillery + tt

---------

Co-authored-by: Adnan Rahic <ado.raha198@gmail.com>

---------

Co-authored-by: Automation <automation@schoren.me>
Co-authored-by: Oscar Reyes <oscar-rreyes1@hotmail.com>
Co-authored-by: Adnan Rahic <ado.raha198@gmail.com>
  • Loading branch information
4 people committed Mar 8, 2024
1 parent a3d8735 commit c861835
Show file tree
Hide file tree
Showing 30 changed files with 21,699 additions and 11 deletions.
12 changes: 12 additions & 0 deletions docs/docs/examples-tutorials/recipes.mdx
Expand Up @@ -40,10 +40,22 @@ These recipes show how to run tests against Serverless Functions with Tracetest.
- [Testing AWS Lambda Functions (Serverless Framework) with OpenTelemetry and Tracetest](/examples-tutorials/recipes/testing-lambda-functions-with-opentelemetry-tracetest)
- [Testing Cloudflare Workers with OpenTelemetry](/examples-tutorials/recipes/testing-cloudflare-workers-with-opentelemetry-tracetest)

## API Gateways

These recipes show how to run tests against services behind API Gateways with Tracetest.

### Tyk

- [Testing Distributed Services Proxied by Tyk Gateway (API Gateway) with OpenTelemetry and Tracetest](/examples-tutorials/recipes/testing-distributed-services-with-tyk-opentelemetry-tracetest)

## Performance Testing

These recipes show how to run performance tests with distributed traces.

### Artillery + Playwright + Tracetest

- [Performance Testing with Distributed Tracing using Artillery, Playwright and Tracetest](/examples-tutorials/recipes/running-playwright-performance-tests-with-artillery-and-tracetest)

## Trace Data Stores

These recipes show integrations with trace data stores and tracing vendors/providers.
Expand Down

Large diffs are not rendered by default.

383 changes: 383 additions & 0 deletions docs/docs/tools-and-integrations/artillery-engine.mdx

Large diffs are not rendered by default.

433 changes: 433 additions & 0 deletions docs/docs/tools-and-integrations/artillery-plugin.mdx

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/docs/tools-and-integrations/overview.mdx
Expand Up @@ -25,4 +25,6 @@ Tracetest can be integrated and used with other tools. See below which integrati

- [K6](/tools-and-integrations/k6) is a powerful tool to run load tests against any type of services (REST, GRPC, GraphQL, etc). It is widely used by Developers, Site Reliability Engineers and Software Engineers in Test/QA teams to find potential issues when testing real life scenarios in both controlled environments and production.

- [Artillery](/tools-and-integrations/artillery-plugin) is a modern, powerful load-testing toolkit. Artillery is designed to help developers and testers simulate traffic to their applications, APIs, and microservices. It allows users to define scenarios to test how their systems behave under different loads.

- [Testkube](/tools-and-integrations/testkube) is a Kubernetes-native testing framework for Testers and Developers that allows you to automate the executions of your existing testing tools inside your Kubernetes cluster, removing all the complexity from your CI/CD/GitOps pipelines.
43 changes: 32 additions & 11 deletions docs/sidebars.js
Expand Up @@ -153,6 +153,28 @@ const sidebars = {
},
],
},
{
type: "category",
label: "Performance Testing",
items: [
{
type: "doc",
id: "examples-tutorials/recipes/running-playwright-performance-tests-with-artillery-and-tracetest",
label: "Performance Testing with Distributed Tracing using Artillery, Playwright and Tracetest",
},
],
},
{
type: "category",
label: "API Gateways",
items: [
{
type: "doc",
id: "examples-tutorials/recipes/testing-distributed-services-with-tyk-opentelemetry-tracetest",
label: "Testing Distributed Services with Tyk, OpenTelemetry, and Tracetest",
},
],
},
{
type: "category",
label: "OpenTelemetry",
Expand Down Expand Up @@ -280,17 +302,6 @@ const sidebars = {
},
],
},
{
type: "category",
label: "Tyk",
items: [
{
type: "doc",
id: "examples-tutorials/recipes/testing-distributed-services-with-tyk-opentelemetry-tracetest",
label: "Testing Distributed Services with Tyk, OpenTelemetry, and Tracetest",
},
],
},
{
type: "category",
label: "Jaeger",
Expand Down Expand Up @@ -359,6 +370,16 @@ const sidebars = {
id: "tools-and-integrations/keptn",
label: "Keptn",
},
{
type: "doc",
id: "tools-and-integrations/artillery-plugin",
label: "Artillery Plugin",
},
{
type: "doc",
id: "tools-and-integrations/artillery-engine",
label: "Artillery Engine",
},
{
type: "doc",
id: "tools-and-integrations/k6",
Expand Down
2 changes: 2 additions & 0 deletions examples/quick-start-artillery-playwright/.env.template
@@ -0,0 +1,2 @@
TRACETEST_AGENT_API_KEY=
TRACETEST_API_TOKEN=
2 changes: 2 additions & 0 deletions examples/quick-start-artillery-playwright/.gitignore
@@ -0,0 +1,2 @@
.env
node_modules
3 changes: 3 additions & 0 deletions examples/quick-start-artillery-playwright/.prettierrc
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
5 changes: 5 additions & 0 deletions examples/quick-start-artillery-playwright/README.md
@@ -0,0 +1,5 @@
# Tracetest + Artillery + Playwright

> [Read the detailed recipe for setting up Tracetest + Artillery + Playwright in our documentation.](https://docs.tracetest.io/examples-tutorials/recipes/running-playwright-performance-tests-with-artillery-and-tracetest)
This is a quick start showing how you can create programs to run trace-based tests from your Artillery x Playwright setup utilizing the `@tracetest/playwright` NPM package. The example shows how to define the Tracetest tests, execute them, and wait for results to be ready. [Read the Tracetest + Artillery + Playwright Quick Start Docs](https://docs.tracetest.io/examples-tutorials/recipes/running-playwright-performance-tests-with-artillery-and-tracetest) to see how to run this example.
@@ -0,0 +1,8 @@
config:
target: http://localhost:8081
engines:
playwright: {}
processor: home.spec.ts
scenarios:
- engine: playwright
testFunction: importPokemon
35 changes: 35 additions & 0 deletions examples/quick-start-artillery-playwright/collector.config.yaml
@@ -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: [batch]
exporters: [logging, jaeger]
traces/1:
receivers: [otlp]
processors: [batch]
exporters: [otlp/trace]
146 changes: 146 additions & 0 deletions examples/quick-start-artillery-playwright/docker-compose.yml
@@ -0,0 +1,146 @@
version: "3.5"
name: pokeshop

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

# pokeshop demo services
postgres:
image: postgres:14
ports:
- 5434:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
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

otel-collector:
image: otel/opentelemetry-collector-contrib:0.59.0
restart: unless-stopped
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- 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:
image: kubeshop/demo-pokemon-api:latest
restart: unless-stopped
pull_policy: always
environment:
REDIS_URL: cache
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/postgres?schema=public
RABBITMQ_HOST: queue
POKE_API_BASE_URL: https://pokeapi.co/api/v2
COLLECTOR_ENDPOINT: http://otel-collector:4317
HTTP_COLLECTOR_ENDPOINT: http://localhost:4318/v1/traces
NPM_RUN_COMMAND: api
healthcheck:
test: ["CMD", "wget", "--spider", "localhost:8081"]
interval: 1s
timeout: 3s
retries: 60
ports:
- 8081:8081
depends_on:
postgres:
condition: service_healthy
cache:
condition: service_healthy
queue:
condition: service_healthy

worker:
image: kubeshop/demo-pokemon-api:latest
restart: unless-stopped
pull_policy: always
environment:
REDIS_URL: cache
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/postgres?schema=public
RABBITMQ_HOST: queue
POKE_API_BASE_URL: https://pokeapi.co/api/v2
COLLECTOR_ENDPOINT: http://otel-collector:4317
NPM_RUN_COMMAND: worker
depends_on:
postgres:
condition: service_healthy
cache:
condition: service_healthy
queue:
condition: service_healthy

rpc:
image: kubeshop/demo-pokemon-api:latest
restart: unless-stopped
pull_policy: always
environment:
REDIS_URL: cache
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/postgres?schema=public
RABBITMQ_HOST: queue
POKE_API_BASE_URL: https://pokeapi.co/api/v2
COLLECTOR_ENDPOINT: http://otel-collector:4317
NPM_RUN_COMMAND: rpc
healthcheck:
test: ["CMD", "lsof", "-i", "8082"]
interval: 1s
timeout: 3s
retries: 60
depends_on:
postgres:
condition: service_healthy
cache:
condition: service_healthy
queue:
condition: service_healthy

jaeger:
image: jaegertracing/all-in-one:latest
ports:
- 16686:16686
healthcheck:
test: ["CMD", "wget", "--spider", "localhost:16686"]
interval: 1s
timeout: 3s
retries: 60
65 changes: 65 additions & 0 deletions examples/quick-start-artillery-playwright/home.spec.ts
@@ -0,0 +1,65 @@
import { Page } from 'playwright';
import { expect } from '@playwright/test';
import Tracetest from '@tracetest/playwright';
import { config } from 'dotenv';

config();

const { TRACETEST_API_TOKEN = '' } = process.env;

const definition = `
type: Test
spec:
id: artillery-playwight-import-pokemon
name: "Artillery Playwright - Import Pokemon"
trigger:
type: playwright
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 postgres.pokemon" db.system="postgres" db.name="postgres" db.user="postgres" db.operation="create" db.sql.table="pokemon"]
value: attr:db.result | json_path '$.id'
`;

export async function importPokemon(page: Page) {
const tracetest = await Tracetest({ apiToken: TRACETEST_API_TOKEN });
const title = 'Artillery Playwright - Import Pokemon';
const pokemonId = Math.floor(Math.random() * 101).toString();
await page.goto('/');

await tracetest?.setOptions({
[title]: {
definition,
runInfo: {
variables: [
{
key: 'POKEMON_ID',
value: pokemonId,
},
],
},
},
});

await tracetest?.capture(title, page);

expect(await page.getByText('Pokeshop')).toBeTruthy();

await page.click('text=Import');

await page.getByLabel('ID').fill(pokemonId);
await page.getByRole('button', { name: 'OK', exact: true }).click();

await tracetest?.summary();
}
29 changes: 29 additions & 0 deletions examples/quick-start-artillery-playwright/import-pokemon.yaml
@@ -0,0 +1,29 @@
type: Test
spec:
id: artillery-engine-import-pokemon
name: "Artillery Engine: Import Pokemon"
trigger:
type: http
httpRequest:
method: POST
url: ${var:ENDPOINT}/pokemon/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 postgres.pokemon" db.system="postgres" db.name="postgres" db.user="postgres" db.operation="create" db.sql.table="pokemon"]
value: attr:db.result | json_path '$.id'

0 comments on commit c861835

Please sign in to comment.