Skip to content

Commit

Permalink
refactor: support setting timeout from admin
Browse files Browse the repository at this point in the history
vicanso committed Apr 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e7b8ebf commit c5f76e7
Showing 7 changed files with 45 additions and 4 deletions.
4 changes: 2 additions & 2 deletions conf/pingap.toml
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion docs/config_zh.md
Original file line number Diff line number Diff line change
@@ -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限制核数
3 changes: 3 additions & 0 deletions src/config/load.rs
Original file line number Diff line number Diff line change
@@ -219,6 +219,7 @@ pub struct PingapConf {
#[serde(default)]
#[serde(with = "humantime_serde")]
pub graceful_shutdown_timeout: Option<Duration>,
pub upstream_keepalive_pool_size: Option<usize>,
}

impl PingapConf {
@@ -260,6 +261,7 @@ struct TomlConfig {
#[serde(default)]
#[serde(with = "humantime_serde")]
pub graceful_shutdown_timeout: Option<Duration>,
pub upstream_keepalive_pool_size: Option<usize>,
}

fn format_toml(value: &Value) -> String {
@@ -340,6 +342,7 @@ pub fn load_config(path: &str, admin: bool) -> Result<PingapConf> {
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 {
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -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();
}
11 changes: 11 additions & 0 deletions src/serve/admin.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
threads: Option<usize>,
work_stealing: Option<bool>,
#[serde(default)]
#[serde(with = "humantime_serde")]
pub grace_period: Option<Duration>,
#[serde(default)]
#[serde(with = "humantime_serde")]
pub graceful_shutdown_timeout: Option<Duration>,
pub upstream_keepalive_pool_size: Option<usize>,
}

#[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| {
21 changes: 21 additions & 0 deletions web/src/pages/basic-info.tsx
Original file line number Diff line number Diff line change
@@ -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",
3 changes: 3 additions & 0 deletions web/src/states/config.ts
Original file line number Diff line number Diff line change
@@ -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 {

0 comments on commit c5f76e7

Please sign in to comment.