def test_handle_actions_only_wrong_type(mock_controller): action_handler = ActionHandler(mock_controller) wrong_type_action = {"type": "NON_EXIST"} actions = [wrong_type_action for _ in range(10)] action_handler.handle_actions(actions) assert mock_controller.kill_actor.call_count == 0
def test_handle_actions_many_kill_actor(mock_controller): action_handler = ActionHandler(mock_controller) # 10 actions required. actions = [_get_mock_kill_action() for _ in range(10)] action_handler.handle_actions(actions) assert mock_controller.kill_actor.call_count == 10
class Exporter(threading.Thread): """Python thread that exports metrics periodically. Args: dashboard_id(str): Unique Dashboard ID. address(str): Address to export metrics. dashboard_controller(BaseDashboardController): dashboard controller for dashboard business logic. update_frequency(float): Frequency to export metrics. """ def __init__(self, dashboard_id, address, dashboard_controller, update_frequency=1.0): assert update_frequency >= 1.0 self.dashboard_id = dashboard_id self.dashboard_controller = dashboard_controller self.action_handler = ActionHandler(dashboard_controller) self.export_address = "{}/ingest".format(address) self.update_frequency = update_frequency self._access_token = None super().__init__() @property def access_token(self): return self._access_token @access_token.setter def access_token(self, access_token): self._access_token = access_token def export(self, ray_config, node_info, raylet_info, tune_info, tune_availability): ingest_response = api.ingest_request(self.export_address, self.dashboard_id, self.access_token, ray_config, node_info, raylet_info, tune_info, tune_availability) actions = ingest_response.actions self.action_handler.handle_actions(actions) def run(self): assert self.access_token is not None, ( "Set access token before running an exporter thread.") while True: try: time.sleep(self.update_frequency) self.export(self.dashboard_controller.get_ray_config(), self.dashboard_controller.get_node_info(), self.dashboard_controller.get_raylet_info(), self.dashboard_controller.tune_info(), self.dashboard_controller.tune_availability()) except Exception as e: logger.error("Exception occured while exporting metrics: {}.\n" "Traceback: {}".format(e, traceback.format_exc())) continue
def test_handle_actions_kill_actor_and_mixed_type(mock_controller): action_handler = ActionHandler(mock_controller) wrong_type_action = {"type": "NON_EXIST"} actions = [ _get_mock_kill_action(), wrong_type_action, _get_mock_kill_action() ] action_handler.handle_actions(actions) assert mock_controller.kill_actor.call_count == 2
def __init__(self, dashboard_id, address, dashboard_controller, update_frequency=1.0): assert update_frequency >= 1.0 self.dashboard_id = dashboard_id self.dashboard_controller = dashboard_controller self.action_handler = ActionHandler(dashboard_controller) self.export_address = "{}/ingest".format(address) self.update_frequency = update_frequency self._access_token = None super().__init__()
def test_handle_kill_action_invalid_dict(mock_controller): action_handler = ActionHandler(mock_controller) kill_action = {"type": "KILL_ACTOR", "ip_address": "1234", "port": 30} with pytest.raises(ValidationError): action_handler.handle_kill_action(kill_action)
def test_handle_kill_action(mock_controller): action_handler = ActionHandler(mock_controller) kill_action = _get_mock_kill_action() action_handler.handle_kill_action(kill_action) assert mock_controller.kill_actor.call_count == 1