Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backend status stream endpoint #844

Merged
merged 1 commit into from
Nov 15, 2024
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
65 changes: 34 additions & 31 deletions plane/src/admin.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use std::path::PathBuf;

use crate::{
client::{PlaneClient, PlaneClientError},
client::{sse::SseStream, PlaneClient, PlaneClientError},
names::{BackendName, DroneName, Name, ProxyName},
protocol::{CertManagerRequest, CertManagerResponse, MessageFromProxy, MessageToProxy},
types::{
BackendStatus, ClusterName, ClusterState, ConnectRequest, DockerExecutorConfig,
DronePoolName, KeyConfig, Mount, NodeState, SpawnConfig, Subdomain,
backend_state::BackendStatusStreamEntry, BackendStatus, ClusterName, ClusterState,
ConnectRequest, DockerExecutorConfig, DronePoolName, KeyConfig, Mount, NodeState,
SpawnConfig, Subdomain,
},
PLANE_GIT_HASH, PLANE_VERSION,
};
use chrono::Duration;
use clap::{Parser, Subcommand};
use colored::Colorize;
use futures_util::{Stream, StreamExt};

Check warning on line 15 in plane/src/admin.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `StreamExt`

warning: unused import: `StreamExt` --> plane/src/admin.rs:15:28 | 15 | use futures_util::{Stream, StreamExt}; | ^^^^^^^^^

Check warning on line 15 in plane/src/admin.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `StreamExt`

warning: unused import: `StreamExt` --> plane/src/admin.rs:15:28 | 15 | use futures_util::{Stream, StreamExt}; | ^^^^^^^^^

Check warning on line 15 in plane/src/admin.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `Stream`

warning: unused import: `Stream` --> plane/src/admin.rs:15:20 | 15 | use futures_util::{Stream, StreamExt}; | ^^^^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 15 in plane/src/admin.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `Stream`

warning: unused import: `Stream` --> plane/src/admin.rs:15:20 | 15 | use futures_util::{Stream, StreamExt}; | ^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use std::path::PathBuf;
use url::Url;

fn show_error(error: &PlaneClientError) {
Expand Down Expand Up @@ -156,6 +157,9 @@
ClusterState {
cluster: ClusterName,
},
BackendStatus {
backend: BackendName,
},
}

pub async fn run_admin_command(opts: AdminOpts) {
Expand All @@ -165,6 +169,23 @@
}
}

pub async fn print_status_stream(
paulgb marked this conversation as resolved.
Show resolved Hide resolved
mut stream: SseStream<BackendStatusStreamEntry>,
until: BackendStatus,
) {
while let Some(status) = stream.next().await {
println!(
"Status: {} at {}",
status.status.to_string().magenta(),
status.time.0.to_string().bright_cyan()
);

if status.status >= until {
break;
}
}
}

pub async fn run_admin_command_inner(opts: AdminOpts) -> Result<(), PlaneClientError> {
let client = PlaneClient::new(opts.controller);

Expand Down Expand Up @@ -227,19 +248,8 @@
}

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

while let Some(status) = stream.next().await {
println!(
"Status: {} at {}",
status.status.to_string().magenta(),
status.time.0.to_string().bright_cyan()
);

if status.status >= BackendStatus::Ready {
break;
}
}
let stream = client.backend_status_stream(&response.backend_id).await?;
print_status_stream(stream, BackendStatus::Ready).await;
}
}
AdminCommand::Terminate {
Expand All @@ -259,19 +269,8 @@
);

if !immediate {
let mut stream = client.backend_status_stream(&backend).await?;

while let Some(status) = stream.next().await {
println!(
"Status: {} at {}",
status.status.to_string().magenta(),
status.time.0.to_string().bright_cyan()
);

if status.status >= BackendStatus::Terminated {
break;
}
}
let stream = client.backend_status_stream(&backend).await?;
print_status_stream(stream, BackendStatus::Terminated).await;
}
}
AdminCommand::Drain { cluster, drone } => {
Expand Down Expand Up @@ -366,6 +365,10 @@
let cluster_state = client.cluster_state(&cluster).await?;
show_cluster_state(&cluster_state);
}
AdminCommand::BackendStatus { backend } => {
let stream = client.backend_status_stream(&backend).await?;
print_status_stream(stream, BackendStatus::Terminated).await;
}
};

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion plane/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use reqwest::{Response, StatusCode};
use serde::de::DeserializeOwned;
use url::{form_urlencoded, Url};
pub mod controller_address;
mod sse;
pub mod sse;

#[derive(thiserror::Error, Debug)]
pub enum PlaneClientError {
Expand Down
Loading