Skip to content

Commit

Permalink
feat(runtime): version endpoint for runner version check
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaro00 committed Apr 24, 2024
1 parent a0e1bf1 commit 3757bfe
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
5 changes: 5 additions & 0 deletions proto/runtime.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ service Runtime {
// Channel to notify a service has been stopped
rpc SubscribeStop(SubscribeStopRequest) returns (stream SubscribeStopResponse);

rpc Version(Ping) returns (VersionInfo);
rpc HealthCheck(Ping) returns (Pong);
}

Expand Down Expand Up @@ -83,3 +84,7 @@ enum StopReason {

message Ping {}
message Pong {}

message VersionInfo {
string version = 1;
}
62 changes: 62 additions & 0 deletions proto/src/generated/runtime.rs

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

19 changes: 10 additions & 9 deletions runtime/src/alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ use anyhow::Context;
use async_trait::async_trait;
use core::future::Future;
use shuttle_common::{extract_propagation::ExtractPropagationLayer, secrets::Secret};
use shuttle_proto::{
runtime::{
runtime_server::{Runtime, RuntimeServer},
LoadRequest, LoadResponse, StartRequest, StartResponse, StopReason, StopRequest,
StopResponse, SubscribeStopRequest, SubscribeStopResponse,
},
runtime::{Ping, Pong},
use shuttle_proto::runtime::{
runtime_server::{Runtime, RuntimeServer},
LoadRequest, LoadResponse, Ping, Pong, StartRequest, StartResponse, StopReason, StopRequest,
StopResponse, SubscribeStopRequest, SubscribeStopResponse, VersionInfo,
};
use shuttle_service::{ResourceFactory, Service};
use tokio::sync::{
Expand All @@ -29,7 +26,7 @@ use tokio_stream::wrappers::ReceiverStream;
use tokio_util::sync::CancellationToken;
use tonic::{transport::Server, Request, Response, Status};

use crate::print_version;
use crate::version;

#[derive(Default)]
struct Args {
Expand Down Expand Up @@ -89,7 +86,7 @@ impl Args {
pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + Send + 'static) {
// `--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();
println!("{}", version());
return;
}

Expand Down Expand Up @@ -502,6 +499,10 @@ where
Ok(Response::new(ReceiverStream::new(rx)))
}

async fn version(&self, _requset: Request<Ping>) -> Result<Response<VersionInfo>, Status> {
Ok(Response::new(VersionInfo { version: version() }))
}

async fn health_check(&self, _request: Request<Ping>) -> Result<Response<Pong>, Status> {
if matches!(self.state.lock().unwrap().deref(), State::Unhealthy) {
println!("runtime health check failed");
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ mod alpha;

const NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");
fn print_version() {
println!("{} {}", crate::NAME, crate::VERSION);
fn version() -> String {
format!("{} {}", crate::NAME, crate::VERSION)
}

// Not part of public API
Expand Down

0 comments on commit 3757bfe

Please sign in to comment.