Skip to content

Commit e424ecb

Browse files
apollo_http_server: polling interval in config
1 parent 3e7fc5d commit e424ecb

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"http_server_config.dynamic_config.accept_new_txs": true,
33
"http_server_config.dynamic_config.max_sierra_program_size": 4194304,
4+
"http_server_config.static_config.dynamic_config_poll_interval": 1000,
45
"http_server_config.static_config.ip": "0.0.0.0",
56
"http_server_config.static_config.port": ""
67
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"http_server_config.dynamic_config.accept_new_txs": true,
33
"http_server_config.dynamic_config.max_sierra_program_size": 4194304,
4+
"http_server_config.static_config.dynamic_config_poll_interval": 1000,
45
"http_server_config.static_config.ip": "0.0.0.0",
56
"http_server_config.static_config.port": "$$$_HTTP_SERVER_CONFIG-STATIC_CONFIG-PORT_$$$"
67
}

crates/apollo_http_server/src/http_server.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,10 @@ impl HttpServer {
9797
let app = self.app();
9898
info!("HttpServer running using socket: {}", addr);
9999

100-
// TODO(Tsabary): make the poll interval part of the config.
101-
let poll_interval = Duration::from_millis(1_000);
102100
tokio::spawn(dynamic_config_poll(
103101
self.dynamic_config_tx.clone(),
104102
self.config_manager_client.clone(),
105-
poll_interval,
103+
self.config.static_config.dynamic_config_poll_interval,
106104
));
107105

108106
// TODO(update the http server struct to hold optional fields of the dynamic_config_tx,

crates/apollo_http_server_config/src/config.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use std::collections::BTreeMap;
22
use std::net::{IpAddr, Ipv4Addr};
3+
use std::time::Duration;
34

5+
use apollo_config::converters::deserialize_milliseconds_to_duration;
46
use apollo_config::dumping::{prepend_sub_config_name, ser_param, SerializeConfig};
57
use apollo_config::{ParamPath, ParamPrivacyInput, SerializedParam};
68
use serde::{Deserialize, Serialize};
79
use validator::Validate;
810

911
pub const HTTP_SERVER_PORT: u16 = 8080;
1012
pub const DEFAULT_MAX_SIERRA_PROGRAM_SIZE: usize = 4 * 1024 * 1024; // 4MB
13+
const DEFAULT_DYNAMIC_CONFIG_POLL_INTERVAL_MS: u64 = 1_000; // 1 second.
1114

1215
/// The http server connection related configuration.
1316
#[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)]
@@ -32,7 +35,13 @@ impl HttpServerConfig {
3235
accept_new_txs: true,
3336
max_sierra_program_size,
3437
},
35-
static_config: HttpServerStaticConfig { ip, port },
38+
static_config: HttpServerStaticConfig {
39+
ip,
40+
port,
41+
dynamic_config_poll_interval: Duration::from_millis(
42+
DEFAULT_DYNAMIC_CONFIG_POLL_INTERVAL_MS,
43+
),
44+
},
3645
}
3746
}
3847

@@ -45,20 +54,34 @@ impl HttpServerConfig {
4554
pub struct HttpServerStaticConfig {
4655
pub ip: IpAddr,
4756
pub port: u16,
57+
#[serde(deserialize_with = "deserialize_milliseconds_to_duration")]
58+
pub dynamic_config_poll_interval: Duration,
4859
}
4960

5061
impl SerializeConfig for HttpServerStaticConfig {
5162
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
5263
BTreeMap::from_iter([
5364
ser_param("ip", &self.ip.to_string(), "The http server ip.", ParamPrivacyInput::Public),
5465
ser_param("port", &self.port, "The http server port.", ParamPrivacyInput::Public),
66+
ser_param(
67+
"dynamic_config_poll_interval",
68+
&self.dynamic_config_poll_interval.as_millis(),
69+
"Polling interval (in milliseconds) for dynamic config.",
70+
ParamPrivacyInput::Public,
71+
),
5572
])
5673
}
5774
}
5875

5976
impl Default for HttpServerStaticConfig {
6077
fn default() -> Self {
61-
Self { ip: IpAddr::from(Ipv4Addr::UNSPECIFIED), port: HTTP_SERVER_PORT }
78+
Self {
79+
ip: IpAddr::from(Ipv4Addr::UNSPECIFIED),
80+
port: HTTP_SERVER_PORT,
81+
dynamic_config_poll_interval: Duration::from_millis(
82+
DEFAULT_DYNAMIC_CONFIG_POLL_INTERVAL_MS,
83+
),
84+
}
6285
}
6386
}
6487

crates/apollo_node/resources/config_schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,6 +2534,11 @@
25342534
"privacy": "Public",
25352535
"value": 4194304
25362536
},
2537+
"http_server_config.static_config.dynamic_config_poll_interval": {
2538+
"description": "Polling interval (in milliseconds) for dynamic config.",
2539+
"privacy": "Public",
2540+
"value": 1000
2541+
},
25372542
"http_server_config.static_config.ip": {
25382543
"description": "The http server ip.",
25392544
"privacy": "Public",

0 commit comments

Comments
 (0)