diff --git a/datadog/api/api_client.py b/datadog/api/api_client.py index f453b4ec9..851c2e9ad 100644 --- a/datadog/api/api_client.py +++ b/datadog/api/api_client.py @@ -257,7 +257,10 @@ def _should_submit(cls): # number of timeouts, then enter the backoff state, recording the time # we started backing off if not cls._backoff_timestamp and cls._timeout_counter >= cls._max_timeouts: - log.info("Max number of datadog timeouts exceeded, backing off for {0} seconds".format(cls._backoff_period)) + log.info( + "Max number of datadog timeouts exceeded, backing off for %s seconds", + cls._backoff_period, + ) cls._backoff_timestamp = now should_submit = False @@ -268,13 +271,17 @@ def _should_submit(cls): backed_off_time, backoff_time_left = cls._backoff_status() if backoff_time_left < 0: log.info( - "Exiting backoff state after {0} seconds, will try to submit metrics again".format(backed_off_time) + "Exiting backoff state after %s seconds, will try to submit metrics again", + backed_off_time, ) cls._backoff_timestamp = None cls._timeout_counter = 0 should_submit = True else: - log.info("In backoff state, won't submit metrics for another {0} seconds".format(backoff_time_left)) + log.info( + "In backoff state, won't submit metrics for another %s seconds", + backoff_time_left, + ) should_submit = False else: should_submit = True diff --git a/datadog/dogstatsd/base.py b/datadog/dogstatsd/base.py index db92b5fcd..919cfdaaf 100644 --- a/datadog/dogstatsd/base.py +++ b/datadog/dogstatsd/base.py @@ -605,13 +605,19 @@ def _xmit_packet(self, packet, is_telemetry): # dogstatsd is overflowing, drop the packets (mimicks the UDP behaviour) pass except (socket.herror, socket.gaierror) as se: - log.warning("Error submitting packet: {}, dropping the packet and closing the socket".format(se)) + log.warning( + "Error submitting packet: %s, dropping the packet and closing the socket", + se, + ) self.close_socket() except socket.error as se: if se.errno == errno.EAGAIN: log.debug("Socket send would block: %s, dropping the packet", se) else: - log.warning("Error submitting packet: {}, dropping the packet and closing the socket".format(se)) + log.warning( + "Error submitting packet: %s, dropping the packet and closing the socket", + se, + ) self.close_socket() except Exception as e: log.error("Unexpected error: %s", str(e)) diff --git a/tests/unit/dogstatsd/test_statsd.py b/tests/unit/dogstatsd/test_statsd.py index 83ef2a2bf..39ee22c42 100644 --- a/tests/unit/dogstatsd/test_statsd.py +++ b/tests/unit/dogstatsd/test_statsd.py @@ -375,7 +375,8 @@ def test_socket_error(self): self.statsd.gauge('no error', 1) mock_log.error.assert_not_called() mock_log.warning.assert_called_once_with( - "Error submitting packet: Socket error, dropping the packet and closing the socket" + "Error submitting packet: %s, dropping the packet and closing the socket", + mock.ANY, ) def test_socket_overflown(self):