Skip to content

Commit

Permalink
Report drone name in connect response (#592)
Browse files Browse the repository at this point in the history
* Report drone name in connect response

* Print drone in CLI
  • Loading branch information
paulgb authored Jan 31, 2024
1 parent 36a8950 commit 7b7723a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 33 deletions.

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

This file was deleted.

4 changes: 4 additions & 0 deletions plane/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ pub async fn run_admin_command_inner(opts: AdminOpts) -> Result<(), PlaneClientE
println!("URL: {}", response.url.bright_white());
println!("Status URL: {}", response.status_url.bright_white());

if let Some(drone) = response.drone {
println!("Drone: {}", drone.to_string().bright_green());
}

if wait {
let mut stream = client.backend_status_stream(&response.backend_id).await?;

Expand Down
2 changes: 2 additions & 0 deletions plane/src/database/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ async fn attempt_connect(
token,
secret_token,
client,
None,
);

return Ok(connect_response);
Expand Down Expand Up @@ -284,6 +285,7 @@ async fn attempt_connect(
token,
secret_token,
client,
Some(drone.drone),
);

Ok(connect_response)
Expand Down
23 changes: 20 additions & 3 deletions plane/src/database/drone.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{
heartbeat_consts::UNHEALTHY_SECONDS,
names::DroneName,
types::{ClusterName, NodeId},
};
use chrono::{DateTime, Utc};
use sqlx::{postgres::types::PgInterval, query, query_as, PgPool};
use sqlx::{postgres::types::PgInterval, query, PgPool};
use std::time::Duration;

pub struct DroneDatabase<'a> {
Expand Down Expand Up @@ -72,11 +73,11 @@ impl<'a> DroneDatabase<'a> {
&self,
cluster: &ClusterName,
) -> sqlx::Result<Option<DroneForSpawn>> {
let result = query_as!(
DroneForSpawn,
let result = query!(
r#"
select
drone.id,
node.name,
drone.last_local_time as "last_local_time!"
from node
left join drone
Expand Down Expand Up @@ -108,11 +109,27 @@ impl<'a> DroneDatabase<'a> {
.fetch_optional(self.pool)
.await?;

let result = match result {
Some(result) => {
let id = NodeId::from(result.id);
let drone = DroneName::try_from(result.name).expect("valid drone name");
let last_local_time = result.last_local_time;

Some(DroneForSpawn {
id,
drone,
last_local_time,
})
}
None => return Ok(None),
};

Ok(result)
}
}

pub struct DroneForSpawn {
pub id: NodeId,
pub drone: DroneName,
pub last_local_time: DateTime<Utc>,
}
11 changes: 10 additions & 1 deletion plane/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::{client::PlaneClient, names::BackendName, util::random_prefixed_string};
use crate::{
client::PlaneClient,
names::{BackendName, DroneName},
util::random_prefixed_string,
};
pub use backend_state::{BackendState, BackendStatus, TerminationKind, TerminationReason};
use bollard::auth::DockerCredentials;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -305,6 +309,9 @@ pub struct ConnectResponse {
pub secret_token: SecretToken,

pub status_url: String,

/// The drone that spawned this backend, if the request resulted in a spawn.
pub drone: Option<DroneName>,
}

impl ConnectResponse {
Expand All @@ -316,6 +323,7 @@ impl ConnectResponse {
token: BearerToken,
secret_token: SecretToken,
client: &PlaneClient,
drone: Option<DroneName>,
) -> Self {
let url = if cluster.is_https() {
format!("https://{}/{}/", cluster, token)
Expand All @@ -333,6 +341,7 @@ impl ConnectResponse {
url,
secret_token,
status_url,
drone,
}
}
}
Expand Down

0 comments on commit 7b7723a

Please sign in to comment.