Skip to content

Commit fd237ab

Browse files
committed
Refactor config fetching
Signed-off-by: Jin Hai <haijin.chn@gmail.com>
1 parent 63131ec commit fd237ab

4 files changed

Lines changed: 26 additions & 30 deletions

File tree

admin/client/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Admin Service is a dedicated management component designed to monitor, maintain, and administrate the RAGFlow system. It provides comprehensive tools for ensuring system stability, performing operational tasks, and managing users and permissions efficiently.
66

7-
The service offers real-time monitoring of critical components, including the RAGFlow server, Task Executor processes, and dependent services such as MySQL, Elasticsearch, Redis, and MinIO. It automatically checks their health status, resource usage, and uptime, and performs restarts in case of failures to minimize downtime.
7+
The service offers real-time monitoring of critical components, including the RAGFlow server, Task Executor processes, and dependent services such as MySQL, Infinity, Elasticsearch, Redis, and MinIO. It automatically checks their health status, resource usage, and uptime, and performs restarts in case of failures to minimize downtime.
88

99
For user and system management, it supports listing, creating, modifying, and deleting users and their associated resources like knowledge bases and Agents.
1010

admin/server/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def decorated(*args, **kwargs):
169169
username = auth.parameters['username']
170170
password = auth.parameters['password']
171171
try:
172-
if check_admin(username, password) is False:
172+
if not check_admin(username, password):
173173
return jsonify({
174174
"code": 500,
175175
"message": "Access denied",

admin/server/config.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,21 @@
2525
from urllib.parse import urlparse
2626

2727

28+
class BaseConfig(BaseModel):
29+
id: int
30+
name: str
31+
host: str
32+
port: int
33+
service_type: str
34+
detail_func_name: str
35+
36+
def to_dict(self) -> dict[str, Any]:
37+
return {'id': self.id, 'name': self.name, 'host': self.host, 'port': self.port,
38+
'service_type': self.service_type}
39+
40+
2841
class ServiceConfigs:
29-
configs = dict
42+
configs = list[BaseConfig]
3043

3144
def __init__(self):
3245
self.configs = []
@@ -45,19 +58,6 @@ class ServiceType(Enum):
4558
FILE_STORE = "file_store"
4659

4760

48-
class BaseConfig(BaseModel):
49-
id: int
50-
name: str
51-
host: str
52-
port: int
53-
service_type: str
54-
detail_func_name: str
55-
56-
def to_dict(self) -> dict[str, Any]:
57-
return {'id': self.id, 'name': self.name, 'host': self.host, 'port': self.port,
58-
'service_type': self.service_type}
59-
60-
6161
class MetaConfig(BaseConfig):
6262
meta_type: str
6363

@@ -227,7 +227,7 @@ def load_configurations(config_path: str) -> list[BaseConfig]:
227227
ragflow_count = 0
228228
id_count = 0
229229
for k, v in raw_configs.items():
230-
match (k):
230+
match k:
231231
case "ragflow":
232232
name: str = f'ragflow_{ragflow_count}'
233233
host: str = v['host']

admin/server/services.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
17-
16+
import logging
1817
import re
1918
from werkzeug.security import check_password_hash
2019
from common.constants import ActiveEnum
@@ -190,7 +189,8 @@ def get_all_services():
190189
config_dict['status'] = service_detail['status']
191190
else:
192191
config_dict['status'] = 'timeout'
193-
except Exception:
192+
except Exception as e:
193+
logging.warning(f"Can't get service details, error: {e}")
194194
config_dict['status'] = 'timeout'
195195
if not config_dict['host']:
196196
config_dict['host'] = '-'
@@ -205,17 +205,13 @@ def get_services_by_type(service_type_str: str):
205205

206206
@staticmethod
207207
def get_service_details(service_id: int):
208-
service_id = int(service_id)
208+
service_idx = int(service_id)
209209
configs = SERVICE_CONFIGS.configs
210-
service_config_mapping = {
211-
c.id: {
212-
'name': c.name,
213-
'detail_func_name': c.detail_func_name
214-
} for c in configs
215-
}
216-
service_info = service_config_mapping.get(service_id, {})
217-
if not service_info:
218-
raise AdminException(f"invalid service_id: {service_id}")
210+
if service_idx < 0 or service_idx >= len(configs):
211+
raise AdminException(f"invalid service_index: {service_idx}")
212+
213+
service_config = configs[service_idx]
214+
service_info = {'name': service_config.name, 'detail_func_name': service_config.detail_func_name}
219215

220216
detail_func = getattr(health_utils, service_info.get('detail_func_name'))
221217
res = detail_func()

0 commit comments

Comments
 (0)