Beispiel #1
0
 def test_check_kafka_connection(self):
     """Test check kafka connections."""
     with patch("kafka.BrokerConnection.connect_blocking",
                return_value=False):
         result = check_kafka_connection()
         self.assertFalse(result)
     with patch("kafka.BrokerConnection.connect_blocking",
                return_value=True):
         with patch("kafka.BrokerConnection.close") as mock_close:
             result = check_kafka_connection()
             mock_close.assert_called()
             self.assertTrue(result)
Beispiel #2
0
 def readiness_check(self):
     """Set the readiness check response."""
     status = 424
     msg = "not ready"
     if self.ready:
         if not check_kafka_connection():
             response = ProbeResponse(status, "kafka connection error")
             self._write_response(response)
             self.logger.info(response.json)
             return
         if not check_sources_connection():
             response = ProbeResponse(status, "sources-api not ready")
             self._write_response(response)
             self.logger.info(response.json)
             return
         status = 200
         msg = "ok"
     self._write_response(ProbeResponse(status, msg))
Beispiel #3
0
def is_kafka_connected():  # pragma: no cover
    """
    Check connectability to Kafka messenger.

    This method will block sources integration initialization until
    Kafka is connected.
    """
    count = 0
    result = False
    while not result:
        result = check_kafka_connection()
        if result:
            LOG.info("Test connection to Kafka was successful.")
        else:
            LOG.error("Unable to connect to Kafka server.")
            KAFKA_CONNECTION_ERRORS_COUNTER.inc()
            backoff(count)
            count += 1
    return result