Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New zocalo.util.rabbitmq.RabbitMQAPI #140

Merged
merged 30 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f018165
New zocalo.util.rabbitmq.RabbitMQAPI
rjgildea Oct 13, 2021
61e1fa8
Method -> property
rjgildea Oct 14, 2021
2c37a48
history
rjgildea Oct 14, 2021
1013cdb
Use RabbitMQAPI in dlq_check
rjgildea Oct 14, 2021
7dcc637
Fix test
rjgildea Oct 14, 2021
dfe8034
Remove broken attempt at filtering useful keys
rjgildea Oct 18, 2021
212c54c
WIP advanced API
rjgildea Oct 22, 2021
0201dfb
nodes and connections
rjgildea Oct 22, 2021
8bab661
Remove underscore prefix
rjgildea Oct 25, 2021
45d688d
Fix tests for new API
rjgildea Oct 25, 2021
ece517d
Tests for queue_declare/delete
rjgildea Oct 25, 2021
7a19152
Tests for exchanges endpoints
rjgildea Oct 25, 2021
55b3177
Test for empty exchange name
rjgildea Oct 25, 2021
5c1f1f2
Test for rmqapi.connections()
rjgildea Oct 25, 2021
94e0d6f
get/add/delete users
rjgildea Oct 26, 2021
2e68810
get/set/clear policies
rjgildea Oct 26, 2021
73094b2
dict -> Dict
rjgildea Oct 27, 2021
77d5b2a
Add vhost to Exchange/Policy/QueueSpec
rjgildea Oct 27, 2021
11919ea
Test exchange_delete
rjgildea Oct 27, 2021
ec0e219
Add {create,delete}_component singledispatchmethods
rjgildea Oct 27, 2021
3f123de
Add requests, pydantic to dependencies
rjgildea Oct 27, 2021
fd63b3a
Updated RabbitMQAPI interface
rjgildea Oct 27, 2021
455984b
Merge branch 'main' into rabbitmqapi2
rjgildea Oct 27, 2021
d7197ce
Remove debugging code
rjgildea Oct 27, 2021
5b92239
Add dependencies here too
rjgildea Oct 27, 2021
e91b751
Move RabbitMQAPI instantiation in line with use
rjgildea Oct 27, 2021
bca16dd
Remove duplicate key
rjgildea Oct 27, 2021
24ebf4c
Too much history is a bad thing
rjgildea Oct 28, 2021
7c3e26b
Partial revert of ec0e219
rjgildea Nov 3, 2021
e517160
Remove logging of response to silence lgtm warnings
rjgildea Nov 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ repos:
hooks:
- id: mypy
files: 'src/.*\.py$'
additional_dependencies: [types-requests]
12 changes: 7 additions & 5 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ History
Unreleased
----------
* Add command line tools for handling dead-letter messages
* ``zocalo.dlq_check`` checks dead-letter queues for messages
* ``zocalo.dlq_purge`` removes messages from specified DLQs and dumps them to a directory
specified in the Zocalo configuration
* ``zocalo.dlq_reinject`` takes a serialised message produced by ``zocalo.dlq_purge`` and
* ``zocalo.dlq_check`` checks dead-letter queues for messages
* ``zocalo.dlq_purge`` removes messages from specified DLQs and dumps them to a directory
specified in the Zocalo configuration
* ``zocalo.dlq_reinject`` takes a serialised message produced by ``zocalo.dlq_purge`` and
places it back on a queue
* Use ``argparse`` for all command line tools and make use of ``workflows`` transport
* Use ``argparse`` for all command line tools and make use of ``workflows`` transport
argument injection. Minimum ``workflows`` version is now 2.14
* New ``zocalo.util.rabbitmq.RabbitMQAPI()`` providing a thin wrapper around the
RabbitMQ HTTP API

0.10.0 (2021-10-04)
-------------------
Expand Down
3 changes: 3 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
PyYAML==6.0
graypy==2.1.0
marshmallow==3.14.0
pydantic
pytest-cov==3.0.0
pytest-mock
pytest==6.2.5
requests
requests_mock
setuptools==58.3.0
workflows==2.14
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ install_requires =
PyYAML
graypy>=1.0
marshmallow
requests
pydantic
setuptools
workflows>=2.14
packages = find:
Expand Down
22 changes: 9 additions & 13 deletions src/zocalo/cli/dlq_check.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import argparse
import json
import urllib

import workflows.transport

import zocalo.configuration
from zocalo.util.jmxstats import JMXAPI
from zocalo.util.rabbitmq import http_api_request
from zocalo.util.rabbitmq import RabbitMQAPI

#
# zocalo.dlq_check
Expand Down Expand Up @@ -50,16 +48,14 @@ def extract_queue_name(namestring):
def check_dlq_rabbitmq(
zc: zocalo.configuration.Configuration, namespace: str = None
) -> dict:
_api_request = http_api_request(zc, "/queues")
with urllib.request.urlopen(_api_request) as response:
reply = response.read()
queue_info = json.loads(reply)
dlq_info = {}
for q in queue_info:
if q["name"].startswith("dlq."):
if (namespace is None or q["vhost"] == namespace) and int(q["messages"]):
dlq_info[q["name"]] = int(q["messages"])
return dlq_info
rmq = RabbitMQAPI.from_zocalo_configuration(zc)
return {
q.name: q.messages
for q in rmq.queues()
if q.name.startswith("dlq.")
and (namespace is None or q.vhost == namespace)
and q.messages
}


def run() -> None:
Expand Down
10 changes: 3 additions & 7 deletions src/zocalo/cli/dlq_reinject.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import workflows.transport

import zocalo.configuration
from zocalo.util.rabbitmq import http_api_request
from zocalo.util.rabbitmq import RabbitMQAPI


def run() -> None:
Expand Down Expand Up @@ -130,12 +130,8 @@ def run() -> None:
header = dlqmsg["header"]
exchange = header.get("headers", {}).get("x-death", {})[0].get("exchange")
if exchange:
import urllib

_api_request = http_api_request(zc, "/queues")
with urllib.request.urlopen(_api_request) as response:
reply = response.read()
exchange_info = json.loads(reply)
rmqapi = RabbitMQAPI.from_zocalo_configuration(zc)
exchange_info = rmqapi.get("queues").json()
for exch in exchange_info:
if exch["name"] == exchange:
if exch["type"] == "fanout":
Expand Down
Loading