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

Conversation

rjgildea
Copy link
Contributor

Provide a (not fully comprehensive) Python wrapper around the RabbitMQ HTTP API. Can be used to read various metrics useful for monitoring/health checks, and configuring exchanges, policies, queues, etc.

Adds explicit dependencies on pydantic and requests modules and a test dependency on requests-mock.

Alternative to #136

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Oct 27, 2021

This pull request introduces 1 alert when merging d7197ce into a7a1ff8 - view on LGTM.com

new alerts:

  • 1 for Clear-text logging of sensitive information

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Oct 27, 2021

This pull request introduces 1 alert when merging 5b92239 into a7a1ff8 - view on LGTM.com

new alerts:

  • 1 for Clear-text logging of sensitive information

This line isn't hit in the tests, and it isn't trivial to inject
fake credentials via the test.
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Oct 27, 2021

This pull request introduces 1 alert when merging e91b751 into a7a1ff8 - view on LGTM.com

new alerts:

  • 1 for Clear-text logging of sensitive information

HISTORY.rst Outdated Show resolved Hide resolved
Comment on lines 680 to 681
@create_component.register
def exchange_declare(self, exchange: ExchangeSpec):
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting use of singledispatch 🤔

Comment on lines 694 to 696
@delete_component.register
def _delete_exchange(self, exchange: ExchangeSpec, **kwargs):
self.exchange_delete(vhost=exchange.vhost, name=exchange.name, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

But surely this one should just be called def _(...):?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did have it as def _(...) but then mypy complains about it, see eg. python/mypy#2904

Copy link
Contributor

Choose a reason for hiding this comment

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

If this style is acceptable, I slightly prefer it - I still read the function name first, but all the examples I could find for singledispatch used this style.

Comment on lines 217 to 218
rmqapi.exchange_declare(exchange=exchange_spec(name))
rmqapi.create_component(exchange_spec(name))
Copy link
Contributor

Choose a reason for hiding this comment

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

So do these two calls not do the same thing then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd added the {exchange,queue}_{declare,delete} etc methods originally, more closely mirroring either the pika or rabbitmqctl interfaces, and then later added the {create,delete}_component interfaces for compatibility with what @d-j-hatton did in his original implementation of the configuration script. E.g. queue_delete and delete_component(queue) have different interfaces, as you can call the former with just the vhost and name strings, whereas the latter expects a full QueueSpec object.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Oct 28, 2021

This pull request introduces 1 alert when merging 24ebf4c into a7a1ff8 - view on LGTM.com

new alerts:

  • 1 for Clear-text logging of sensitive information

@d-j-hatton
Copy link
Contributor

I used a singledispatchmethod in the configuration script that this has inherited because we didn't need to worry about python versions there (singledispatchmethod was new in 3.8). Does this need a slight rewrite to fix the test failures related to this, or do we want to drop the singledispatch in favour of a more {exchange, queue}_{declare, delete} design?

@rjgildea
Copy link
Contributor Author

rjgildea commented Nov 3, 2021

I used a singledispatchmethod in the configuration script that this has inherited because we didn't need to worry about python versions there (singledispatchmethod was new in 3.8). Does this need a slight rewrite to fix the test failures related to this, or do we want to drop the singledispatch in favour of a more {exchange, queue}_{declare, delete} design?

Since the singledispatch mode was added after the explicit {exchange, queue}_{declare, delete} versions, it should only need a relatively straightforward revert of a single commit. The updated version of the server configuration script that uses the API would need a bit of re-working to use the explicit methods, but obviously not insurmountable.

@d-j-hatton
Copy link
Contributor

I used a singledispatchmethod in the configuration script that this has inherited because we didn't need to worry about python versions there (singledispatchmethod was new in 3.8). Does this need a slight rewrite to fix the test failures related to this, or do we want to drop the singledispatch in favour of a more {exchange, queue}_{declare, delete} design?

Since the singledispatch mode was added after the explicit {exchange, queue}_{declare, delete} versions, it should only need a relatively straightforward revert of a single commit. The updated version of the server configuration script that uses the API would need a bit of re-working to use the explicit methods, but obviously not insurmountable.

I think either way is fairly simple. The single dispatch method could just be changed to call a single dispatch that doesn't live inside the class. I don't mind either direction. Any preferences?

functools.singledispatchmethod is Python 3.8+ only
@rjgildea
Copy link
Contributor Author

rjgildea commented Nov 3, 2021

I used a singledispatchmethod in the configuration script that this has inherited because we didn't need to worry about python versions there (singledispatchmethod was new in 3.8). Does this need a slight rewrite to fix the test failures related to this, or do we want to drop the singledispatch in favour of a more {exchange, queue}_{declare, delete} design?

Since the singledispatch mode was added after the explicit {exchange, queue}_{declare, delete} versions, it should only need a relatively straightforward revert of a single commit. The updated version of the server configuration script that uses the API would need a bit of re-working to use the explicit methods, but obviously not insurmountable.

I think either way is fairly simple. The single dispatch method could just be changed to call a single dispatch that doesn't live inside the class. I don't mind either direction. Any preferences?

I've removed the functools.singledispatchmethod use here, and then in our configuration script we can just extend the API to add the {create,delete}_component methods where we don't have the limitation of supporting Python prior to 3.8.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Nov 3, 2021

This pull request introduces 1 alert when merging 7c3e26b into 5f070ee - view on LGTM.com

new alerts:

  • 1 for Clear-text logging of sensitive information

@rjgildea rjgildea merged commit d0ea600 into DiamondLightSource:main Nov 3, 2021
@rjgildea rjgildea deleted the rabbitmqapi2 branch November 3, 2021 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants