Skip to content

Commit

Permalink
Add stomp consumers
Browse files Browse the repository at this point in the history
Starts message consumers in WSGI HTTP server. This allows scaling the
consumers easily with `gunicorn --workers=X` and enables access to
`api/v1.0/metrics` endpoint containing message metrics.

Example to start the consumers:

    gunicorn-3 --workers=4 greenwave.resultsdb_listener:app
  • Loading branch information
hluk committed Mar 23, 2022
1 parent 12672c5 commit 1b5ad3a
Show file tree
Hide file tree
Showing 14 changed files with 586 additions and 118 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN dnf -y install \
python3-prometheus_client \
python3-PyYAML \
python3-requests \
python3-stomppy \
&& dnf -y clean all \
&& rm -rf /tmp/*

Expand Down
82 changes: 64 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: '2.1'
services:
dev:
build: .
image: greenwave_dev
user: ${DEV_USER_ID:-1000}
working_dir: /src
env_file: ["docker/dev.env"]
Expand All @@ -20,23 +21,6 @@ services:
- resultsdb
- waiverdb

resultsdb-consumer:
build: .
user: ${DEV_USER_ID:-1000}
working_dir: /
env_file: docker/dev.env
command: ["/usr/bin/fedmsg-hub-3"]
volumes:
- ./:/src:ro,z
- ./docker/home:/home/dev:rw,z
- ./docker/greenwave-settings.py:/etc/greenwave/settings.py:ro,z
- ./conf/policies/:/etc/greenwave/policies/:ro,z
- ./conf/subject_types/:/etc/greenwave/subject_types/:ro,z
- ./docker/fedmsg.d:/etc/fedmsg.d:ro,z
depends_on:
- memcached
- umb

resultsdb-db:
image: postgres:9.5.2
restart: always
Expand All @@ -52,6 +36,8 @@ services:
context: ../resultsdb
dockerfile: Dockerfile
working_dir: /code
environment:
- GREENWAVE_LISTENERS=${GREENWAVE_LISTENERS:-1}
command: ["bash", "-c", "/start.sh"]
volumes:
- ../resultsdb:/code:ro,z
Expand All @@ -76,6 +62,8 @@ services:
dockerfile: openshift/containers/waiverdb/Dockerfile
working_dir: /code
env_file: ["docker/waiverdb.env"]
environment:
- GREENWAVE_LISTENERS=${GREENWAVE_LISTENERS:-1}
command: ["bash", "-c", "/start.sh"]
volumes:
- ../waiverdb:/code:ro,z
Expand All @@ -92,8 +80,64 @@ services:
memcached:
image: "quay.io/factory2/memcached"

resultsdb-listener:
build: .
image: greenwave_dev
user: ${DEV_USER_ID:-1000}
working_dir: /
env_file: ["docker/dev.env"]
command:
- "/usr/bin/gunicorn-3"
- "--reload"
- "--bind=0.0.0.0:8082"
- "--access-logfile=-"
- "--enable-stdio-inheritance"
- "--workers=2"
- "greenwave.resultsdb_listener:app"
ports:
- 8082:8082
volumes:
- ./:/src:ro,z
- ./docker/home:/home/dev:rw,z
- ./docker/greenwave-settings.py:/etc/greenwave/settings.py:ro,z
- ./conf/policies/:/etc/greenwave/policies/:ro,z
- ./conf/subject_types/:/etc/greenwave/subject_types/:ro,z
depends_on:
- memcached
- umb
deploy:
replicas: ${GREENWAVE_LISTENERS:-1}

waiverdb-listener:
build: .
image: greenwave_dev
user: ${DEV_USER_ID:-1000}
working_dir: /
env_file: ["docker/dev.env"]
command:
- "/usr/bin/gunicorn-3"
- "--reload"
- "--bind=0.0.0.0:8083"
- "--access-logfile=-"
- "--enable-stdio-inheritance"
- "--workers=2"
- "greenwave.waiverdb_listener:app"
ports:
- 8083:8083
volumes:
- ./:/src:ro,z
- ./docker/home:/home/dev:rw,z
- ./docker/greenwave-settings.py:/etc/greenwave/settings.py:ro,z
- ./conf/policies/:/etc/greenwave/policies/:ro,z
- ./conf/subject_types/:/etc/greenwave/subject_types/:ro,z
depends_on:
- memcached
- umb
deploy:
replicas: ${GREENWAVE_LISTENERS:-1}

umb:
image: docker-registry.upshift.redhat.com/c3i/umb:latest
image: images.paas.redhat.com/exd-sp-guild-c3i/umb:latest
restart: unless-stopped
command:
- "java"
Expand All @@ -105,6 +149,8 @@ services:
ports:
- 5671:5671 # amqp
- 61612:61612 # stomp
deploy:
replicas: ${GREENWAVE_LISTENERS:-1}

networks:
default:
Expand Down
1 change: 0 additions & 1 deletion docker/dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ WAIVERDB_TEST_URL=http://waiverdb:5004/
RESULTSDB_TEST_URL=http://resultsdb:5001/
PYTEST_ADDOPTS=-o cache_dir=/home/dev/.pytest_cache
PYTHONPATH=/src
RESULTSDB_HANDLER=please
48 changes: 0 additions & 48 deletions docker/fedmsg.d/base.py

This file was deleted.

38 changes: 0 additions & 38 deletions docker/fedmsg.d/logging.py

This file was deleted.

21 changes: 17 additions & 4 deletions docker/greenwave-settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
HOST = '127.0.0.1'
PORT = 8080
DEBUG = True
POLICIES_DIR = '/etc/greenwave/policies/'
WAIVERDB_API_URL = 'http://waiverdb:5004/api/v1.0'
RESULTSDB_API_URL = 'http://resultsdb:5001/api/v2.0'
GREENWAVE_API_URL = 'http://dev:8080/api/v1.0'
POLICIES_DIR = "/etc/greenwave/policies/"
WAIVERDB_API_URL = "http://waiverdb:5004/api/v1.0"
RESULTSDB_API_URL = "http://resultsdb:5001/api/v2.0"
LISTENER_HOSTS = "umb:61612"
LISTENER_CONNECTION_SSL = None
LISTENER_CONNECTION = {
"heartbeats": (10000, 20000),
"keepalive": True,
"timeout": 5000,
"reconnect_sleep_initial": 1.0,
"reconnect_sleep_increase": 1.0,
"reconnect_sleep_max": 10.0,
"reconnect_attempts_max": 5,
}
CACHE = {
# 'backend': "dogpile.cache.null",
'backend': "dogpile.cache.memcached",
Expand All @@ -26,6 +36,9 @@
'dogpile.cache': {
'level': 'DEBUG',
},
"stomp.py": {
"level": "DEBUG",
},
},
'handlers': {
'console': {
Expand Down
19 changes: 11 additions & 8 deletions docker/resultsdb-settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

SECRET_KEY = 'resultsdb'
SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://resultsdb:resultsdb@resultsdb-db:5432/resultsdb'
FILE_LOGGING = False
Expand All @@ -6,14 +8,15 @@
STREAM_LOGGING = True
RUN_HOST = '0.0.0.0'
RUN_PORT = 5001
MESSAGE_BUS_PUBLISH = True
MESSAGE_BUS_PLUGIN = 'stomp'
ADDITIONAL_RESULT_OUTCOMES = ("RUNNING", "QUEUED", "ERROR")

MESSAGE_BUS_PUBLISH = os.environ.get("GREENWAVE_LISTENERS", "") not in ("", "0")
MESSAGE_BUS_PLUGIN = "stomp"
MESSAGE_BUS_KWARGS = {
'modname': 'resultsdb',
'destination': '/topic/VirtualTopic.eng.resultsdb.result.new',
'connection': {
'host_and_ports': [('localhost', 61612)],
'use_ssl': False,
"modname": "resultsdb",
"destination": "/topic/VirtualTopic.eng.resultsdb.result.new",
"connection": {
"host_and_ports": [("umb", 61612)],
"use_ssl": False,
},
}
ADDITIONAL_RESULT_OUTCOMES = ('RUNNING', 'QUEUED', 'ERROR')
11 changes: 10 additions & 1 deletion docker/waiverdb-settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@
PORT = 5004
#AUTH_METHOD = 'OIDC'
AUTH_METHOD = 'dummy'
MESSAGE_BUS_PUBLISH = False
SUPERUSERS = ['dummy']
#OIDC_CLIENT_SECRETS = '/etc/secret/client_secrets.json'
RESULTSDB_API_URL = 'http://resultsdb:5001/api/v2.0'

MESSAGE_BUS_PUBLISH = os.environ.get("GREENWAVE_LISTENERS", "") not in ("", "0")
MESSAGE_PUBLISHER = "stomp"
STOMP_CONFIGS = {
"destination": "/topic/VirtualTopic.eng.waiverdb.waiver.new",
"connection": {
"host_and_ports": [("umb", 61612)],
"use_ssl": False,
},
}
1 change: 1 addition & 0 deletions greenwave/app_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0+

import logging
import logging.config

from flask import Flask
from greenwave.api_v1 import api
Expand Down
Loading

0 comments on commit 1b5ad3a

Please sign in to comment.