# Several scenarios running concurrently with independent executors, start
# times and tags, plus groups and a custom metric.
name: mixed-workload
description: browsers + API clients + a batch job, all at once

defaults:
  http:
    base_url: https://shop.example.com
  tags:
    team: platform

metrics:
  carts_created: { kind: counter, description: "Carts created during the test" }

scenarios:
  browsers:
    executor: ramping-vus
    start_vus: 0
    stages: [ { duration: 1m, target: 30 }, { duration: 4m, target: 30 } ]
    think_time: { type: gaussian, mean: 2s, std_dev: 500ms }
    flow:
      - group:
          name: storefront
          steps:
            - request: { name: home, url: / }
            - request: { name: search, url: "/search?q=widget" }
      - group:
          name: cart
          steps:
            - request:
                name: add to cart
                method: POST
                url: /cart
                body: { json: { sku: "W-1" } }
                checks: [ { type: status, equals: 201 } ]
            - js: "session.counterAdd('carts_created', 1)"

  api_clients:
    executor: constant-arrival-rate
    rate: 50
    duration: 5m
    pre_allocated_vus: 20
    max_vus: 60
    tags: { kind: api }
    flow:
      - request: { name: api inventory, url: /api/v1/inventory }

  nightly_export:
    executor: per-vu-iterations
    vus: 1
    iterations: 1
    start_time: 2m          # kicks off two minutes into the test
    flow:
      - request:
          name: export
          method: POST
          url: /api/v1/export
          timeout: 120s

thresholds:
  "http_req_duration{scenario:api_clients}": [ "p(99)<250" ]
  "http_req_duration{scenario:browsers}": [ "p(95)<800" ]
  carts_created: [ "count>50" ]
