def test_zk_prefix_replacement(): if os.getenv('ZOOKEEPER_PREFIX', None): os.unsetenv('ZOOKEEPER_PREFIX') assert load_config().zk_prefix == '/' os.environ['ZOOKEEPER_PREFIX'] = '/' assert load_config().zk_prefix == '/' os.environ['ZOOKEEPER_PREFIX'] = 'test' assert load_config().zk_prefix == '/test' os.environ['ZOOKEEPER_PREFIX'] = '/test' assert load_config().zk_prefix == '/test'
def do_GET(self): if self.path in ('/api/disk_stats', '/api/disk_stats/'): used_kb, free_kb = self.cmd_helper.get_disk_stats() self._send_response({'free_kb': free_kb, 'used_kb': used_kb}) elif self.path.startswith(_API_CONTROLLER): self.wrap_controller_execution(lambda: self._run_controller_action(self.path[len(_API_CONTROLLER):])) elif self.path in ('/api/metrics', '/api/metrics/'): config = load_config() env_provider = EnvProvider.create_env_provider(config) with load_exhibitor_proxy(env_provider.get_address_provider(), config.zk_prefix) as zookeeper: metrics = MetricCollector(zookeeper).get_metrics_from_brokers() self._send_response({'metrics': metrics}) else: self._send_response({'status': 'OK'})
def main(): logging.basicConfig(level=getattr(logging, 'INFO', None)) config = load_config() _LOG.info("Using configuration: {}".format(config)) process = KafkaProcess(config.kafka_dir) _LOG.info('Starting health server') cmd_helper = CmdHelper() controller_api.start_server(config.health_port, cmd_helper) restart_on_init = False while True: try: run_daemon_loop(config, process, cmd_helper, restart_on_init) break except Exception as ex: _LOG.error("WOW! Almost died! Will try to restart from the begin. " "After initialization will be complete, will try to restart", exc_info=ex) if process.is_running(): restart_on_init = False
def main(): logging.basicConfig(level=getattr(logging, 'INFO', None)) config = load_config() _LOG.info("Using configuration: {}".format(config)) process = KafkaProcess(config.kafka_dir) _LOG.info('Starting health server') cmd_helper = CmdHelper() health.start_server(config.health_port, cmd_helper) restart_on_init = False while True: try: run_daemon_loop(config, process, cmd_helper, restart_on_init) break except Exception as ex: _LOG.error( "WOW! Almost died! Will try to restart from the begin. " "After initialization will be complete, will try to restart", exc_info=ex) if process.is_running(): restart_on_init = False
def is_cluster_healthy(): config = load_config() try: response = requests.get('http://{}:{}/api/metrics'.format('localhost', '8080')) resp_json = response.json() if not resp_json['metrics']: return False for metrics in resp_json['metrics']: metric = metrics['metrics'] if metric: if metric['PreferredReplicaImbalance'] > 0: return False if metric['OfflinePartitions'] > 0: return False if metric['UnderReplicatedPartitions'] > 0: return False else: return False return True except Exception as e: _LOG.error('Failed to get cluster state', exc_info=e) return False
def prepare_configs(): config = load_config() _LOG.info('Using config: {}'.format(config)) env_provider = EnvProvider.create_env_provider(config) return config, env_provider
def __prepare_configs(): config = load_config() _LOG.info('Using config: {}'.format(config)) env_provider = EnvProvider.create_env_provider(config) return config, env_provider