diff --git a/.github/workflows/scheduled-jobs.yml b/.github/workflows/scheduled-jobs.yml index c2103c97c4..cfd4bbb8be 100644 --- a/.github/workflows/scheduled-jobs.yml +++ b/.github/workflows/scheduled-jobs.yml @@ -62,6 +62,60 @@ jobs: SLACK_WEBHOOK_URL: ${{ secrets.SYNTETIC_MONITORING_SLACK_WEBHOOK_URL }} SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + pokeshop-serverless-trace-based-tests: + name: Run trace based tests for Pokeshop Serverless + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Configure Tracetest CLI + uses: kubeshop/tracetest-github-action@v1 + with: + token: ${{secrets.TRACETEST_SERVERLESS_POKESHOP_TOKEN}} + + - name: Run synthetic monitoring tests + run: | + tracetest run testsuite --file ./testing/synthetic-monitoring/pokeshop-serverless/_testsuite.yaml --vars ./testing/synthetic-monitoring/pokeshop-serverless/_variableset.yaml + + - name: Send message on Slack in case of failure + if: ${{ failure() }} + uses: slackapi/slack-github-action@v1.24.0 + with: + # check the block kit builder docs to understand how it works + # and how to modify it: https://api.slack.com/block-kit + payload: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": ":warning: Synthetic Monitoring Alert - Serverless Pokeshop Demo :warning:", + "emoji": true + } + }, + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "*Status:*\nFailed" + }, + { + "type": "mrkdwn", + "text": "*Pipeline:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View workflow>" + } + ] + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SYNTETIC_MONITORING_SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + otel-demo-trace-based-tests: name: Run trace based tests for Open Telemetry demo runs-on: ubuntu-latest diff --git a/testing/synthetic-monitoring/pokeshop-serverless/01-add-pokemon-with-api.yaml b/testing/synthetic-monitoring/pokeshop-serverless/01-add-pokemon-with-api.yaml new file mode 100644 index 0000000000..dce2460025 --- /dev/null +++ b/testing/synthetic-monitoring/pokeshop-serverless/01-add-pokemon-with-api.yaml @@ -0,0 +1,23 @@ +type: Test +spec: + id: pokeshop-serverless-demo-add-pokemon + name: Serverless - Pokeshop - Add + description: Add a Pokemon + trigger: + type: http + httpRequest: + method: POST + url: ${var:POKESHOP_API_URL}/pokemon + body: "{\n \"name\": \"meowth\",\n \"type\":\"normal\",\n \"imageUrl\":\"https://assets.pokemon.com/assets/cms2/img/pokedex/full/052.png\",\n \"isFeatured\": true\n}\n" + headers: + - key: Content-Type + value: application/json + specs: + - selector: span[tracetest.span.type="http" name="POST /pokemon"] + name: The POST /pokemon was called correctly + assertions: + - attr:tracetest.selected_spans.count = 1 + - selector: span[tracetest.span.type="database" name="create pokeshop.pokemon" db.operation="create" db.sql.table="pokemon"] + name: A Pokemon was inserted on database + assertions: + - attr:db.result | json_path '$.imageUrl' = "https://assets.pokemon.com/assets/cms2/img/pokedex/full/052.png" diff --git a/testing/synthetic-monitoring/pokeshop-serverless/02-import-pokemon-with-queue.yaml b/testing/synthetic-monitoring/pokeshop-serverless/02-import-pokemon-with-queue.yaml new file mode 100644 index 0000000000..d32fdfa806 --- /dev/null +++ b/testing/synthetic-monitoring/pokeshop-serverless/02-import-pokemon-with-queue.yaml @@ -0,0 +1,31 @@ +type: Test +spec: + id: pokeshop-serverless-demo-import-pokemon-queue + name: Serverless - Import a Pokemon using API and Worker + description: Import a Pokemon + trigger: + type: http + httpRequest: + method: POST + url: ${var:POKESHOP_API_URL}/pokemon/import + body: "{\n \"id\": 6\n}\n" + headers: + - key: Content-Type + value: application/json + specs: + - selector: span[tracetest.span.type="http" name="POST /pokemon/import"] + name: POST /pokemon/import was called successfuly + assertions: + - attr:http.request.body contains "6" + - selector: span[tracetest.span.type="messaging" name="queue.synchronizePokemon publish" messaging.system="sqs" messaging.destination="queue.synchronizePokemon" messaging.operation="publish"] + name: A message was enqueued to the worker + assertions: + - attr:messaging.payload | json_path '$.id' = "6" + - selector: span[tracetest.span.type="messaging" name="queue.synchronizePokemon process" messaging.system="sqs" messaging.destination="queue.synchronizePokemon" messaging.operation="process"] + name: A message was read by the worker + assertions: + - attr:messaging.payload | json_path '$.attributes.MessageGroupId' = "queue.synchronizePokemon" + - selector: span[tracetest.span.type="general" name="import pokemon"] + name: A "import pokemon" action was triggered + assertions: + - attr:tracetest.selected_spans.count >= 1 diff --git a/testing/synthetic-monitoring/pokeshop-serverless/04-list-pokemons.yaml b/testing/synthetic-monitoring/pokeshop-serverless/04-list-pokemons.yaml new file mode 100644 index 0000000000..bd0eb2d74b --- /dev/null +++ b/testing/synthetic-monitoring/pokeshop-serverless/04-list-pokemons.yaml @@ -0,0 +1,25 @@ +type: Test +spec: + id: pokeshop-serverless-demo-list-pokemon + name: Serverless - List Pokemons + trigger: + type: http + httpRequest: + method: GET + url: ${var:POKESHOP_API_URL}/pokemon?take=100&skip=0 + headers: + - key: Content-Type + value: application/json + specs: + - selector: span[tracetest.span.type="http" name="GET /pokemon"] + name: GET /pokemon endpoint was called and returned valid data + assertions: + - attr:tracetest.selected_spans.count = 1 + - selector: span[tracetest.span.type="database" name="count pokeshop.pokemon" db.system="postgres" db.name="pokeshop" db.user="ashketchum" db.operation="count" db.sql.table="pokemon"] + name: A count operation was triggered on database + assertions: + - attr:db.operation = "count" + - selector: span[tracetest.span.type="database" name="findMany pokeshop.pokemon" db.system="postgres" db.name="pokeshop" db.user="ashketchum" db.operation="findMany" db.sql.table="pokemon"] + name: A select operation was triggered on database + assertions: + - attr:db.operation = "findMany" diff --git a/testing/synthetic-monitoring/pokeshop-serverless/_testsuite.yaml b/testing/synthetic-monitoring/pokeshop-serverless/_testsuite.yaml new file mode 100644 index 0000000000..c5272fe99a --- /dev/null +++ b/testing/synthetic-monitoring/pokeshop-serverless/_testsuite.yaml @@ -0,0 +1,9 @@ +type: Transaction +spec: + id: pokeshop-serverless-demo-test-suite + name: "Serverless - Pokeshop Synthetic tests" + description: Simulate a user doing a series of imports on Pokeshop and listing its results + steps: + - ./01-add-pokemon-with-api.yaml + - ./02-import-pokemon-with-queue.yaml + - ./04-list-pokemons.yaml diff --git a/testing/synthetic-monitoring/pokeshop-serverless/_variableset.yaml b/testing/synthetic-monitoring/pokeshop-serverless/_variableset.yaml new file mode 100644 index 0000000000..45b8b8ab5a --- /dev/null +++ b/testing/synthetic-monitoring/pokeshop-serverless/_variableset.yaml @@ -0,0 +1,7 @@ +type: VariableSet +spec: + id: tracetesting-vars-serverless + name: tracetesting-vars-serverless + values: + - key: POKESHOP_API_URL + value: https://75yj353nn7.execute-api.us-east-1.amazonaws.com