From 884482620833062c475d0dfb5173eb07f1cd7087 Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Wed, 15 Oct 2025 16:22:07 +0800 Subject: [PATCH] Refactor admin client for message prompts (#10583) ### What problem does this PR solve? As title ### Type of change - [x] Refactoring Signed-off-by: Jin Hai --- admin/client/admin_client.py | 10 +++------- admin/server/config.py | 11 ++++++++--- admin/server/services.py | 10 +++++----- api/utils/health_utils.py | 34 ++++++++++++++++------------------ 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/admin/client/admin_client.py b/admin/client/admin_client.py index 9ff0f7f10..e2ed47440 100644 --- a/admin/client/admin_client.py +++ b/admin/client/admin_client.py @@ -213,12 +213,8 @@ class AdminCLI(Cmd): def onecmd(self, command: str) -> bool: try: - # print(f"command: {command}") result = self.parse_command(command) - # if 'type' in result and result.get('type') == 'empty': - # return False - if isinstance(result, dict): if 'type' in result and result.get('type') == 'empty': return False @@ -463,14 +459,14 @@ class AdminCLI(Cmd): res_json = response.json() if response.status_code == 200: res_data = res_json['data'] - if res_data['alive']: - print(f"Service {res_data['service_name']} is alive. Detail:") + if 'status' in res_data and res_data['status'] == 'alive': + print(f"Service {res_data['service_name']} is alive, ") if isinstance(res_data['message'], str): print(res_data['message']) else: self._print_table_simple(res_data['message']) else: - print(f"Service {res_data['service_name']} is down. Detail: {res_data['message']}") + print(f"Service {res_data['service_name']} is down, {res_data['message']}") else: print(f"Fail to show service, code: {res_json['code']}, message: {res_json['message']}") diff --git a/admin/server/config.py b/admin/server/config.py index 609c321a7..a14d95b1a 100644 --- a/admin/server/config.py +++ b/admin/server/config.py @@ -26,6 +26,8 @@ from urllib.parse import urlparse class ServiceConfigs: + configs = dict + def __init__(self): self.configs = [] self.lock = threading.Lock() @@ -229,7 +231,8 @@ def load_configurations(config_path: str) -> list[BaseConfig]: host: str = v['host'] http_port: int = v['http_port'] config = RAGFlowServerConfig(id=id_count, name=name, host=host, port=http_port, - service_type="ragflow_server", detail_func_name="check_ragflow_server_alive") + service_type="ragflow_server", + detail_func_name="check_ragflow_server_alive") configurations.append(config) id_count += 1 case "es": @@ -254,7 +257,8 @@ def load_configurations(config_path: str) -> list[BaseConfig]: host = parts[0] port = int(parts[1]) database: str = v.get('db_name', 'default_db') - config = InfinityConfig(id=id_count, name=name, host=host, port=port, service_type="retrieval", retrieval_type="infinity", + config = InfinityConfig(id=id_count, name=name, host=host, port=port, service_type="retrieval", + retrieval_type="infinity", db_name=database, detail_func_name="get_infinity_status") configurations.append(config) id_count += 1 @@ -266,7 +270,8 @@ def load_configurations(config_path: str) -> list[BaseConfig]: port = int(parts[1]) user = v.get('user') password = v.get('password') - config = MinioConfig(id=id_count, name=name, host=host, port=port, user=user, password=password, service_type="file_store", + config = MinioConfig(id=id_count, name=name, host=host, port=port, user=user, password=password, + service_type="file_store", store_type="minio", detail_func_name="check_minio_alive") configurations.append(config) id_count += 1 diff --git a/admin/server/services.py b/admin/server/services.py index c7dd30ab7..05a41ad53 100644 --- a/admin/server/services.py +++ b/admin/server/services.py @@ -181,12 +181,12 @@ class ServiceMgr: config_dict = config.to_dict() try: service_detail = ServiceMgr.get_service_details(service_id) - if service_detail['alive']: - config_dict['status'] = 'Alive' + if "status" in service_detail: + config_dict['status'] = service_detail['status'] else: - config_dict['status'] = 'Timeout' + config_dict['status'] = 'timeout' except Exception: - config_dict['status'] = 'Timeout' + config_dict['status'] = 'timeout' result.append(config_dict) return result @@ -206,7 +206,7 @@ class ServiceMgr: } service_info = service_config_mapping.get(service_id, {}) if not service_info: - raise AdminException(f"Invalid service_id: {service_id}") + raise AdminException(f"invalid service_id: {service_id}") detail_func = getattr(health_utils, service_info.get('detail_func_name')) res = detail_func() diff --git a/api/utils/health_utils.py b/api/utils/health_utils.py index 1396d7595..3a97fc572 100644 --- a/api/utils/health_utils.py +++ b/api/utils/health_utils.py @@ -74,12 +74,12 @@ def get_es_cluster_stats() -> dict: raise Exception("Elasticsearch is not in use.") try: return { - "alive": True, + "status": "alive", "message": ESConnection().get_cluster_stats() } except Exception as e: return { - "alive": False, + "status": "timeout", "message": f"error: {str(e)}", } @@ -90,12 +90,12 @@ def get_infinity_status(): raise Exception("Infinity is not in use.") try: return { - "alive": True, + "status": "alive", "message": InfinityConnection().health() } except Exception as e: return { - "alive": False, + "status": "timeout", "message": f"error: {str(e)}", } @@ -107,12 +107,12 @@ def get_mysql_status(): headers = ['id', 'user', 'host', 'db', 'command', 'time', 'state', 'info'] cursor.close() return { - "alive": True, + "status": "alive", "message": [dict(zip(headers, r)) for r in res_rows] } except Exception as e: return { - "alive": False, + "status": "timeout", "message": f"error: {str(e)}", } @@ -122,12 +122,12 @@ def check_minio_alive(): try: response = requests.get(f'http://{rag_settings.MINIO["host"]}/minio/health/live') if response.status_code == 200: - return {'alive': True, "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} + return {"status": "alive", "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} else: - return {'alive': False, "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} + return {"status": "timeout", "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} except Exception as e: return { - "alive": False, + "status": "timeout", "message": f"error: {str(e)}", } @@ -135,12 +135,12 @@ def check_minio_alive(): def get_redis_info(): try: return { - "alive": True, + "status": "alive", "message": REDIS_CONN.info() } except Exception as e: return { - "alive": False, + "status": "timeout", "message": f"error: {str(e)}", } @@ -150,12 +150,12 @@ def check_ragflow_server_alive(): try: response = requests.get(f'http://{settings.HOST_IP}:{settings.HOST_PORT}/v1/system/ping') if response.status_code == 200: - return {'alive': True, "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} + return {"status": "alive", "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} else: - return {'alive': False, "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} + return {"status": "timeout", "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} except Exception as e: return { - "alive": False, + "status": "timeout", "message": f"error: {str(e)}", } @@ -192,9 +192,7 @@ def run_health_checks() -> tuple[dict, bool]: except Exception: result["storage"] = "nok" - - all_ok = (result.get("db") == "ok") and (result.get("redis") == "ok") and (result.get("doc_engine") == "ok") and (result.get("storage") == "ok") + all_ok = (result.get("db") == "ok") and (result.get("redis") == "ok") and (result.get("doc_engine") == "ok") and ( + result.get("storage") == "ok") result["status"] = "ok" if all_ok else "nok" return result, all_ok - -