From 55fe2621f8ae3c7da5021ce001b81ea518dc1eb0 Mon Sep 17 00:00:00 2001 From: chakcy <947105045@qq.com> Date: Thu, 17 Sep 2026 15:34:18 +0800 Subject: [PATCH] =?UTF-8?q?modify=20=E4=BF=AE=E5=A4=8D=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E9=85=8D=E7=BD=AE=E4=B8=8E=E5=AE=9E=E9=99=85?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E9=85=8D=E7=BD=AE=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/workerAdmin.ts | 62 ++++++- src/views/WorkerView.vue | 371 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 413 insertions(+), 20 deletions(-) diff --git a/src/api/workerAdmin.ts b/src/api/workerAdmin.ts index f334b93..2d6a7c8 100644 --- a/src/api/workerAdmin.ts +++ b/src/api/workerAdmin.ts @@ -22,6 +22,12 @@ export interface AdminCmdReply { exit_request?: string } +/** 插件配置优先来源模式:toml=以 config.toml 为准(启动时覆盖缓存);cache=以缓存为准 */ +export type ConfigMode = 'toml' | 'cache' + +/** 展示值的实际来源:cache=运行时缓存;toml=缓存缺失或副本未响应,回退读配置文件 */ +export type ConfigSource = 'cache' | 'toml' + export interface RestartAllResult { worker_id: string ok: boolean @@ -125,10 +131,16 @@ export function parseJwt(token: string): AuthUser | null { /** 读取某插件的现有运行时配置([workers.config]) */ export function getWorkerConfig(token: string, workerType: string) { - return request<{ success: boolean; worker_type: string; config: Record }>( - `/api/v1/admin/workers/${encodeURIComponent(workerType)}/config`, - token, - ) + return request<{ + success: boolean + worker_type: string + worker_id?: string + /** 展示值实际来自哪一侧(后端如实回报,勿混用缓存/文件值) */ + source?: ConfigSource + /** 该类插件的配置优先来源模式 */ + mode?: ConfigMode + config: Record + }>(`/api/v1/admin/workers/${encodeURIComponent(workerType)}/config`, token) } /** 更新某插件的运行时配置([workers.config],路由配置除外),由 worker 写回并重启 */ @@ -160,4 +172,46 @@ export function scaleWorker(token: string, workerType: string, count: number) { ) } +export interface WorkerInstanceGroup { + worker_type: string + instance_id: string + mode: 'inline' | 'external' + replicas: number + worker_ids: string[] +} + +export interface ScaleInstanceResult { + success: boolean + result: { + worker_type: string + instance_id: string + target: number + mode: 'inline' | 'external' + sent_to?: string + reply?: AdminCmdReply & { persist?: string } + } +} + +/** 按「外部进程实例」分组列出某类型的 worker(精细扩缩寻址) */ +export function listWorkerInstances(token: string, workerType: string) { + return request<{ success: boolean; result: WorkerInstanceGroup[] }>( + `/api/v1/admin/workers/${encodeURIComponent(workerType)}/instances`, + token, + ) +} + +/** 把某实例精确扩缩到指定副本数(绝对数,不影响其它实例) */ +export function scaleWorkerInstance( + token: string, + workerType: string, + instanceId: string, + count: number, +) { + return request( + `/api/v1/admin/workers/${encodeURIComponent(workerType)}/scale_instance`, + token, + { method: 'POST', body: JSON.stringify({ instance_id: instanceId, count }) }, + ) +} + export const TOKEN_KEY = 'cm_admin_token' \ No newline at end of file diff --git a/src/views/WorkerView.vue b/src/views/WorkerView.vue index 57bd00f..48f314d 100644 --- a/src/views/WorkerView.vue +++ b/src/views/WorkerView.vue @@ -65,6 +65,34 @@ +
+ + + + + + +
+ 副本数 ≥ + +
+ 筛选同时作用于下方「逐实例精细扩缩」分组表(副本数仅对实例分组表生效) +
+ 调小会优雅排空:先隔离新请求,等当前请求处理完再关闭对应副本;数量将写入配置,重启网关后保持。调小会优雅排空:先隔离新请求,等当前请求处理完再关闭对应副本;数量写入运行时缓存——cache + 模式下重启网关后保持,TOML 模式下重启会被 config.toml 的 count 覆盖。 + 逐实例精细扩缩 +
+
+ 把某个外部进程/实例精确调整到指定副本数(绝对数,不影响其它实例);「调整数量」全局缩放会清除这些定制、回到均匀分摊。 +
+ + + + + + + + + + + + + + +
@@ -182,7 +253,7 @@ type="info" :closable="false" show-icon - title="写入插件 config.toml 的 [workers.config](路由配置除外)。由 worker 写回并重启所有对应副本。" + :title="configAlertTitle" style="margin-bottom: 14px" /> @@ -190,6 +261,17 @@ {{ workerType || '-' }} +
+ + 模式:{{ configMode === 'cache' ? '缓存为准' : 'TOML 为准' }} + + + 来源:{{ configSource === 'cache' ? '运行时缓存' : 'config.toml(回退读取)' }} + + + 副本未响应或缓存中无该键,以上取自配置文件,可能不是实际生效值 + +
+ + +
+ +
+ + 格式化 + + + JSON 不合法:{{ configJsonError }} + + JSON 合法 +
+