# Apache Kafka load test, driven by the `loadr-plugin-kafka` native protocol
# plugin.
#
# Kafka support is NOT built into loadr core — it is a runtime-loadable plugin
# that ships its own Kafka client. That client is `rskafka`, a PURE-RUST client
# (no librdkafka / C toolchain), so the plugin cross-compiles to every release
# target. The plugin declares the `kafka://` URL scheme, so once it is installed
# a request to a `kafka://` URL routes straight to it; no explicit `protocol:`
# is needed. The broker is the URL authority and the topic is the URL path
# (`kafka://broker:9092/topic`).
#
# Each request runs one operation (produce/fetch) from its `plugin:` block.
# loadr records the operation latency in `kafka_req_duration`, the count of
# messages produced/fetched in `kafka_msgs`, and any client error fails the
# request (status 1 = ok, status 0 = client/transport error).
#
# Build + install the plugin, then run:
#   cargo build -p loadr-plugin-kafka --release
#   mkdir -p dist && cp plugins/loadr-plugin-kafka/plugin.toml dist/ \
#     && cp target/release/libloadr_plugin_kafka.so dist/
#   loadr plugin install dist
#   loadr run examples/31-kafka.yaml
#
# Or point the plan's `plugins:` entry at the built artifact directly (below).
name: kafka
description: produce + fetch against Apache Kafka via loadr-plugin-kafka

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

scenarios:
  # Producers stream messages into the demo topic.
  producers:
    executor: constant-vus
    vus: 5
    duration: 15s
    flow:
      - request:
          name: produce event
          url: kafka://broker.example.com:9092/loadr-demo
          plugin:
            operation: produce
            key: "vu-${vu}"
            value: "event from vu ${vu} iter ${iteration}"
          assert:
            - { type: status, equals: 1 }            # 1 = ok, 0 = client error

  # Consumers fetch from the head of the topic.
  consumers:
    executor: constant-arrival-rate
    rate: 40
    duration: 15s
    pre_allocated_vus: 5
    max_vus: 20
    flow:
      - request:
          name: fetch from head
          url: kafka://broker.example.com:9092/loadr-demo
          plugin:
            operation: fetch
            offset: 0
            max_bytes: 1000000
            max_wait_ms: 500
          checks:
            - { type: status, equals: 1 }
            - { type: duration, name: fetch is fast, max: 1s }

thresholds:
  checks: [ "rate>0.99" ]
  kafka_req_duration: [ "p(95)<1s" ]
  kafka_reqs: [ "count>0" ]
