def test_stacktrace_full_task(): stacktrace = """java.lang.Exception: Stack trace at java.base/java.lang.Thread.dumpStack(Thread.java:1383) at com.ericgoebelbecker.stacktraces.StackTrace.d(StackTrace.java:23) """ patcherGet = patch("requests.get") mock_get = patcherGet.start() mock_get.return_value = MockResp( data={"foo": { "status": { "tasks": [{ "trace": stacktrace }] } }}) resp = connect.load_state(0) patcherGet.stop() mock_get.assert_called_once_with( "http://localhost:8083/connectors?expand=info&expand=status", timeout=TIMEOUT) assert resp[0]["tasks"][0][ "traceShort"] == "java.lang.Exception: Stack trace" assert resp[0]["tasks"][0]["traceException"] == "java.lang.Exception" assert resp[0]["tasks"][0]["trace"] == stacktrace assert resp[0]["tasks"][0]["downtime"] is not None
def test_load_state(data): patcherGet = patch("requests.get") mock_get = patcherGet.start() mock_get.return_value = MockResp(data=data) resp = connect.load_state(0) patcherGet.stop() mock_get.assert_called_once_with( "http://localhost:8083/connectors?expand=info&expand=status", timeout=TIMEOUT) assert resp == []
def connectors(): cluster_states = [] errors = [] resp = {"state": cluster_states, "errors": errors} for cluster in config.get_connect_clusters(): cluster_url = cluster["url"] cluster_id = cluster["id"] try: logger.info("request connect cluster state {}".format(cluster)) state = connect.load_state(cluster_id) cache_entry = get_store().merge( store.CacheEntry( id=cluster_id, state=state, running=True, error_mesage="", last_time_running=datetime.now(), )) cluster_states.extend(cache_entry.get_state()) except ConnectionError: error_msg = config.ERROR_MSG_CLUSTER_NOT_REACHABLE.format( cluster_url) logger.info(error_msg) cache_entry = get_store().merge( store.CacheEntry(id=cluster_id, running=False, error_mesage=error_msg)) cluster_states.extend(cache_entry.get_state()) errors.append({"message": error_msg}) except Timeout: error_msg = config.ERROR_MSG_CLUSTER_TIMEOUT.format(cluster_url) logger.info(error_msg) get_store().merge( store.CacheEntry(id=cluster_id, running=False, error_mesage=error_msg)) cluster_states.extend(cache_entry.get_state()) errors.append({"message": error_msg}) return jsonify(resp)
def run(self): cache = store.CacheManager(config.get_redis()) for cluster in config.get_connect_clusters(): try: cluster_id = cluster["id"] logger.info("loading cluster state {}".format(cluster)) state = connect.load_state(cluster_id) logger.info("merging cache {}".format(cluster)) cache.merge( store.CacheEntry( id=cluster_id, state=state, running=True, error_mesage=None, last_time_running=datetime.now(), )) logger.info("cache updated {}".format(cluster)) except ConnectionError: logger.info( config.ERROR_MSG_CLUSTER_NOT_REACHABLE.format( config.get_connect_url(cluster_id))) cache.merge( store.CacheEntry( id=cluster_id, running=False, error_mesage=config.ERROR_MSG_CLUSTER_NOT_REACHABLE. format(config.get_connect_url(cluster_id)), )) except Timeout: logger.info( config.ERROR_MSG_CLUSTER_TIMEOUT.format( config.get_connect_url(cluster_id))) cache.merge( store.CacheEntry( id=cluster_id, running=False, error_mesage=config.ERROR_MSG_CLUSTER_TIMEOUT.format( config.get_connect_url(cluster_id)), )) except Exception as e: logger.error("Could not update cache: %s", e)
def test_cluster_info(): patcherGet = patch("requests.get") mock_get = patcherGet.start() mock_get.return_value = MockResp( data={"foo": { "status": { "connector": {}, "tasks": [] } }}) resp = connect.load_state(0) patcherGet.stop() mock_get.assert_called_once_with( "http://localhost:8083/connectors?expand=info&expand=status", timeout=TIMEOUT) assert resp[0]["cluster"] is not None assert resp[0]["cluster"]["url"] is not None assert resp[0]["cluster"]["id"] is not None
def test_trace_short(): patcherGet = patch("requests.get") mock_get = patcherGet.start() mock_get.return_value = MockResp( data={"foo": { "status": { "connector": { "trace": "foo\nbar" } } }}) resp = connect.load_state(0) patcherGet.stop() mock_get.assert_called_once_with( "http://localhost:8083/connectors?expand=info&expand=status", timeout=TIMEOUT) assert resp[0]["connector"]["traceShort"] == "foo" assert resp[0]["connector"]["trace"] == "foo\nbar" assert resp[0]["connector"]["downtime"] is not None