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

✨ Rabbitmq: prepare for using topic queues #4165

Merged

Conversation

sanderegg
Copy link
Member

@sanderegg sanderegg commented Apr 25, 2023

What do these changes do?

  • some typing fixes
  • allows to use RabbitMQ topic exchanges by passing an optional topic parameter in publish and subscribe methods

NOTE: since we currently use durable exchanges they are kept within rabbitmq memory. Therefore one needs to change the name of the exchange between deployments once they get used.
Since this PR does not yet make use of the new feature this is not yet necessary, but will be once the topic queues are put to use for logs.

Using a topic queue brings the following possibilities:

  • say we have RabbitMQ exchange of type TOPIC
  • then one can publish logs in that exchange everytime setting the routing_key with origin.criticality pattern (e.g. publish(message="this is a log message", routing_key="dynamic_sidecar.INFO")
  • the webserver might connect to that exchange but only subscribing to topic of type *.WARNING
  • it will only receive the messages from any origin but with WARNING set up.

Here is a summary of how RabbitMQ messaging works

  1. First a quick image shows more than anything. This shows the different types of Exchanges (FANOUT - the current one we use, DIRECT and TOPICS)
    image
  2. in RabbitMQ an Exchange is just a kind of placeholder where messages are published to. They are not stored there unless 1 or more Queues are bound to the Exchange
  3. How these Queues are bound to the Exchange defines what messages go there (this is defined by the routing key. in case of DIRECT, the routing key must be exactly the same, in case of FANOUT the routing key is discarded, in case of TOPICS the routing key can be made of * (exactly 1 word) and # (0 or more words) and can contain . between words (e.g. .. and a message might use "director-v2.event.black".
  4. Additionally there can be 1 or more Consumers per Queue.
  5. Everytime a consumer successfully consumes a message from a Queue, that message disappears. Therefore you cannot keep messages 10 minutes there. They are kept until a consumer consumes them, or their TTL ran out or the Queue max number of messages is attained.

Related issue/s

How to test

DevOps Checklist

@sanderegg sanderegg added the a:services-library issues on packages/service-libs label Apr 25, 2023
@sanderegg sanderegg added this to the Jelly Beans milestone Apr 25, 2023
@sanderegg sanderegg requested a review from pcrespov as a code owner April 25, 2023 14:07
@sanderegg sanderegg self-assigned this Apr 25, 2023
@codecov
Copy link

codecov bot commented Apr 25, 2023

Codecov Report

Merging #4165 (45dddb0) into master (b2223f1) will increase coverage by 0.4%.
The diff coverage is 100.0%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #4165     +/-   ##
========================================
+ Coverage    85.4%   85.9%   +0.4%     
========================================
  Files         955     799    -156     
  Lines       41378   35660   -5718     
  Branches      945     540    -405     
========================================
- Hits        35358   30636   -4722     
+ Misses       5803    4896    -907     
+ Partials      217     128     -89     
Flag Coverage Δ
integrationtests 67.2% <ø> (-0.1%) ⬇️
unittests 82.2% <100.0%> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ackages/service-library/src/servicelib/rabbitmq.py 95.6% <100.0%> (+2.4%) ⬆️
...s/service-library/src/servicelib/rabbitmq_utils.py 89.1% <100.0%> (ø)

... and 161 files with indirect coverage changes

@sanderegg sanderegg marked this pull request as draft April 25, 2023 20:32
@sanderegg sanderegg marked this pull request as ready for review April 25, 2023 20:33
Copy link
Member

@pcrespov pcrespov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brilliant! thx!

@GitHK
Copy link
Contributor

GitHK commented Apr 26, 2023

@sanderegg One thing is not clear to me. Let's say the fronted subscribes to *.WARNING. This means that the following are possible:

  1. It will receive all messages with WARNING log level, from that moment onward?
  2. It is still capable of fetching messages from a 10 minutes ago from the queue?

It is not clear to me how the message delivery works. Currently we are using the pub/sub pattern (if you are not subscribed you do not get messages). What do the new queues bring?

Copy link
Contributor

@GitHK GitHK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

packages/service-library/src/servicelib/rabbitmq.py Outdated Show resolved Hide resolved
packages/service-library/src/servicelib/rabbitmq.py Outdated Show resolved Hide resolved
packages/service-library/src/servicelib/rabbitmq.py Outdated Show resolved Hide resolved
@sanderegg sanderegg force-pushed the rabbitmq/use_topic_queues_for_logs branch from 101531d to 2f91896 Compare April 26, 2023 20:20
@sanderegg
Copy link
Member Author

@sanderegg One thing is not clear to me. Let's say the fronted subscribes to *.WARNING. This means that the following are possible:

  1. It will receive all messages with WARNING log level, from that moment onward?
    Yes
  2. It is still capable of fetching messages from a 10 minutes ago from the queue?
    No.
    I updated the description above to try to better explain the concept behind RabbitMQ messageing

@sonarcloud
Copy link

sonarcloud bot commented Apr 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codeclimate
Copy link

codeclimate bot commented Apr 26, 2023

Code Climate has analyzed commit 45dddb0 and detected 0 issues on this pull request.

View more on Code Climate.

@sanderegg sanderegg merged commit beb9630 into ITISFoundation:master Apr 27, 2023
@sanderegg sanderegg deleted the rabbitmq/use_topic_queues_for_logs branch April 27, 2023 07:38
@matusdrobuliak66 matusdrobuliak66 mentioned this pull request May 30, 2023
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:services-library issues on packages/service-libs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants