# MySQL load test, driven by the `loadr-plugin-mysql` native protocol plugin.
#
# MySQL support is NOT built into loadr core — it is a runtime-loadable plugin
# that ships the heavy `sqlx` Rust driver on its own (with ONLY the `mysql`
# feature). The plugin declares the `mysql://` URL scheme, so once it is
# installed a request to such a URL routes straight to it; no explicit
# `protocol:` is needed.
#
# Each request runs one configured query as the "request"; loadr records query
# latency in `mysql_req_duration`, the number of rows returned (SELECT) or
# affected (INSERT/UPDATE/DELETE) in `mysql_rows`, and any database error fails
# the request (status 1 = ok, status 0 = DB/transport error). Positional
# parameters are bound safely by the driver with `?` placeholders.
#
# Build + install the plugin, then run:
#   cargo build -p loadr-plugin-mysql --release
#   mkdir -p dist && cp plugins/loadr-plugin-mysql/plugin.toml dist/ \
#     && cp target/release/libloadr_plugin_mysql.so dist/
#   loadr plugin install dist
#   loadr run examples/29-mysql.yaml
#
# Or point the plan's `plugins:` entry at the built artifact directly (below).
name: mysql
description: Parameterised SELECT against MySQL via loadr-plugin-mysql

plugins:
  # Resolve `mysql` by name from the plugins dir (after `loadr plugin install`).
  # To run straight from a build tree instead, set:
  #   path: target/release/libloadr_plugin_mysql.so
  - name: mysql

scenarios:
  # Steady query rate over the MySQL wire protocol (note `?` params).
  mysql_reads:
    executor: constant-arrival-rate
    rate: 100
    duration: 30s
    pre_allocated_vus: 10
    max_vus: 40
    flow:
      - request:
          name: my count products
          url: mysql://loadr:loadr@db.example.com:3306/loadr
          sql:
            query: SELECT COUNT(*) AS n FROM products WHERE stock > ?
            params: ["0"]
          checks:
            - { type: status, equals: 1 }                 # 1 = ok, 0 = DB error
            - { type: duration, name: query is fast, max: 250ms }
      - request:
          name: my top products
          url: mysql://loadr:loadr@db.example.com:3306/loadr
          sql:
            query: SELECT name, price FROM products ORDER BY price DESC LIMIT 3
          assert:
            - { type: status, equals: 1 }

thresholds:
  checks: [ "rate>0.99" ]
  mysql_req_duration: [ "p(95)<300ms" ]
  mysql_reqs: [ "count>0" ]
