Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plane/plane-tests/tests/common/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl TestEnvironment {
None,
None,
None,
2,
)
.await
.expect("Unable to construct controller.")
Expand Down Expand Up @@ -179,6 +180,7 @@ impl TestEnvironment {
None,
None,
Some(forward_auth.clone()),
2,
)
.await
.expect("Unable to construct controller.")
Expand Down
4 changes: 4 additions & 0 deletions plane/src/controller/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub struct ControllerOpts {
/// (after stripping `/ctrl` and everything before it).
#[clap(long)]
forward_auth: Option<Url>,

#[clap(long, default_value = "2")]
best_of: i64,
}

impl ControllerOpts {
Expand All @@ -56,6 +59,7 @@ impl ControllerOpts {
cleanup_min_age_days: self.cleanup_min_age_days,
cleanup_batch_size: None,
forward_auth: self.forward_auth,
best_of: self.best_of,
})
}
}
10 changes: 9 additions & 1 deletion plane/src/controller/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Controller {
pub id: ControllerName,
pub client: PlaneClient,
pub default_cluster: Option<ClusterName>,
pub best_of: i64,
}

pub struct NodeHandle {
Expand Down Expand Up @@ -77,6 +78,7 @@ impl Controller {
id: ControllerName,
controller_url: Url,
default_cluster: Option<ClusterName>,
best_of: i64,
) -> Self {
let client = PlaneClient::new(controller_url);

Expand All @@ -85,6 +87,7 @@ impl Controller {
id,
client,
default_cluster,
best_of,
}
}

Expand All @@ -94,7 +97,12 @@ impl Controller {
) -> Result<ConnectResponse, ConnectError> {
let response = self
.db
.connect(self.default_cluster.as_ref(), connect_request, &self.client)
.connect(
self.default_cluster.as_ref(),
connect_request,
&self.client,
self.best_of,
)
.await?;

Ok(response)
Expand Down
13 changes: 11 additions & 2 deletions plane/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl ControllerServer {
config.cleanup_min_age_days,
config.cleanup_batch_size,
config.forward_auth,
config.best_of,
)
.await
}
Expand All @@ -186,6 +187,7 @@ impl ControllerServer {
cleanup_min_age_days: Option<i32>,
cleanup_batch_size: Option<i32>,
forward_auth: Option<Url>,
best_of: i64,
) -> Result<Self> {
let bind_addr = listener.local_addr()?;

Expand All @@ -200,8 +202,14 @@ impl ControllerServer {
let (graceful_terminate_sender, graceful_terminate_receiver) =
tokio::sync::oneshot::channel::<()>();

let controller =
Controller::new(db.clone(), id.clone(), controller_url, default_cluster).await;
let controller = Controller::new(
db.clone(),
id.clone(),
controller_url,
default_cluster,
best_of,
)
.await;

let trace_layer = TraceLayer::new_for_http()
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
Expand Down Expand Up @@ -353,6 +361,7 @@ pub struct ControllerConfig {
pub cleanup_min_age_days: Option<i32>,
pub cleanup_batch_size: Option<i32>,
pub forward_auth: Option<Url>,
pub best_of: i64,
}

pub async fn run_controller(config: ControllerConfig) -> Result<()> {
Expand Down
6 changes: 4 additions & 2 deletions plane/src/database/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ async fn attempt_connect(
default_cluster: Option<&ClusterName>,
request: &ConnectRequest,
client: &PlaneClient,
best_of: i64,
) -> Result<ConnectResponse> {
let key = if let Some(key) = &request.key {
// Request includes a key, so we need to check if it is held.
Expand Down Expand Up @@ -317,7 +318,7 @@ async fn attempt_connect(
.ok_or(ConnectError::NoClusterProvided)?;

let drone = DroneDatabase::new(pool)
.pick_drone_for_spawn(cluster, &spawn_config.pool)
.pick_drone_for_spawn(cluster, &spawn_config.pool, best_of)
.await?
.ok_or(ConnectError::NoDroneAvailable)?;

Expand Down Expand Up @@ -372,10 +373,11 @@ pub async fn connect(
default_cluster: Option<&ClusterName>,
request: &ConnectRequest,
client: &PlaneClient,
best_of: i64,
) -> Result<ConnectResponse> {
let mut attempt = 1;
loop {
match attempt_connect(pool, default_cluster, request, client).await {
match attempt_connect(pool, default_cluster, request, client, best_of).await {
Ok(response) => return Ok(response),
Err(error) => {
if !error.retryable() || attempt >= 3 {
Expand Down
4 changes: 3 additions & 1 deletion plane/src/database/drone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
) -> sqlx::Result<Vec<DroneWithMetadata>> {
// Converting to a PgInterval fails if the duration has nanosecond granularity.
// So let's round up to the nearest microsecond.
let seen_in_last = if seen_in_last.subsec_nanos() % 1000 == 0 {

Check warning on line 107 in plane/src/database/drone.rs

View workflow job for this annotation

GitHub Actions / clippy

manual implementation of `.is_multiple_of()`

warning: manual implementation of `.is_multiple_of()` --> plane/src/database/drone.rs:107:31 | 107 | let seen_in_last = if seen_in_last.subsec_nanos() % 1000 == 0 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `seen_in_last.subsec_nanos().is_multiple_of(1000)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#manual_is_multiple_of = note: `#[warn(clippy::manual_is_multiple_of)]` on by default

Check warning on line 107 in plane/src/database/drone.rs

View workflow job for this annotation

GitHub Actions / clippy

manual implementation of `.is_multiple_of()`

warning: manual implementation of `.is_multiple_of()` --> plane/src/database/drone.rs:107:31 | 107 | let seen_in_last = if seen_in_last.subsec_nanos() % 1000 == 0 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `seen_in_last.subsec_nanos().is_multiple_of(1000)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#manual_is_multiple_of = note: `#[warn(clippy::manual_is_multiple_of)]` on by default
seen_in_last
} else {
let nanos = (seen_in_last.subsec_micros() + 1) * 1000;
Expand Down Expand Up @@ -175,6 +175,7 @@
&self,
cluster: &ClusterName,
pool: &DronePoolName,
best_of: i64,
) -> sqlx::Result<Option<DroneForSpawn>> {
let result = query!(
r#"
Expand Down Expand Up @@ -205,13 +206,14 @@
and last_local_time is not null
and pool = $3
order by random()
limit 2
limit $5
"#,
cluster.to_string(),
PgInterval::try_from(Duration::from_secs(UNHEALTHY_SECONDS as _))
.expect("valid interval"),
pool.to_string(),
BackendStatus::Terminated.to_string(),
best_of,
)
.fetch_all(self.pool)
.await?;
Expand Down
3 changes: 2 additions & 1 deletion plane/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@
}
}

pub fn acme(&self) -> acme::AcmeDatabase {

Check warning on line 59 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:59:17 | 59 | pub fn acme(&self) -> acme::AcmeDatabase { | ^^^^^ ^^^^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default help: use `'_` for type paths | 59 | pub fn acme(&self) -> acme::AcmeDatabase<'_> { | ++++

Check warning on line 59 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:59:17 | 59 | pub fn acme(&self) -> acme::AcmeDatabase { | ^^^^^ ^^^^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default help: use `'_` for type paths | 59 | pub fn acme(&self) -> acme::AcmeDatabase<'_> { | ++++
AcmeDatabase::new(&self.pool)
}

pub fn drone(&self) -> DroneDatabase {

Check warning on line 63 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:63:18 | 63 | pub fn drone(&self) -> DroneDatabase { | ^^^^^ ^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 63 | pub fn drone(&self) -> DroneDatabase<'_> { | ++++

Check warning on line 63 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:63:18 | 63 | pub fn drone(&self) -> DroneDatabase { | ^^^^^ ^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 63 | pub fn drone(&self) -> DroneDatabase<'_> { | ++++
DroneDatabase::new(&self.pool)
}

pub fn cluster(&self) -> ClusterDatabase {

Check warning on line 67 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:67:20 | 67 | pub fn cluster(&self) -> ClusterDatabase { | ^^^^^ ^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 67 | pub fn cluster(&self) -> ClusterDatabase<'_> { | ++++

Check warning on line 67 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:67:20 | 67 | pub fn cluster(&self) -> ClusterDatabase { | ^^^^^ ^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 67 | pub fn cluster(&self) -> ClusterDatabase<'_> { | ++++
ClusterDatabase::new(&self.pool)
}

pub fn node(&self) -> NodeDatabase {

Check warning on line 71 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:71:17 | 71 | pub fn node(&self) -> NodeDatabase { | ^^^^^ ^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 71 | pub fn node(&self) -> NodeDatabase<'_> { | ++++

Check warning on line 71 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:71:17 | 71 | pub fn node(&self) -> NodeDatabase { | ^^^^^ ^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 71 | pub fn node(&self) -> NodeDatabase<'_> { | ++++
NodeDatabase::new(&self.pool)
}

pub fn backend(&self) -> BackendDatabase {

Check warning on line 75 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:75:20 | 75 | pub fn backend(&self) -> BackendDatabase { | ^^^^^ ^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 75 | pub fn backend(&self) -> BackendDatabase<'_> { | ++++

Check warning on line 75 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:75:20 | 75 | pub fn backend(&self) -> BackendDatabase { | ^^^^^ ^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 75 | pub fn backend(&self) -> BackendDatabase<'_> { | ++++
BackendDatabase::new(self)
}

Expand All @@ -80,11 +80,11 @@
BackendActionDatabase::new(&self.pool)
}

pub fn keys(&self) -> backend_key::KeysDatabase {

Check warning on line 83 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:83:17 | 83 | pub fn keys(&self) -> backend_key::KeysDatabase { | ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 83 | pub fn keys(&self) -> backend_key::KeysDatabase<'_> { | ++++

Check warning on line 83 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:83:17 | 83 | pub fn keys(&self) -> backend_key::KeysDatabase { | ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 83 | pub fn keys(&self) -> backend_key::KeysDatabase<'_> { | ++++
KeysDatabase::new(&self.pool)
}

pub fn controller(&self) -> controller::ControllerDatabase {

Check warning on line 87 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:87:23 | 87 | pub fn controller(&self) -> controller::ControllerDatabase { | ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 87 | pub fn controller(&self) -> controller::ControllerDatabase<'_> { | ++++

Check warning on line 87 in plane/src/database/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> plane/src/database/mod.rs:87:23 | 87 | pub fn controller(&self) -> controller::ControllerDatabase { | ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 87 | pub fn controller(&self) -> controller::ControllerDatabase<'_> { | ++++
ControllerDatabase::new(&self.pool)
}

Expand All @@ -100,8 +100,9 @@
default_cluster: Option<&ClusterName>,
request: &ConnectRequest,
client: &PlaneClient,
best_of: i64,
) -> Result<ConnectResponse, ConnectError> {
connect::connect(&self.pool, default_cluster, request, client).await
connect::connect(&self.pool, default_cluster, request, client, best_of).await
}
pub async fn revoke(&self, request: &RevokeRequest) -> Result<(), ConnectError> {
connect::revoke(&self.pool, request).await
Expand Down
Loading