Skip to content

Commit

Permalink
Remove idle request interval for agent (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky authored May 8, 2024
1 parent 90f7e05 commit d16edbf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 49 deletions.
12 changes: 1 addition & 11 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,7 @@ impl Cli {
Commands::GenerateConfigSchema(generator) => {
return generator.generate_config_schema();
}
Commands::Agent(agent) => {
let ready = components::agent::Ready {
idle_request_interval: agent
.idle_request_interval_secs
.map(std::time::Duration::from_secs)
.unwrap_or(admin_server::IDLE_REQUEST_INTERVAL),
..Default::default()
};
Admin::Agent(ready)
}
Commands::Agent(_) => Admin::Agent(<_>::default()),
Commands::Proxy(proxy) => {
let ready = components::proxy::Ready {
idle_request_interval: proxy
Expand All @@ -169,7 +160,6 @@ impl Cli {
}
Commands::Manage(_mng) => {
let ready = components::manage::Ready {
idle_request_interval: admin_server::IDLE_REQUEST_INTERVAL,
is_manage: true,
..Default::default()
};
Expand Down
5 changes: 0 additions & 5 deletions src/cli/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ pub struct Agent {
/// If specified, additionally filters the gameserver address by its ip kind
#[clap(long, requires("address_type"), value_enum)]
pub ip_kind: Option<crate::config::AddrKind>,
/// The interval in seconds at which the agent will wait for a discovery
/// request from a relay server before restarting the connection.
#[clap(long, env = "QUILKIN_IDLE_REQUEST_INTERVAL_SECS")]
pub idle_request_interval_secs: Option<u64>,
/// The ICAO code for the agent.
#[clap(short, long, env, default_value_t = crate::config::IcaoCode::default())]
pub icao_code: crate::config::IcaoCode,
Expand Down Expand Up @@ -88,7 +84,6 @@ impl Default for Agent {
zone: <_>::default(),
sub_zone: <_>::default(),
provider: <_>::default(),
idle_request_interval_secs: None,
icao_code: <_>::default(),
address_type: None,
ip_kind: None,
Expand Down
1 change: 0 additions & 1 deletion src/components/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ impl Admin {
pub fn idle_request_interval(&self) -> Duration {
match self {
Self::Proxy(config) => config.idle_request_interval,
Self::Agent(config) => config.idle_request_interval,
Self::Relay(config) => config.idle_request_interval,
_ => IDLE_REQUEST_INTERVAL,
}
Expand Down
1 change: 0 additions & 1 deletion src/components/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::sync::{

#[derive(Clone, Debug, Default)]
pub struct Ready {
pub idle_request_interval: std::time::Duration,
pub provider_is_healthy: Arc<AtomicBool>,
pub relay_is_healthy: Arc<AtomicBool>,
/// If true, only care about the provider being healthy, not the relay
Expand Down
4 changes: 1 addition & 3 deletions src/components/manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ impl Manage {
None,
);

let idle_request_interval = ready.idle_request_interval;

let _relay_stream = if !self.relay_servers.is_empty() {
tracing::info!("connecting to relay server");
let client = crate::net::xds::client::MdsClient::connect(
Expand Down Expand Up @@ -70,7 +68,7 @@ impl Manage {
let server_task = tokio::spawn(crate::net::xds::server::spawn(
self.listener,
config,
idle_request_interval,
crate::components::admin::IDLE_REQUEST_INTERVAL,
)?)
.map_err(From::from)
.and_then(std::future::ready);
Expand Down
44 changes: 16 additions & 28 deletions src/net/xds/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,20 @@ impl MdsClient {
let handle = tokio::task::spawn(
async move {
tracing::trace!("starting relay client delta stream task");
let interval = rt_config.idle_request_interval;

loop {
{
let control_plane =
super::server::ControlPlane::from_arc(config.clone(), interval);
let control_plane = super::server::ControlPlane::from_arc(
config.clone(),
crate::components::admin::IDLE_REQUEST_INTERVAL,
);
let mut stream = control_plane.delta_aggregated_resources(stream).await?;
rt_config.relay_is_healthy.store(true, Ordering::SeqCst);

loop {
let timeout = tokio::time::timeout(interval, stream.next());

match timeout.await {
Ok(Some(result)) => {
let response = result?;
tracing::trace!("received delta discovery response");
ds.send_response(response).await?;
}
_ => break,
}
while let Some(result) = stream.next().await {
let response = result?;
tracing::trace!("received delta discovery response");
ds.send_response(response).await?;
}
}

Expand Down Expand Up @@ -699,7 +693,6 @@ impl MdsStream {
identifier.clone(),
move |(requests, mut rx), _| async move {
tracing::trace!("starting relay client stream task");
let idle_interval = rt_config.idle_request_interval;

loop {
let initial_response = DiscoveryResponse {
Expand All @@ -722,22 +715,17 @@ impl MdsStream {
.await?
.into_inner();

let control_plane =
super::server::ControlPlane::from_arc(config.clone(), idle_interval);
let control_plane = super::server::ControlPlane::from_arc(
config.clone(),
crate::components::admin::IDLE_REQUEST_INTERVAL,
);
let mut stream = control_plane.stream_resources(stream).await?;
rt_config.relay_is_healthy.store(true, Ordering::SeqCst);

loop {
let timeout = tokio::time::timeout(idle_interval, stream.next());

match timeout.await {
Ok(Some(result)) => {
let response = result?;
tracing::debug!(config=%serde_json::to_value(&config).unwrap(), "received discovery response");
requests.send(response)?;
}
_ => break,
}
while let Some(result) = stream.next().await {
let response = result?;
tracing::debug!(config=%serde_json::to_value(&config).unwrap(), "received discovery response");
requests.send(response)?;
}

rt_config.relay_is_healthy.store(false, Ordering::SeqCst);
Expand Down

0 comments on commit d16edbf

Please sign in to comment.