diff --git a/docs/docs/cli/creating-tests-graphql.mdx b/docs/docs/cli/creating-tests-graphql.mdx new file mode 100644 index 0000000000..e901d24742 --- /dev/null +++ b/docs/docs/cli/creating-tests-graphql.mdx @@ -0,0 +1,33 @@ +--- +id: creating-tests-graphql +title: Defining GraphQL Tests as Text Files +description: Tracetest enables developers to define tests as text files and run them using a CLI. Integrate the execution of tests in your existing CI pipeline. +keywords: + - tracetest + - trace-based testing + - observability + - distributed tracing + - testing + - graphql +image: https://res.cloudinary.com/djwdcmwdz/image/upload/v1698686403/docs/Blog_Thumbnail_14_rsvkmo.jpg +--- + +When defining a GraphQL trigger, you are required to define a `graphql` object containing the request Tracetest will send to your system. You also define: `body` with `query`, `variables` and `operationName`, `url`, `headers`, and `SSLVerification`, and `schema`. + +```yaml +trigger: + type: graphql + graphql: + url: ${env:GRAPHQL_URL} + headers: + - key: Content-Type + value: application/json + body: + # path to the query file or the query itself + query: ./query.graphql + variables: {} + operationName: "" + sslVerification: false + # path to the schema file or the schema itself + schema: ./schema.graphql +``` diff --git a/docs/docs/examples-tutorials/recipes.mdx b/docs/docs/examples-tutorials/recipes.mdx index 1acb75ad18..e61a389cf1 100644 --- a/docs/docs/examples-tutorials/recipes.mdx +++ b/docs/docs/examples-tutorials/recipes.mdx @@ -23,6 +23,7 @@ Recipes are short, self-contained, guides for getting started with building popu These guides show how to get the best of your instrumentation using the native Tracetest Triggers. - [True End-To-End Trace-Based Tests with the Tracetest Playwright Engine](/examples-tutorials/recipes/running-tests-with-tracetest-playwright-engine) +- [Trace-Based Tests with the Tracetest GrapqhQL Trigger](/examples-tutorials/recipes/running-tests-with-tracetest-graphql-pokeshop) ## Synthetic Monitoring diff --git a/docs/docs/examples-tutorials/recipes/running-tests-with-tracetest-graphql-pokeshop.mdx b/docs/docs/examples-tutorials/recipes/running-tests-with-tracetest-graphql-pokeshop.mdx new file mode 100644 index 0000000000..a06d1a0c6c --- /dev/null +++ b/docs/docs/examples-tutorials/recipes/running-tests-with-tracetest-graphql-pokeshop.mdx @@ -0,0 +1,319 @@ +--- +id: running-tests-with-tracetest-graphql-pokeshop +title: Trace-Based Tests with the Tracetest GrapqhQL Trigger +description: Quickstart on how to create Trace-Based Tests with the Tracetest GraphQL Trigger +hide_table_of_contents: false +keywords: + - tracetest + - trace-based testing + - observability + - distributed tracing + - end-to-end testing + - tracetest + - graphql + - trace-based-testing + - trigger +image: https://res.cloudinary.com/djwdcmwdz/image/upload/v1698686403/docs/Blog_Thumbnail_14_rsvkmo.jpg +--- + +:::info Version Compatibility +The features described here are compatible with the [Tracetest CLI v1.5.2](https://github.com/kubeshop/tracetest/releases/tag/v1.5.2) and above. +::: + +:::note +[Check out the source code on GitHub here.](https://github.com/kubeshop/tracetest/tree/main/examples/tracetest-jaeger-graphql-pokeshop) +::: + +[Tracetest](https://tracetest.io/) is a testing tool based on [OpenTelemetry](https://opentelemetry.io/) that permits you to test your distributed application. It allows you to use the trace data generated by your OpenTelemetry tools to check and assert if your application has the desired behavior defined by your test definitions. +[GraphQL](https://graphql.org/) is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools. + +## Why is this important? + +The Tracetest GraphQL trigger enables you to unleash the power of the trace-based testing to easily capture a full distributed trace from your OpenTelemetry instrumented GraphQL back-end system. + +By creating a Tracetest GraphQL test, you will be able to create trace-based assertions to be applied across the entire flow like any other Tracetest test. Not only that but it allows you to mix and match it with your existing Monitors, Test Suites and CI/CD validations. + +Other impactful benefits of using traces as test specs are: + +- Faster MTTR for failing performance tests. +- Assert against the Mutiple Queries and Mutations at once from a single test execution. +- Validate functionality of other parts of your system that may be broken, even when the initial request is passing. + +## Requirements + +**Tracetest Account**: + +- Sign up to [`app.tracetest.io`](https://app.tracetest.io) or follow the [get started](/getting-started/installation) docs. +- 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. + +## Run This Example + +The example below is provided as part of the Tracetest GitHub repo. You can download and run the example by following these steps: + +```bash +git clone https://github.com/kubeshop/tracetest +cd tracetest/examples/tracetest-jaeger-graphql-pokeshop +``` + +Follow these instructions to run the quick start: + +1. Copy the `.env.template` file to `.env`. +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. + +## Project Structure + +The project structure for running Tracetest GraphQL tests is as follows: + +```bash +.env.template +.gitignore +.Dockerfile +collector.config.yaml +docker-compose.yaml +/resources + apply.sh + datastore.yaml + test.yaml + run.sh + scheme.graphql + query.graphql +``` + +The [Pokeshop Demo App](/live-examples/pokeshop/overview) is a complete example of a distributed application using different back-end and front-end services. We will be launching it and running tests against it as part of this example. +The `docker-compose.yaml` file in the root directory of the quick start runs the Pokeshop Demo app, the OpenTelemetry Collector, Jaeger, and the [Tracetest Agent](/concepts/agent) setup. + +The Tracetest resource definitions and scripts are defined under the `/resources` directory. The resources include tests and the tracing backend definition, while the scripts include the `apply.sh` and `run.sh` scripts to apply the resources and run the tests. + +## Provisioned Resources + +The example provisions the following resources: + +### Import Pokemon Test + +```yaml title="resources/test.yaml" +type: Test +spec: + id: re9XOxqSR + name: Pokeshop - Import + trigger: + type: graphql + graphql: + url: http://demo-api:8081/graphql + headers: + - key: Content-Type + value: application/json + auth: + apiKey: {} + basic: {} + bearer: {} + body: + query: ./query.graphql + variables: {} + operationName: "" + sslVerification: false + schema: ./schema.graphql + specs: + - name: Import Pokemon Span Exists + selector: span[tracetest.span.type="general" name="import pokemon"] + assertions: + - attr:tracetest.selected_spans.count = 1 + - name: Uses Correct PokemonId + selector: span[tracetest.span.type="http" name="GET" http.method="GET"] + assertions: + - attr:http.url = "https://pokeapi.co/api/v2/pokemon/6" + - name: Matching db result with the Pokemon Name + selector: span[tracetest.span.type="database" name="create postgres.pokemon"]:first + assertions: + - attr:db.result contains "charizard" +``` + +### GraphQL + +```graphql title="resources/query.graphql" +mutation import { + importPokemon(id: 6) { + id + } +} +``` + +### GraphQL Schema + +```graphql title="resources/schema.graphql" +schema { + query: Query + mutation: Mutation +} + +type Pokemon { + id: Int + name: String! + type: String! + isFeatured: Boolean! + imageUrl: String +} + +"The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1." +scalar Int + +"The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text." +scalar String + +"The `Boolean` scalar type represents `true` or `false`." +scalar Boolean + +type PokemonList { + items: [Pokemon] + totalCount: Int +} + +type ImportPokemon { + id: Int! +} + +type Query { + getPokemonList(where: String, skip: Int, take: Int): PokemonList +} + +type Mutation { + createPokemon(name: String!, type: String!, isFeatured: Boolean!, imageUrl: String): Pokemon! + importPokemon(id: Int!): ImportPokemon! +} +// ...See more in the schema.graphql file +``` + +### Jaeger Tracing Backend + +```yaml title="resources/datastore.yaml" +type: DataStore +spec: + id: current + name: jaeger + type: jaeger + default: true + jaeger: + endpoint: jaeger:16685 + headers: + "": "" + tls: + insecure: true +``` + +### The Apply Script + +The apply script configures and provisions the resources in the Tracetest environment: + +```bash title="resources/apply.sh" +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_API_KEY +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 +``` + +### The Run Script + +The run script runs the test suite against the provisioned resources: + +```bash title="resources/run.sh" +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_API_KEY +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 +``` + +## Setting the Environment Variables + +Copy the `.env.template` file to `.env` and add the Tracetest API token and agent tokens to the `TRACETEST_API_TOKEN` and `TRACETEST_ENVIRONMENT_ID` variables. + +## Running the Full Example + +Everything is automated for you to only run the following command: + +```bash +docker compose run tracetest-run +``` + +This command will run the `apply.sh` script to provision the resources and the `run.sh` script to run the test suite. + +## Finding the Results + +The output from the Tracetest Engine script should be visible in the console log after running the test command. + +```bash title=Output +WARN[0000] /Users/oscar/Documents/kubeshop/t/examples/tracetest-jaeger-graphql-pokeshop/docker-compose.yaml: `version` is obsolete +[+] Running 2/2 + ✔ demo-api Pulled 0.9s + ✔ demo-worker Pulled 0.9s +[+] Creating 10/9 + ✔ Network tracetest-jaeger-graphql-pokeshop_default Created 0.0s + ✔ Container tracetest-jaeger-graphql-pokeshop-postgres-1 Created 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-cache-1 Created 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-tracetest-agent-1 Created 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-queue-1 Created 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-jaeger-1 Created 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-demo-worker-1 Created 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-otel-collector-1 Created 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-demo-api-1 Created 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-tracetest-apply-1 Created 0.0s +[+] Running 9/9 + ✔ Container tracetest-jaeger-graphql-pokeshop-cache-1 Healthy 10.5s + ✔ Container tracetest-jaeger-graphql-pokeshop-tracetest-agent-1 Started 0.3s + ✔ Container tracetest-jaeger-graphql-pokeshop-jaeger-1 Healthy 1.9s + ✔ Container tracetest-jaeger-graphql-pokeshop-postgres-1 Healthy 10.5s + ✔ Container tracetest-jaeger-graphql-pokeshop-queue-1 Healthy 10.5s + ✔ Container tracetest-jaeger-graphql-pokeshop-otel-collector-1 Started 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-demo-worker-1 Started 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-demo-api-1 Started 0.1s + ✔ Container tracetest-jaeger-graphql-pokeshop-tracetest-apply-1 Started 0.1s +[+] Running 2/2 + ✔ demo-api Pulled 0.8s + ✔ demo-worker Pulled 0.8s +Configuring Tracetest + SUCCESS Successfully configured Tracetest CLI +Running Trace-Based Tests... +✔ RunGroup: #US5klbqSR (https://app-stage.tracetest.io/organizations/ttorg_c71a6b53c3709e95/environments/ttenv_bcf29b43f06a12dc/run/US5klbqSR) + Summary: 1 passed, 0 failed, 0 pending + ✔ Pokeshop - Import (https://app-stage.tracetest.io/organizations/ttorg_c71a6b53c3709e95/environments/ttenv_bcf29b43f06a12dc/test/re9XOxqSR/run/11/test) - trace id: 6facf84ee23757eda97930c16fd1d8f9 + ✔ Import Pokemon Span Exists + ✔ Uses Correct PokemonId + ✔ Matching db result with the Pokemon Name +``` + +## What's Next? + +After running the test, you can click the run link, update the assertions, and run the scripts once more. This flow enables complete a trace-based TDD flow. + +![assertions](../img/playwright-engine.gif) + +## Learn More + +Please visit our [examples in GitHub](https://github.com/kubeshop/tracetest/tree/main/examples) and join our [Slack Community](https://dub.sh/tracetest-community) for more info! diff --git a/docs/docs/img/graphql-choose-trigger.png b/docs/docs/img/graphql-choose-trigger.png new file mode 100644 index 0000000000..78e9f7fbfc Binary files /dev/null and b/docs/docs/img/graphql-choose-trigger.png differ diff --git a/docs/docs/img/graphql-details-2.png b/docs/docs/img/graphql-details-2.png new file mode 100644 index 0000000000..dc700b4e0e Binary files /dev/null and b/docs/docs/img/graphql-details-2.png differ diff --git a/docs/docs/img/graphql-details.png b/docs/docs/img/graphql-details.png new file mode 100644 index 0000000000..b42da8cf7b Binary files /dev/null and b/docs/docs/img/graphql-details.png differ diff --git a/docs/docs/img/graphql-select-demo.png b/docs/docs/img/graphql-select-demo.png new file mode 100644 index 0000000000..14570a794b Binary files /dev/null and b/docs/docs/img/graphql-select-demo.png differ diff --git a/docs/docs/img/graphql-success.png b/docs/docs/img/graphql-success.png new file mode 100644 index 0000000000..fb379eeb71 Binary files /dev/null and b/docs/docs/img/graphql-success.png differ diff --git a/docs/docs/web-ui/creating-tests-graphql.mdx b/docs/docs/web-ui/creating-tests-graphql.mdx new file mode 100644 index 0000000000..fc47f8cac8 --- /dev/null +++ b/docs/docs/web-ui/creating-tests-graphql.mdx @@ -0,0 +1,47 @@ +--- +id: creating-tests-graphql +title: Creating Tests - GraphQL +description: Tracetest enables creating tests visually in the Tracetest Web UI. +hide_table_of_contents: false +keywords: + - tracetest + - trace-based testing + - observability + - distributed tracing + - testing + - graphql +image: https://res.cloudinary.com/djwdcmwdz/image/upload/v1698686403/docs/Blog_Thumbnail_14_rsvkmo.jpg +--- + +[GraphQL](https://graphql.org/) is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools. + +👉 **Join our [shared Pokeshop API Demo environment](https://app.tracetest.io/organizations/ttorg_2179a9cd8ba8dfa5/invites/invite_760904a64b4b9dc9/accept) and try creating a Test yourself!** + +Click the GraphQL option to continue: + +![Choose Trigger](../img/choose-trigger-0.16.png) + +In this example, a GaphQL Request has been chosen. + +![Choose Example](../img/graphql-choose-trigger.png) + +Input the **Name** and **Trigger** details or select one of the example provided in the drop down: + +![Choose Example Pokemon](../img/graphql-select-demo.png) + +The **Pokeshop - Import from Stream** example has been chosen. + +Add any additional information and click **Run**: + +![Create Test - Query](../img/graphql-details.png) + +![Create Test - Schema](../img/graphql-details-2.png) + +When the test is finished, you will get the following results: + +![Finished Trace](../img/graphql-success.png) + +Please visit the [Test Results](../web-ui/test-results.mdx) document for an explanation of viewing the results of a test. + +👉 **Join our [shared Pokeshop API Demo environment](https://app.tracetest.io/organizations/ttorg_2179a9cd8ba8dfa5/invites/invite_760904a64b4b9dc9/accept) and try creating a Test yourself!** + diff --git a/docs/sidebars.js b/docs/sidebars.js index d6a5cdd145..50a392e955 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -43,6 +43,11 @@ const sidebars = { id: "examples-tutorials/recipes/running-tests-with-tracetest-playwright-engine", label: "True End-To-End Trace-Based Tests with the Tracetest Playwright Engine", }, + { + type: "doc", + id: "examples-tutorials/recipes/running-tests-with-tracetest-graphql-pokeshop", + label: "Trace-Based Tests with the Tracetest GrapqhQL Trigger", + }, ], }, { @@ -981,6 +986,11 @@ const sidebars = { id: "web-ui/creating-tests-kafka", label: "Creating Tests - Kafka", }, + { + type: "doc", + id: "web-ui/creating-tests-graphql", + label: "Creating Tests - GraphQL", + }, { type: "doc", id: "web-ui/creating-tests-traceid", @@ -1124,6 +1134,11 @@ const sidebars = { id: "cli/creating-tests-kafka", label: "Creating Tests - Kafka", }, + { + type: "doc", + id: "cli/creating-tests-graphql", + label: "Creating Tests - GraphQL", + }, { type: "doc", id: "cli/creating-tests-traceid", diff --git a/examples/tracetest-jaeger-graphql-pokeshop/.env.template b/examples/tracetest-jaeger-graphql-pokeshop/.env.template new file mode 100644 index 0000000000..c0437a9d95 --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/.env.template @@ -0,0 +1,4 @@ +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" diff --git a/examples/tracetest-jaeger-graphql-pokeshop/.gitignore b/examples/tracetest-jaeger-graphql-pokeshop/.gitignore new file mode 100644 index 0000000000..d8f337266f --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/.gitignore @@ -0,0 +1,3 @@ +node_modules +.DS_Store +.env diff --git a/examples/tracetest-jaeger-graphql-pokeshop/Dockerfile.tracetest b/examples/tracetest-jaeger-graphql-pokeshop/Dockerfile.tracetest new file mode 100644 index 0000000000..2d143ccf9c --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/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 -- v1.5.2 + +WORKDIR /resources + +ENTRYPOINT ["echo", "Tracetest CLI installed"] diff --git a/examples/tracetest-jaeger-graphql-pokeshop/README.md b/examples/tracetest-jaeger-graphql-pokeshop/README.md new file mode 100644 index 0000000000..8897a04d14 --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/README.md @@ -0,0 +1,5 @@ +# Tracetest + Amazon X-Ray (using Tracetest awsxray integration) + Pokeshop + +> [Read the detailed recipe for setting up Tracetest + Amazon X-Ray (using Tracetest awsxray integration) + Pokeshop in our documentation.](https://docs.tracetest.io/examples-tutorials/recipes/running-tests-with-tracetest-graphql-pokeshop) + +This repository objective is to show how you can configure your Tracetest instance to connect to AWS X-Ray and use it as its tracing backend. diff --git a/examples/tracetest-jaeger-graphql-pokeshop/collector.config.yaml b/examples/tracetest-jaeger-graphql-pokeshop/collector.config.yaml new file mode 100644 index 0000000000..6cadc75881 --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/collector.config.yaml @@ -0,0 +1,24 @@ +receivers: + otlp: + protocols: + grpc: + http: + +processors: + batch: + timeout: 100ms + +exporters: + logging: + loglevel: debug + otlp: + endpoint: jaeger:4317 + tls: + insecure: true + +service: + pipelines: + traces/1: + receivers: [otlp] + processors: [batch] + exporters: [logging, otlp] diff --git a/examples/tracetest-jaeger-graphql-pokeshop/docker-compose.yaml b/examples/tracetest-jaeger-graphql-pokeshop/docker-compose.yaml new file mode 100644 index 0000000000..944300f823 --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/docker-compose.yaml @@ -0,0 +1,148 @@ +version: "3" +services: + # 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: + demo-api: + 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 + + otel-collector: + image: otel/opentelemetry-collector-contrib:0.100.0 + command: + - "--config" + - "/otel-local-config.yaml" + volumes: + - ./collector.config.yaml:/otel-local-config.yaml + depends_on: + jaeger: + condition: service_healthy + + jaeger: + image: jaegertracing/all-in-one:latest + ports: + - 14250:14250 + - 16685:16685 + - 16686:16686 + healthcheck: + test: ["CMD", "wget", "--spider", "localhost:16686"] + interval: 1s + timeout: 3s + retries: 60 + + 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 + + cache: + image: redis:6 + restart: unless-stopped + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 1s + timeout: 3s + retries: 60 + + queue: + image: rabbitmq:3.8-management + restart: unless-stopped + healthcheck: + test: rabbitmq-diagnostics -q check_running + interval: 1s + timeout: 5s + retries: 60 + + demo-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 + NPM_RUN_COMMAND: api + ports: + - "8081:8081" + healthcheck: + test: ["CMD", "wget", "--spider", "localhost:8081"] + interval: 1s + timeout: 3s + retries: 60 + depends_on: + demo-worker: + condition: service_started + otel-collector: + condition: service_started + postgres: + condition: service_healthy + cache: + condition: service_healthy + queue: + condition: service_healthy + + demo-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 diff --git a/examples/tracetest-jaeger-graphql-pokeshop/resources/apply.sh b/examples/tracetest-jaeger-graphql-pokeshop/resources/apply.sh new file mode 100644 index 0000000000..13b878ba47 --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/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/tracetest-jaeger-graphql-pokeshop/resources/datastore.yaml b/examples/tracetest-jaeger-graphql-pokeshop/resources/datastore.yaml new file mode 100644 index 0000000000..72f8294fcd --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/resources/datastore.yaml @@ -0,0 +1,12 @@ +type: DataStore +spec: + id: current + name: jaeger + type: jaeger + default: true + jaeger: + endpoint: jaeger:16685 + headers: + "": "" + tls: + insecure: true diff --git a/examples/tracetest-jaeger-graphql-pokeshop/resources/query.graphql b/examples/tracetest-jaeger-graphql-pokeshop/resources/query.graphql new file mode 100644 index 0000000000..62d3439f2c --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/resources/query.graphql @@ -0,0 +1,5 @@ +mutation import { + importPokemon(id: 6) { + id + } +} diff --git a/examples/tracetest-jaeger-graphql-pokeshop/resources/run.sh b/examples/tracetest-jaeger-graphql-pokeshop/resources/run.sh new file mode 100644 index 0000000000..05d0f41724 --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/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/tracetest-jaeger-graphql-pokeshop/resources/schema.graphql b/examples/tracetest-jaeger-graphql-pokeshop/resources/schema.graphql new file mode 100644 index 0000000000..7e7eead596 --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/resources/schema.graphql @@ -0,0 +1,191 @@ +schema { + query: Query + mutation: Mutation +} + +type Pokemon { + id: Int + name: String! + type: String! + isFeatured: Boolean! + imageUrl: String +} + +"The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1." +scalar Int + +"The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text." +scalar String + +"The `Boolean` scalar type represents `true` or `false`." +scalar Boolean + +type PokemonList { + items: [Pokemon] + totalCount: Int +} + +type ImportPokemon { + id: Int! +} + +type Query { + getPokemonList(where: String, skip: Int, take: Int): PokemonList +} + +type Mutation { + createPokemon(name: String!, type: String!, isFeatured: Boolean!, imageUrl: String): Pokemon! + importPokemon(id: Int!): ImportPokemon! +} + +"A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations." +type __Schema { + description: String + "A list of all types supported by this server." + types: [__Type!]! + "The type that query operations will be rooted at." + queryType: __Type! + "If this server supports mutation, the type that mutation operations will be rooted at." + mutationType: __Type + "If this server support subscription, the type that subscription operations will be rooted at." + subscriptionType: __Type + "A list of all directives supported by this server." + directives: [__Directive!]! +} + +""" +The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum. + +Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByUrl`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types. +""" +type __Type { + kind: __TypeKind! + name: String + description: String + specifiedByUrl: String + fields(includeDeprecated: Boolean = false): [__Field!] + interfaces: [__Type!] + possibleTypes: [__Type!] + enumValues(includeDeprecated: Boolean = false): [__EnumValue!] + inputFields(includeDeprecated: Boolean = false): [__InputValue!] + ofType: __Type +} + +"An enum describing what kind of type a given `__Type` is." +enum __TypeKind { + "Indicates this type is a scalar." + SCALAR + "Indicates this type is an object. `fields` and `interfaces` are valid fields." + OBJECT + "Indicates this type is an interface. `fields`, `interfaces`, and `possibleTypes` are valid fields." + INTERFACE + "Indicates this type is a union. `possibleTypes` is a valid field." + UNION + "Indicates this type is an enum. `enumValues` is a valid field." + ENUM + "Indicates this type is an input object. `inputFields` is a valid field." + INPUT_OBJECT + "Indicates this type is a list. `ofType` is a valid field." + LIST + "Indicates this type is a non-null. `ofType` is a valid field." + NON_NULL +} + +"Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type." +type __Field { + name: String! + description: String + args(includeDeprecated: Boolean = false): [__InputValue!]! + type: __Type! + isDeprecated: Boolean! + deprecationReason: String +} + +"Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value." +type __InputValue { + name: String! + description: String + type: __Type! + "A GraphQL-formatted string representing the default value for this input value." + defaultValue: String + isDeprecated: Boolean! + deprecationReason: String +} + +"One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string." +type __EnumValue { + name: String! + description: String + isDeprecated: Boolean! + deprecationReason: String +} + +""" +A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document. + +In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor. +""" +type __Directive { + name: String! + description: String + isRepeatable: Boolean! + locations: [__DirectiveLocation!]! + args(includeDeprecated: Boolean = false): [__InputValue!]! +} + +"A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies." +enum __DirectiveLocation { + "Location adjacent to a query operation." + QUERY + "Location adjacent to a mutation operation." + MUTATION + "Location adjacent to a subscription operation." + SUBSCRIPTION + "Location adjacent to a field." + FIELD + "Location adjacent to a fragment definition." + FRAGMENT_DEFINITION + "Location adjacent to a fragment spread." + FRAGMENT_SPREAD + "Location adjacent to an inline fragment." + INLINE_FRAGMENT + "Location adjacent to a variable definition." + VARIABLE_DEFINITION + "Location adjacent to a schema definition." + SCHEMA + "Location adjacent to a scalar definition." + SCALAR + "Location adjacent to an object type definition." + OBJECT + "Location adjacent to a field definition." + FIELD_DEFINITION + "Location adjacent to an argument definition." + ARGUMENT_DEFINITION + "Location adjacent to an interface definition." + INTERFACE + "Location adjacent to a union definition." + UNION + "Location adjacent to an enum definition." + ENUM + "Location adjacent to an enum value definition." + ENUM_VALUE + "Location adjacent to an input object type definition." + INPUT_OBJECT + "Location adjacent to an input object field definition." + INPUT_FIELD_DEFINITION +} + +"Directs the executor to include this field or fragment only when the `if` argument is true." +directive @include("Included when true." if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + +"Directs the executor to skip this field or fragment when the `if` argument is true." +directive @skip("Skipped when true." if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + +"Marks an element of a GraphQL schema as no longer supported." +directive @deprecated( + "Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/)." + reason: String = "No longer supported" +) on FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM_VALUE | INPUT_FIELD_DEFINITION + +"Exposes a URL that specifies the behaviour of this scalar." +directive @specifiedBy("The URL that specifies the behaviour of this scalar." url: String!) on SCALAR diff --git a/examples/tracetest-jaeger-graphql-pokeshop/resources/test.yaml b/examples/tracetest-jaeger-graphql-pokeshop/resources/test.yaml new file mode 100644 index 0000000000..944768f9d7 --- /dev/null +++ b/examples/tracetest-jaeger-graphql-pokeshop/resources/test.yaml @@ -0,0 +1,34 @@ +type: Test +spec: + id: re9XOxqSR + name: Pokeshop - Import + trigger: + type: graphql + graphql: + url: http://demo-api:8081/graphql + headers: + - key: Content-Type + value: application/json + auth: + apiKey: {} + basic: {} + bearer: {} + body: + query: ./query.graphql + variables: {} + operationName: "" + sslVerification: false + schema: ./schema.graphql + specs: + - name: Import Pokemon Span Exists + selector: span[tracetest.span.type="general" name="import pokemon"] + assertions: + - attr:tracetest.selected_spans.count = 1 + - name: Uses Correct PokemonId + selector: span[tracetest.span.type="http" name="GET" http.method="GET"] + assertions: + - attr:http.url = "https://pokeapi.co/api/v2/pokemon/6" + - name: Matching db result with the Pokemon Name + selector: span[tracetest.span.type="database" name="create postgres.pokemon"]:first + assertions: + - attr:db.result contains "charizard"