Example #1
0
    def test_should_report_healthy_if_all_services_healthy(
            self, kafka_check, alarms_db_check, metrics_db_check, _):
        kafka_check.health_check.return_value = base.CheckResult(True, 'OK')
        alarms_db_check.health_check.return_value = base.CheckResult(
            True, 'OK')
        metrics_db_check.health_check.return_value = base.CheckResult(
            True, 'OK')
        self.set_route()
        self.resources._kafka_check = kafka_check
        self.resources._alarm_db_check = alarms_db_check
        self.resources._metrics_db_check = metrics_db_check

        response = self.simulate_request(
            ENDPOINT,
            headers={'Content-Type': 'application/json'},
            decode='utf8',
            method='GET')
        self.assertEqual(falcon.HTTP_OK, self.srmock.status)

        response = utils.from_json(response)
        self.assertIn('kafka', response)
        self.assertIn('alarms_database', response)
        self.assertIn('metrics_database', response)
        self.assertEqual('OK', response.get('kafka'))
        self.assertEqual('OK', response.get('alarms_database'))
        self.assertEqual('OK', response.get('metrics_database'))
Example #2
0
    def health_check(self):
        url = CONF.kafka.uri

        try:
            kafka_client = client.KafkaClient(hosts=url)
        except client.KafkaUnavailableError as ex:
            LOG.error(repr(ex))
            error_str = 'Could not connect to Kafka at {0}'.format(url)
            return base.CheckResult(healthy=False, message=error_str)

        status = self._verify_topics(kafka_client)
        self._disconnect_gracefully(kafka_client)

        return base.CheckResult(healthy=status[0], message=status[1])
Example #3
0
    def health_check(self):
        if self._db == 'influxdb':
            status = self._check_influxdb_status()
        else:
            status = self._check_cassandra_status()

        return base.CheckResult(healthy=status[0], message=status[1])
Example #4
0
    def test_should_report_not_healthy_if_one_service_not_healthy(self,
                                                                  kafka_check,
                                                                  alarms_db_check,
                                                                  metrics_db_check,
                                                                  _):
        test_list = [
            {'kafka': {'healthy': False, 'message': 'Unavailable'},
             'alarms_db': {'healthy': True, 'message': 'OK'},
             'netrics_db': {'healthy': True, 'message': 'OK'}
             },
            {'kafka': {'healthy': True, 'message': 'OK'},
             'alarms_db': {'healthy': False, 'message': 'Connection Error'},
             'netrics_db': {'healthy': True, 'message': 'OK'}
             },
            {'kafka': {'healthy': True, 'message': 'OK'},
             'alarms_db': {'healthy': True, 'message': 'OK'},
             'netrics_db': {'healthy': False, 'message': 'Error'}
             },
        ]

        for service in test_list:
            kafka_check.health_check.return_value = base.CheckResult(service['kafka']['healthy'],
                                                                     service['kafka']['message'])
            alarms_db_check.health_check.return_value = base.CheckResult(service['alarms_db']['healthy'],
                                                                         service['alarms_db']['message'])
            metrics_db_check.health_check.return_value = base.CheckResult(service['netrics_db']['healthy'],
                                                                          service['netrics_db']['message'])
            self.set_route()
            self.resources._kafka_check = kafka_check
            self.resources._alarm_db_check = alarms_db_check
            self.resources._metrics_db_check = metrics_db_check

            response = self.simulate_request(ENDPOINT,
                                             headers={
                                                 'Content-Type': 'application/json'
                                             },
                                             decode='utf8',
                                             method='GET')
            self.assertEqual(falcon.HTTP_SERVICE_UNAVAILABLE, self.srmock.status)

            response = utils.from_json(response)
            self.assertIn('kafka', response)
            self.assertIn('alarms_database', response)
            self.assertIn('metrics_database', response)
            self.assertEqual(service['kafka']['message'], response.get('kafka'))
            self.assertEqual(service['alarms_db']['message'], response.get('alarms_database'))
            self.assertEqual(service['netrics_db']['message'], response.get('metrics_database'))
    def health_check(self):
        metric_driver = CONF.repositories.metrics_driver
        db = self._detected_database_type(metric_driver)

        if db == 'influxdb':
            status = self._check_influxdb_status()
        else:
            status = self._check_cassandra_status()

        return base.CheckResult(healthy=status[0], message=status[1])
Example #6
0
 def health_check(self):
     status = self._metrics_repo.check_status()
     return base.CheckResult(healthy=status[0], message=status[1])
Example #7
0
 def health_check(self):
     status = self.check_db_status()
     return base.CheckResult(healthy=status[0], message=status[1])