增加timing环境变量

This commit is contained in:
xiuting.xu
2026-04-15 16:26:09 +08:00
parent 17c1a02c90
commit 99250f8aa9
7 changed files with 107 additions and 29 deletions

View File

@@ -29,7 +29,8 @@ struct AppConfig {
max_delta: u8,
prune_delta_by_snapshot_size: bool,
strict_ccr_validation: bool,
refresh_interval: Duration,
source_refresh_interval: Duration,
timing: Timing,
service_config: RtrServiceConfig,
}
@@ -51,7 +52,8 @@ impl Default for AppConfig {
max_delta: 100,
prune_delta_by_snapshot_size: false,
strict_ccr_validation: false,
refresh_interval: Duration::from_secs(300),
source_refresh_interval: Duration::from_secs(300),
timing: Timing::default(),
service_config: RtrServiceConfig {
max_connections: 512,
@@ -126,22 +128,51 @@ impl AppConfig {
if let Some(value) = env_var("RPKI_RTR_STRICT_CCR_VALIDATION")? {
config.strict_ccr_validation = parse_bool(&value, "RPKI_RTR_STRICT_CCR_VALIDATION")?;
}
if let Some(value) = env_var("RPKI_RTR_REFRESH_INTERVAL_SECS")? {
let secs: u64 = value.parse().map_err(|err| {
anyhow!(
"invalid RPKI_RTR_REFRESH_INTERVAL_SECS '{}': {}",
value,
err
)
})?;
if secs == 0 {
return Err(anyhow!(
"invalid RPKI_RTR_REFRESH_INTERVAL_SECS '{}': must be >= 1",
value
));
let source_refresh_interval_new = env_var("RPKI_RTR_SOURCE_REFRESH_INTERVAL_SECS")?;
let source_refresh_interval_legacy = env_var("RPKI_RTR_REFRESH_INTERVAL_SECS")?;
match (
source_refresh_interval_new.as_deref(),
source_refresh_interval_legacy.as_deref(),
) {
(Some(new_value), Some(_)) => {
let secs = parse_positive_u64(
new_value,
"RPKI_RTR_SOURCE_REFRESH_INTERVAL_SECS",
)?;
config.source_refresh_interval = Duration::from_secs(secs);
warn!(
"both RPKI_RTR_SOURCE_REFRESH_INTERVAL_SECS and legacy RPKI_RTR_REFRESH_INTERVAL_SECS are set; using RPKI_RTR_SOURCE_REFRESH_INTERVAL_SECS"
);
}
config.refresh_interval = Duration::from_secs(secs);
(Some(new_value), None) => {
let secs = parse_positive_u64(
new_value,
"RPKI_RTR_SOURCE_REFRESH_INTERVAL_SECS",
)?;
config.source_refresh_interval = Duration::from_secs(secs);
}
(None, Some(legacy_value)) => {
let secs = parse_positive_u64(legacy_value, "RPKI_RTR_REFRESH_INTERVAL_SECS")?;
config.source_refresh_interval = Duration::from_secs(secs);
warn!(
"RPKI_RTR_REFRESH_INTERVAL_SECS is deprecated; use RPKI_RTR_SOURCE_REFRESH_INTERVAL_SECS"
);
}
(None, None) => {}
}
if let Some(value) = env_var("RPKI_RTR_TIMING_REFRESH_SECS")? {
config.timing.refresh = parse_positive_u32(&value, "RPKI_RTR_TIMING_REFRESH_SECS")?;
}
if let Some(value) = env_var("RPKI_RTR_TIMING_RETRY_SECS")? {
config.timing.retry = parse_positive_u32(&value, "RPKI_RTR_TIMING_RETRY_SECS")?;
}
if let Some(value) = env_var("RPKI_RTR_TIMING_EXPIRE_SECS")? {
config.timing.expire = parse_positive_u32(&value, "RPKI_RTR_TIMING_EXPIRE_SECS")?;
}
config
.timing
.validate()
.map_err(|err| anyhow!("invalid RTR timing configuration: {}", err))?;
if let Some(value) = env_var("RPKI_RTR_MAX_CONNECTIONS")? {
config.service_config.max_connections = value
.parse()
@@ -218,7 +249,7 @@ fn init_shared_cache(config: &AppConfig, store: &RtrStore) -> Result<SharedRtrCa
store,
config.max_delta,
config.prune_delta_by_snapshot_size,
Timing::default(),
config.timing,
|| load_payloads_from_latest_sources(&payload_load_config),
)?;
@@ -261,7 +292,7 @@ fn spawn_refresh_task(
store: RtrStore,
notifier: RtrNotifier,
) -> JoinHandle<()> {
let refresh_interval = config.refresh_interval;
let refresh_interval = config.source_refresh_interval;
let payload_load_config = PayloadLoadConfig {
ccr_dir: config.ccr_dir.clone(),
slurm_dir: config.slurm_dir.clone(),
@@ -358,9 +389,12 @@ fn log_startup_config(config: &AppConfig) {
info!("max_delta={}", config.max_delta);
info!("strict_ccr_validation={}", config.strict_ccr_validation);
info!(
"refresh_interval_secs={}",
config.refresh_interval.as_secs()
"source_refresh_interval_secs={}",
config.source_refresh_interval.as_secs()
);
info!("rtr_timing_refresh_secs={}", config.timing.refresh);
info!("rtr_timing_retry_secs={}", config.timing.retry);
info!("rtr_timing_expire_secs={}", config.timing.expire);
info!("max_connections={}", config.service_config.max_connections);
info!(
"notify_queue_size={}",
@@ -407,3 +441,23 @@ fn parse_bool(value: &str, name: &str) -> Result<bool> {
_ => Err(anyhow!("invalid {} '{}': expected boolean", name, value)),
}
}
fn parse_positive_u64(value: &str, name: &str) -> Result<u64> {
let parsed = value
.parse::<u64>()
.map_err(|err| anyhow!("invalid {} '{}': {}", name, value, err))?;
if parsed == 0 {
return Err(anyhow!("invalid {} '{}': must be >= 1", name, value));
}
Ok(parsed)
}
fn parse_positive_u32(value: &str, name: &str) -> Result<u32> {
let parsed = value
.parse::<u32>()
.map_err(|err| anyhow!("invalid {} '{}': {}", name, value, err))?;
if parsed == 0 {
return Err(anyhow!("invalid {} '{}': must be >= 1", name, value));
}
Ok(parsed)
}

View File

@@ -292,7 +292,7 @@ impl Timing {
impl Default for Timing {
fn default() -> Self {
Self {
refresh: 60,
refresh: 3600,
retry: 600,
expire: 7200,
}