From c5f76e7d4b7a2192982db09ce02a1159ec95bccc Mon Sep 17 00:00:00 2001 From: vicanso Date: Sat, 6 Apr 2024 14:13:47 +0800 Subject: [PATCH] refactor: support setting timeout from admin --- conf/pingap.toml | 4 ++-- docs/config_zh.md | 2 +- src/config/load.rs | 3 +++ src/main.rs | 5 ++++- src/serve/admin.rs | 11 +++++++++++ web/src/pages/basic-info.tsx | 21 +++++++++++++++++++++ web/src/states/config.ts | 3 +++ 7 files changed, 45 insertions(+), 4 deletions(-) diff --git a/conf/pingap.toml b/conf/pingap.toml index 9c261d1b..f0e33d51 100644 --- a/conf/pingap.toml +++ b/conf/pingap.toml @@ -4,8 +4,8 @@ error_template = "" # The pid file of this server. Default `/tmp/pingap.pid` pid_file = "/tmp/pingap.pid" -# The path to the upgrade socket. Default `/tmp/pingap.sock` -upgrade_sock = "/tmp/pingap.sock" +# The path to the upgrade socket. Default `/tmp/pingap_upgrade.sock` +upgrade_sock = "/tmp/pingap_upgrade.sock" # If configured, after daemonization, this process will switch to # the given user before starting to serve traffic. Default `None` diff --git a/docs/config_zh.md b/docs/config_zh.md index 430606ae..8d86ccea 100644 --- a/docs/config_zh.md +++ b/docs/config_zh.md @@ -8,7 +8,7 @@ Pingap使用toml来配置相关参数,具体参数说明如下: - `error_template`: 参数可选,出错时的html模板,可自定义出错的html模板,在出错时会替换模板中的`{{version}}`为pingap的版本号,`{{content}}`为出错的具体信息。 - `pid_file`: 参数可选,默认为`/tmp/pingap.pid`,此参数配置进程id的记录文件。 -- `upgrade_sock`: 参数可选,默认为`/tmp/pingap.sock`,此参数配置程序无中断式更新时的socket路径,用于新的pingap进程与旧进程之间切换时使用。 +- `upgrade_sock`: 参数可选,默认为`/tmp/pingap_upgrade.sock`,此参数配置程序无中断式更新时的socket路径,用于新的pingap进程与旧进程之间切换时使用。 - `user`: 参数可选,默认为空,用于设置守护进程的执行用户 - `group`: 参数可选,默认为空,与`user`类似 - `threads`: 参数可选,默认为1,用于设置每个服务(如server监控的tcp连接)使用的线程数,如果设置为0,则使用cpu或cgroup限制核数 diff --git a/src/config/load.rs b/src/config/load.rs index 0ee30eaa..04c9795e 100644 --- a/src/config/load.rs +++ b/src/config/load.rs @@ -219,6 +219,7 @@ pub struct PingapConf { #[serde(default)] #[serde(with = "humantime_serde")] pub graceful_shutdown_timeout: Option, + pub upstream_keepalive_pool_size: Option, } impl PingapConf { @@ -260,6 +261,7 @@ struct TomlConfig { #[serde(default)] #[serde(with = "humantime_serde")] pub graceful_shutdown_timeout: Option, + pub upstream_keepalive_pool_size: Option, } fn format_toml(value: &Value) -> String { @@ -340,6 +342,7 @@ pub fn load_config(path: &str, admin: bool) -> Result { created_at: data.created_at, grace_period: data.grace_period, graceful_shutdown_timeout: data.graceful_shutdown_timeout, + upstream_keepalive_pool_size: data.upstream_keepalive_pool_size, ..Default::default() }; for (name, value) in data.upstreams { diff --git a/src/main.rs b/src/main.rs index ef843e9e..aca0f1f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,7 @@ struct Args { fn new_server_conf(args: &Args, conf: &PingapConf) -> server::configuration::ServerConf { let mut server_conf = server::configuration::ServerConf { pid_file: format!("/tmp/{}.pid", utils::get_pkg_name()), - upgrade_sock: format!("/tmp/{}.sock", utils::get_pkg_name()), + upgrade_sock: format!("/tmp/{}_upgrade.sock", utils::get_pkg_name()), user: conf.user.clone(), group: conf.group.clone(), daemon: args.daemon, @@ -59,6 +59,9 @@ fn new_server_conf(args: &Args, conf: &PingapConf) -> server::configuration::Ser if let Some(value) = conf.graceful_shutdown_timeout { server_conf.graceful_shutdown_timeout_seconds = Some(value.as_secs()); } + if let Some(upstream_keepalive_pool_size) = conf.upstream_keepalive_pool_size { + server_conf.upstream_keepalive_pool_size = upstream_keepalive_pool_size; + } if let Some(pid_file) = &conf.pid_file { server_conf.pid_file = pid_file.to_string(); } diff --git a/src/serve/admin.rs b/src/serve/admin.rs index 91897a4f..552fb641 100644 --- a/src/serve/admin.rs +++ b/src/serve/admin.rs @@ -14,6 +14,7 @@ use once_cell::sync::Lazy; use pingora::proxy::Session; use rust_embed::RustEmbed; use serde::{Deserialize, Serialize}; +use std::time::Duration; use substring::Substring; #[derive(RustEmbed)] @@ -37,6 +38,13 @@ struct BasicConfParams { group: Option, threads: Option, work_stealing: Option, + #[serde(default)] + #[serde(with = "humantime_serde")] + pub grace_period: Option, + #[serde(default)] + #[serde(with = "humantime_serde")] + pub graceful_shutdown_timeout: Option, + pub upstream_keepalive_pool_size: Option, } #[derive(Serialize, Deserialize)] @@ -138,6 +146,9 @@ impl AdminServe { conf.group = basic_conf.group; conf.threads = basic_conf.threads; conf.work_stealing = basic_conf.work_stealing; + conf.grace_period = basic_conf.grace_period; + conf.graceful_shutdown_timeout = basic_conf.graceful_shutdown_timeout; + conf.upstream_keepalive_pool_size = basic_conf.upstream_keepalive_pool_size; } }; save_config(&config::get_config_path(), &mut conf).map_err(|e| { diff --git a/web/src/pages/basic-info.tsx b/web/src/pages/basic-info.tsx index c1158820..b62b9e34 100644 --- a/web/src/pages/basic-info.tsx +++ b/web/src/pages/basic-info.tsx @@ -57,6 +57,27 @@ export default function BasicInfo() { span: 6, category: FormItemCategory.TEXT, }, + { + id: "grace_period", + label: "Grace Period", + defaultValue: config.grace_period, + span: 6, + category: FormItemCategory.TEXT, + }, + { + id: "graceful_shutdown_timeout", + label: "Graceful Shutdown Timeout", + defaultValue: config.graceful_shutdown_timeout, + span: 6, + category: FormItemCategory.TEXT, + }, + { + id: "upstream_keepalive_pool_size", + label: "Upstream Keepalive Pool Size", + defaultValue: config.upstream_keepalive_pool_size, + span: 12, + category: FormItemCategory.NUMBER, + }, { id: "error_template", label: "Error Template", diff --git a/web/src/states/config.ts b/web/src/states/config.ts index 12cf24c0..57d70c68 100644 --- a/web/src/states/config.ts +++ b/web/src/states/config.ts @@ -48,6 +48,9 @@ interface Config { group?: string; threads?: number; work_stealing?: boolean; + grace_period?: string; + graceful_shutdown_timeout?: string; + upstream_keepalive_pool_size?: number; } interface ConfigState {