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

chore: merge shuttle-ecs-common to main #1753

Merged
merged 30 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f60106c
common: add control backend type
iulianbarbu Mar 26, 2024
222b613
backends: reinstate http otel exporter
iulianbarbu Mar 26, 2024
01b69a2
Merge remote-tracking branch 'upstream/main' into feat/shuttle-ecs-co…
oddgrd Apr 2, 2024
e40002b
feat: merge runtime updates in main ecs branch (#1709)
oddgrd Apr 2, 2024
45e5d4e
feat: add resource request struct to backends (#1718)
oddgrd Apr 5, 2024
f732be0
Merge branch 'main' into feat/shuttle-ecs-common
jonaro00 Apr 10, 2024
72839f0
feat(cargo-shuttle): beta flag, remove project list pagination logic …
jonaro00 Apr 11, 2024
d09d803
feat: add models and header for new ecs provisioner (#1730)
oddgrd Apr 11, 2024
2286c04
fix: runtime panic (#1735)
oddgrd Apr 11, 2024
cd7b71c
fix(cargo-shuttle): deploy http method
jonaro00 Apr 11, 2024
d3f6c6b
cargo-shuttle: update deploy cmd for beta platform (#1734)
iulianbarbu Apr 16, 2024
ae3c5b0
feat: add services client constructor for default headers (#1737)
oddgrd Apr 16, 2024
81ecaae
feat(cargo-shuttle): beta deploy zip file, package name (#1742)
jonaro00 Apr 17, 2024
6231811
cargo-shuttle: added beta deployment status (#1740)
iulianbarbu Apr 18, 2024
8767db4
Add log streaming in beta platform (#1743)
Kazy Apr 18, 2024
82876bd
feat(cargo-shuttle beta): enable resource list (#1744)
oddgrd Apr 19, 2024
a44d095
cargo-shuttle: added beta deployment list (#1741)
iulianbarbu Apr 19, 2024
fe9f49c
feat(c-s beta): enable resource delete (#1745)
oddgrd Apr 19, 2024
b84ea8f
feat: support secrets on beta platform (#1748)
oddgrd Apr 23, 2024
90bd111
feat(common): add building EcsState (#1752)
Kazy Apr 23, 2024
ceed492
Merge remote-tracking branch 'upstream/main' into feat/shuttle-ecs-co…
jonaro00 Apr 23, 2024
f1f4b4e
feat(cargo-shuttle): nits
jonaro00 Apr 23, 2024
b52786b
fix(cargo-shuttle): skip org project listing on beta
jonaro00 Apr 23, 2024
85a8d54
fix(backends): switch to http otel collector for compatibility with beta
jonaro00 Apr 23, 2024
3fc73ea
fix(runtime): make compatible with alpha & beta
jonaro00 Apr 23, 2024
a45addb
fix: make services compatible with beta runtime
jonaro00 Apr 23, 2024
a0e1bf1
Merge remote-tracking branch 'upstream/main' into feat/shuttle-ecs-co…
jonaro00 Apr 23, 2024
3757bfe
feat(runtime): version endpoint for runner version check
jonaro00 Apr 24, 2024
cd2c7a8
fix: review comments on ecs-common
jonaro00 Apr 24, 2024
95c155b
nit: update timeout comment
jonaro00 Apr 24, 2024
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
102 changes: 78 additions & 24 deletions runtime/src/alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,65 @@ use tokio_stream::wrappers::ReceiverStream;
use tokio_util::sync::CancellationToken;
use tonic::{transport::Server, Request, Response, Status};

use crate::args::args;
use crate::print_version;

// uses custom macro instead of clap to reduce dependency weight
args! {
pub struct Args {
// The port to open the gRPC control layer on.
// The address to expose for the service is given in the StartRequest.
"--port" => pub port: u16,
#[derive(Default)]
struct Args {
/// Enable compatibility with beta platform
beta: bool,
/// Alpha (required): Port to open gRPC server on
port: Option<u16>,
/// Beta (required): Address to bind the gRPC server to
address: Option<SocketAddr>,
}

impl Args {
// uses simple arg parsing logic instead of clap to reduce dependency weight
fn parse() -> anyhow::Result<Self> {
let mut args = Self::default();

// The first argument is the path of the executable
let mut args_iter = std::env::args().skip(1);

while let Some(arg) = args_iter.next() {
match arg.as_str() {
"--beta" => {
args.beta = true;
}
"--port" => {
let port = args_iter
.next()
.context("missing port value")?
.parse()
.context("invalid port value")?;
args.port = Some(port);
}
"--address" => {
let address = args_iter
.next()
.context("missing address value")?
.parse()
.context("invalid address value")?;
args.address = Some(address);
}
_ => {}
oddgrd marked this conversation as resolved.
Show resolved Hide resolved
}
}

if args.beta {
if args.address.is_none() {
return Err(anyhow::anyhow!("--address is required with --beta"));
}
} else if args.port.is_none() {
return Err(anyhow::anyhow!("--port is required"));
}

Ok(args)
}
}

pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + Send + 'static) {
// `--version` overrides any other arguments.
// `--version` overrides any other arguments. Used by cargo-shuttle to check compatibility on local runs.
if std::env::args().any(|arg| arg == "--version") {
print_version();
return;
Expand Down Expand Up @@ -88,7 +133,11 @@ pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + S
}

// where to serve the gRPC control layer
let addr = SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), args.port);
let addr = if args.beta {
args.address.unwrap()
} else {
SocketAddr::new(Ipv4Addr::LOCALHOST.into(), args.port.unwrap())
};

let mut server_builder = Server::builder()
.http2_keepalive_interval(Some(Duration::from_secs(60)))
Expand All @@ -99,7 +148,7 @@ pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + S
let cloned_token = token.clone();

let router = {
let alpha = Alpha::new(loader, runner, token);
let alpha = Alpha::new(args.beta, loader, runner, token);

let svc = RuntimeServer::new(alpha);
server_builder.add_service(svc)
Expand All @@ -125,6 +174,8 @@ pub enum State {
}

pub struct Alpha<L, R> {
/// alter behaviour to interact with the new platform
beta: bool,
// Mutexes are for interior mutability
stopped_tx: Sender<(StopReason, String)>,
kill_tx: Mutex<Option<oneshot::Sender<String>>>,
Expand All @@ -138,10 +189,11 @@ pub struct Alpha<L, R> {
}

impl<L, R> Alpha<L, R> {
pub fn new(loader: L, runner: R, cancellation_token: CancellationToken) -> Self {
pub fn new(beta: bool, loader: L, runner: R, cancellation_token: CancellationToken) -> Self {
let (stopped_tx, _stopped_rx) = broadcast::channel(10);

Self {
beta,
stopped_tx,
kill_tx: Mutex::new(None),
loader: Mutex::new(Some(loader)),
Expand Down Expand Up @@ -251,24 +303,26 @@ where
}
};

println!("setting current state to healthy");
*self.state.lock().unwrap() = State::Loading;

let state = self.state.clone();
let cancellation_token = self.cancellation_token.clone();

// Ensure that the runtime is set to unhealthy if it doesn't reach the running state after
// it has sent a load response, so that the ECS task will fail.
tokio::spawn(async move {
// Note: The timeout is quite low as we are not actually provisioning resources after
// sending the load response.
tokio::time::sleep(Duration::from_secs(180)).await;
if !matches!(state.lock().unwrap().deref(), State::Running) {
println!("the runtime failed to enter the running state before timing out");

cancellation_token.cancel();
}
});
// State and cancellation is not used in alpha
if self.beta {
// Ensure that the runtime is set to unhealthy if it doesn't reach the running state after
// it has sent a load response, so that the ECS task will fail.
tokio::spawn(async move {
// Note: The timeout is quite low as we are not actually provisioning resources after
// sending the load response.
jonaro00 marked this conversation as resolved.
Show resolved Hide resolved
tokio::time::sleep(Duration::from_secs(180)).await;
if !matches!(state.lock().unwrap().deref(), State::Running) {
println!("the runtime failed to enter the running state before timing out");

cancellation_token.cancel();
}
});
}

Ok(Response::new(LoadResponse {
success: true,
Expand Down
80 changes: 0 additions & 80 deletions runtime/src/args.rs

This file was deleted.

1 change: 0 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub use async_trait::async_trait;
pub use tokio;

mod alpha;
mod args;

const NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down