Skip to content

Commit ef39232

Browse files
authored
Merge pull request #819 from rackerlabs/PUC-176-document-notifications
feat: PUC-176: Adding link of OpenStack RabbitMQ Queue Dump Tool in Operators guide for better visibility
2 parents ea7755a + 93121aa commit ef39232

File tree

3 files changed

+52
-26
lines changed

3 files changed

+52
-26
lines changed

docs/operator-guide/rabbitmq.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ kubectl -n openstack exec -it rabbitmq-server-0 -c rabbitmq -- rabbitmqadmin --v
6161
kubectl -n openstack exec -it rabbitmq-server-0 -c rabbitmq -- rabbitmqadmin --vhost=nova get queue=notifications.info ackmode=ack_requeue_true payload_file=/tmp/test.json
6262
kubectl -n openstack cp rabbitmq-server-0:/tmp/test.json -c rabbitmq /tmp/test.json
6363
```
64+
65+
### To dump, print, list-events, and requeue an openstack notifications rabbitmq queue
66+
67+
use [OpenStack RabbitMQ Queue Dump Tool](https://github.com/rackerlabs/understack/tree/main/examples/openstack-notifications)

examples/openstack-notifications/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ export RABBIT_PASS=$(kubectl -n openstack get secret rabbitmq-default-user -o js
2121
kubectl -n openstack port-forward svc/rabbitmq 5672
2222
```
2323

24-
3. Run the `queue_dump.py` tool:
24+
4. Use RabbitMq management UI to know more about Virtualhosts, Exchanges, Queues etc, follow the instructions [provided here](https://rackerlabs.github.io/understack/operator-guide/rabbitmq/):
25+
26+
27+
5. Run the `queue_dump.py` tool:
2528

2629
``` text
2730
 python queue_dump.py -h
2831
usage: queue-dump [-h] -u USERNAME -p PASSWORD [--host HOST] [--port PORT] [--virtualhost VIRTUALHOST] [--queue QUEUE] [-v] [--destroy]
2932
30-
dump, print, and requeue an openstack notifications rabbitmq queue
33+
dump, print, list-events, and requeue an openstack notifications rabbitmq queue
3134
3235
options:
3336
-h, --help show this help message and exit
@@ -52,6 +55,14 @@ options:
5255
python queue_dump.py -u $RABBIT_USER -p $RABBIT_PASS
5356
```
5457

58+
## List OpenStack notifications event types
59+
60+
If you want to understand what are the different event-types being emitted by OpenStack notifications system, you can use:
61+
62+
```
63+
python queue_dump.py --virtualhost $VIRTUAL_HOST -u $RABBIT_USER -p $RABBIT_PASS --queue notifications.info --list-event-types
64+
```
65+
5566
## Find OpenStack notifications for a specific event type
5667

5768
If you need to find a specific event type to troubleshoot something, you can use:

examples/openstack-notifications/queue_dump.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
required=False,
3131
help="Scan for a specific OpenStack notification event type",
3232
)
33+
parser.add_argument(
34+
"--list-event-types",
35+
action="store_true",
36+
help="List event_type values found in the queue",
37+
)
3338
parser.add_argument(
3439
"--provision-state",
3540
type=str,
@@ -73,32 +78,37 @@ def callback(ch, method, properties, body):
7378
if message:
7479
parsed["oslo.message"] = message
7580

76-
if args.event_type or args.provision_state:
77-
if args.event_type:
78-
event_type = message.get("event_type")
79-
if event_type == args.event_type:
80-
print(json.dumps(parsed, indent=4))
81-
82-
if args.provision_state:
83-
payload = message.get("payload", {})
84-
ironic_object = payload.get("ironic_object.data", {})
85-
provision_state = ironic_object.get("provision_state")
86-
if provision_state == args.provision_state:
87-
print(json.dumps(parsed, indent=4))
88-
else:
89-
print(json.dumps(parsed, indent=4))
90-
91-
if args.destroy:
92-
print("Destroying message.")
93-
# Acknowledge that the message has been handled, removing it from the queue.
94-
ch.basic_ack(delivery_tag=method.delivery_tag)
81+
event_type = message.get("event_type")
9582

83+
if args.list_event_types and message.get("event_type", None):
84+
print(event_type)
9685
else:
97-
if args.verbose:
98-
print("Re-queueing the message.")
99-
100-
# Requeue the message using using nack
101-
ch.basic_nack(delivery_tag=method.delivery_tag, requeue=True)
86+
if args.event_type or args.provision_state:
87+
if args.event_type:
88+
event_type = message.get("event_type")
89+
if event_type == args.event_type:
90+
print(json.dumps(parsed, indent=4))
91+
92+
if args.provision_state:
93+
payload = message.get("payload", {})
94+
ironic_object = payload.get("ironic_object.data", {})
95+
provision_state = ironic_object.get("provision_state")
96+
if provision_state == args.provision_state:
97+
print(json.dumps(parsed, indent=4))
98+
else:
99+
print(json.dumps(parsed, indent=4))
100+
101+
if args.destroy:
102+
print("Destroying message.")
103+
# Acknowledge that the message has been handled, removing it from the queue.
104+
ch.basic_ack(delivery_tag=method.delivery_tag)
105+
106+
else:
107+
if args.verbose:
108+
print("Re-queueing the message.")
109+
110+
# Requeue the message using using nack
111+
ch.basic_nack(delivery_tag=method.delivery_tag, requeue=True)
102112

103113

104114
# Set up the consumer to pull messages from the queue
@@ -108,6 +118,7 @@ def callback(ch, method, properties, body):
108118
try:
109119
# Start consuming messages
110120
channel.start_consuming()
121+
111122
except KeyboardInterrupt:
112123
# Gracefully stop the consumer on CTRL+C
113124
print("\nStopping consumer.")

0 commit comments

Comments
 (0)