# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

# @feature: elasticsearch; set up prometheus_elasticsearch_exporter and OpenTelemetry collector

version: '2.1'

services:
  rmq0: &rabbitmq
    image: rabbitmq:3.11.14-management
    networks:
      - sw
    ports:
      - "15673:15672"
      - "15693:15692"
    cap_add:
      - ALL
    hostname: rmq0
    environment:
      RABBITMQ_ERLANG_COOKIE: rabbitmq-prometheus
    volumes:
      - ./config/rabbitmq/rabbitmq-overview.conf:/etc/rabbitmq/rabbitmq.conf:ro
      - ./config/rabbitmq/rabbitmq-overview-definitions.json:/etc/rabbitmq/rabbitmq-definitions.json:ro
    ulimits:
      nofile:
        soft: 2000
        hard: 2000

  # The following services are used for mocking test data
  basic-get:
    image: &perf-test-image pivotalrabbitmq/perf-test:2.15.0-ubuntu
    networks:
      - "e2e"
    environment:
      URI: "amqp://guest:guest@rmq0:5672/%2f"
      QUEUE: basic-get
      ROUTING_KEY: basic-get
      VARIABLE_RATE: "1:1,0:30"
      POLLING: "true"
      POLLING_INTERVAL: 5000
      AUTOACK: "false"
      SERVERS_STARTUP_TIMEOUT: &startup_timeout 60
      METRICS_PROMETHEUS: "true"
  basic-get-auto:
    image: *perf-test-image
    networks:
      - "e2e"
    environment:
      URI: "amqp://guest:guest@rmq0:5672/%2f"
      QUEUE: basic-get
      ROUTING_KEY: basic-get
      PRODUCERS: 0
      POLLING: "true"
      POLLING_INTERVAL: 5000
      AUTOACK: "true"
      SERVERS_STARTUP_TIMEOUT: *startup_timeout
      METRICS_PROMETHEUS: "true"
  greedy-consumer:
    image: *perf-test-image
    networks:
      - "e2e"
    environment:
      URI: "amqp://guest:guest@rmq0:5672/%2f"
      QUEUE: greedy-consumer
      ROUTING_KEY: greedy-consumer
      VARIABLE_RATE: "100:20,0:20"
      CONSUMER_RATE: 50
      QOS: 2000
      AUTOACK: "false"
      SERVERS_STARTUP_TIMEOUT: *startup_timeout
      METRICS_PROMETHEUS: "true"
  publisher-confirms:
    image: *perf-test-image
    networks:
      - "e2e"
    environment:
      URI: "amqp://guest:guest@rmq0:5672/%2f"
      QUEUE: publisher-confirms
      ROUTING_KEY: publisher-confirms
      AUTOACK: "true"
      VARIABLE_RATE: "12:30,25:30,50:30,100:30"
      CONFIRM: 1
      CONFIRM_TIMEOUT: 1
      SERVERS_STARTUP_TIMEOUT: *startup_timeout
      METRICS_PROMETHEUS: "true"
  slow-consumer-persistent:
    image: *perf-test-image
    networks:
      - "e2e"
    environment:
      URI: "amqp://guest:guest@rmq0:5672/%2f"
      QUEUE: ha3-slow-consumer-persistent
      ROUTING_KEY: slow-consumer-persistent
      QUEUE_ARGS: x-max-length=10000
      FLAG: persistent
      AUTO_DELETE: "false"
      SIZE: 51200
      VARIABLE_RATE: "100:20,0:20"
      CONSUMER_RATE: 50
      QOS: 50
      AUTOACK: "false"
      SERVERS_STARTUP_TIMEOUT: *startup_timeout
      METRICS_PROMETHEUS: "true"
  nack:
    image: *perf-test-image
    networks:
      - "e2e"
    entrypoint: []
    command: /bin/bash -c "while true; do bin/runjava com.rabbitmq.perf.PerfTest; sleep 10; done"
    environment:
      TIME: 60
      URI: "amqp://guest:guest@rmq0:5672/%2f"
      VARIABLE_RATE: "1:10,0:20"
      QUEUE: nack
      QUEUE_ARGS: x-max-length=100
      ROUTING_KEY: nack
      AUTOACK: "false"
      NACK: "true"
      QOS: 5
      CONSUMER_LATENCY: 3000000
      SERVERS_STARTUP_TIMEOUT: *startup_timeout
      METRICS_PROMETHEUS: "true"
  unroutable-return:
    image: *perf-test-image
    networks:
      - "e2e"
    environment:
      URI: "amqp://guest:guest@rmq0:5672/%2f"
      VARIABLE_RATE: "2:30,4:30,10:30"
      VARIABLE_SIZE: "100:30,200:30"
      CONSUMERS: 0
      FLAG: mandatory
      SERVERS_STARTUP_TIMEOUT: *startup_timeout
      METRICS_PROMETHEUS: "true"
  unroutable-drop:
    image: *perf-test-image
    networks:
      - "e2e"
    environment:
      URI: "amqp://guest:guest@rmq0:5672/%2f"
      VARIABLE_RATE: "5:30,10:30,20:30"
      VARIABLE_SIZE: "100:30,200:30"
      CONSUMERS: 0
      SERVERS_STARTUP_TIMEOUT: *startup_timeout
      METRICS_PROMETHEUS: "true"

  otel-collector:
    image: ${OTEL_COLLECTOR_IMAGE}:${OTEL_COLLECTOR_IMAGE_TAG}
    networks:
      - sw
    command: [ "--config=/etc/otel-collector-config.yaml" ]
    volumes:
      - ./config/rabbitmq/otel-collector-config.yaml:/etc/otel-collector-config.yaml
    expose:
      - 55678
    depends_on:
      oap:
        condition: service_healthy

networks:
  sw:
