Warn about missing hostname only when default one is available (#1488)

* Warn about missing hostname only when default one is available

The `No hostname was supplied` warning is affecting projects that use
AWS SQS (as detailed in #1357), as a hostname is not required when
setting up the broker URL. Instead, the official documentation [0] specifies
that the valid broker URL formats are:

* `sqs://`
* `sqs://aws_access_key_id:aws_secret_access_key@`

With these formats, the `kombu.utils.url.parse_url` util doesn't return
a hostname, and workers end up triggering the following warning:

> No hostname was supplied. Reverting to default 'None'

As the SQS transport doesn't provide a default value for hostname, this
diff changes the behavior to only warn the user when the hostname hasn't
been supplied but a default one is being set by the default connection
parameters for the defined transport.

Fixes #1357.

[0] https://docs.celeryproject.org/en/stable/getting-started/backends-and-brokers/sqs.html#configuration

* Use caplog default logging level of WARNING
This commit is contained in:
Michael Manganiello 2022-02-02 10:23:14 -03:00 committed by GitHub
parent ac92e047c1
commit 2f3b153acc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -625,7 +625,7 @@ class Connection:
transport_cls, transport_cls)
D = self.transport.default_connection_params
if not self.hostname:
if not self.hostname and D.get('hostname'):
logger.warning(
"No hostname was supplied. "
f"Reverting to default '{D.get('hostname')}'")

View File

@ -99,6 +99,19 @@ class test_connection_utils:
# see Appendix A of http://www.rabbitmq.com/uri-spec.html
self.assert_info(Connection(url), **expected)
@pytest.mark.parametrize('url,expected', [
('sqs://user:pass@',
{'userid': None, 'password': None, 'hostname': None,
'port': None, 'virtual_host': '/'}),
('sqs://',
{'userid': None, 'password': None, 'hostname': None,
'port': None, 'virtual_host': '/'}),
])
def test_sqs_example_urls(self, url, expected, caplog):
pytest.importorskip('boto3')
self.assert_info(Connection('sqs://'), **expected)
assert not caplog.records
@pytest.mark.skip('TODO: urllib cannot parse ipv6 urls')
def test_url_IPV6(self):
self.assert_info(