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

[next] refactor: remove ids from runtime #712

Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 1 addition & 2 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use shuttle_service::builder::{build_crate, Runtime};
use std::fmt::Write;
use strum::IntoEnumIterator;
use tar::Builder;
use tracing::trace;
use tracing::{trace, warn};
use uuid::Uuid;

use crate::args::{DeploymentCommand, ProjectCommand};
Expand Down Expand Up @@ -477,6 +477,8 @@ impl Shuttle {
let path = std::fs::canonicalize(format!("{MANIFEST_DIR}/../runtime"))
.expect("path to shuttle-runtime does not exist or is invalid");

trace!(?path, "installing runtime from local filesystem");

// TODO: Add --features next here when https://github.com/shuttle-hq/shuttle/pull/688 is merged
std::process::Command::new("cargo")
.arg("install")
Expand All @@ -494,7 +496,7 @@ impl Shuttle {
// or it isn't installed, try to install shuttle-runtime from the production
// branch.
if let Err(err) = check_version(&runtime_path) {
trace!("{}", err);
warn!("{}", err);

trace!("installing shuttle-runtime");
// TODO: Add --features next here when https://github.com/shuttle-hq/shuttle/pull/688 is merged
Expand All @@ -516,6 +518,7 @@ impl Shuttle {

runtime_path
} else {
trace!(path = ?executable_path, "using alpha runtime");
executable_path.clone()
}
};
Expand Down Expand Up @@ -580,7 +583,6 @@ impl Shuttle {
let addr = SocketAddr::new(addr, run_args.port);

let start_request = StartRequest {
deployment_id: Uuid::default().as_bytes().to_vec(),
ip: addr.to_string(),
};

Expand Down
25 changes: 5 additions & 20 deletions common/src/storage_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ pub trait StorageManager: Sync + Send {
/// Path for a specific service build files
fn service_build_path(&self, service_name: &str) -> Result<PathBuf, io::Error>;

/// Path to folder for storing deployment files
fn deployment_storage_path(
&self,
service_name: &str,
deployment_id: &Uuid,
) -> Result<PathBuf, io::Error>;
/// Path to folder for storing service files
fn service_storage_path(&self, service_name: &str) -> Result<PathBuf, io::Error>;
}

/// Manager to take care of directories for storing project, services and deployment files for deployer
Expand Down Expand Up @@ -65,15 +61,8 @@ impl StorageManager for ArtifactsStorageManager {
Ok(builds_path)
}

fn deployment_storage_path(
&self,
service_name: &str,
deployment_id: &Uuid,
) -> Result<PathBuf, io::Error> {
let storage_path = self
.storage_path()?
.join(service_name)
.join(deployment_id.to_string());
fn service_storage_path(&self, service_name: &str) -> Result<PathBuf, io::Error> {
let storage_path = self.storage_path()?.join(service_name);
fs::create_dir_all(&storage_path)?;

Ok(storage_path)
Expand All @@ -97,11 +86,7 @@ impl StorageManager for WorkingDirStorageManager {
Ok(self.working_dir.clone())
}

fn deployment_storage_path(
&self,
_service_name: &str,
_deployment_id: &Uuid,
) -> Result<PathBuf, io::Error> {
fn service_storage_path(&self, _service_name: &str) -> Result<PathBuf, io::Error> {
Ok(self.working_dir.clone())
}
}
22 changes: 2 additions & 20 deletions deployer/src/deployment/deploy_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ impl TryFrom<runtime::LogItem> for Log {

fn try_from(log: runtime::LogItem) -> Result<Self, Self::Error> {
Ok(Self {
id: Uuid::from_slice(&log.id)?,
state: runtime::LogState::from_i32(log.state)
.unwrap_or_default()
.into(),
id: Default::default(),
state: State::Running,
level: runtime::LogLevel::from_i32(log.level)
.unwrap_or_default()
.into(),
Expand All @@ -134,22 +132,6 @@ impl TryFrom<runtime::LogItem> for Log {
}
}

impl From<runtime::LogState> for State {
fn from(state: runtime::LogState) -> Self {
match state {
runtime::LogState::Queued => Self::Queued,
runtime::LogState::Building => Self::Building,
runtime::LogState::Built => Self::Built,
runtime::LogState::Loading => Self::Loading,
runtime::LogState::Running => Self::Running,
runtime::LogState::Completed => Self::Completed,
runtime::LogState::Stopped => Self::Stopped,
runtime::LogState::Crashed => Self::Crashed,
runtime::LogState::Unknown => Self::Unknown,
}
}
}

impl From<runtime::LogLevel> for LogLevel {
fn from(level: runtime::LogLevel) -> Self {
match level {
Expand Down
1 change: 0 additions & 1 deletion deployer/src/deployment/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ async fn run(
.expect("to set deployment address");

let start_request = tonic::Request::new(StartRequest {
deployment_id: id.as_bytes().to_vec(),
ip: address.to_string(),
});

Expand Down
6 changes: 4 additions & 2 deletions deployer/src/runtime_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, convert::TryInto, path::PathBuf, sync::Arc};
use std::{collections::HashMap, path::PathBuf, sync::Arc};

use anyhow::Context;
use shuttle_proto::runtime::{
Expand Down Expand Up @@ -111,7 +111,9 @@ impl RuntimeManager {

tokio::spawn(async move {
while let Ok(Some(log)) = stream.message().await {
if let Ok(log) = log.try_into() {
if let Ok(mut log) = deploy_layer::Log::try_from(log) {
log.id = id;

sender.send(log).expect("to send log to persistence");
}
}
Expand Down
1 change: 0 additions & 1 deletion proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ prost-types = { workspace = true }
tokio = { version = "1.22.0", features = ["process"] }
tonic = { workspace = true }
tracing = { workspace = true }
uuid = { workspace = true, features = ["v4"] }

[dependencies.shuttle-common]
workspace = true
Expand Down
18 changes: 1 addition & 17 deletions proto/runtime.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ message LoadResponse {
}

message StartRequest {
// Id to associate with the deployment being started
bytes deployment_id = 1;
// Address and port to start the service on
string ip = 3;
string ip = 1;
}

message StartResponse {
Expand Down Expand Up @@ -81,28 +79,14 @@ enum StopReason {
message SubscribeLogsRequest {}

message LogItem {
bytes id = 1;
google.protobuf.Timestamp timestamp = 2;
LogState state = 3;
LogLevel level = 4;
optional string file = 5;
optional uint32 line = 6;
string target = 7;
bytes fields = 8;
}

enum LogState {
Queued = 0;
Building = 1;
Built = 2;
Loading = 3;
Running = 4;
Completed = 5;
Stopped = 6;
Crashed = 7;
Unknown = 50;
}

enum LogLevel {
Trace = 0;
Debug = 1;
Expand Down
66 changes: 14 additions & 52 deletions proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ pub mod runtime {
use tokio::process;
use tonic::transport::{Channel, Endpoint};
use tracing::info;
use uuid::Uuid;

pub enum StorageManagerType {
Artifacts(PathBuf),
Expand All @@ -117,37 +116,6 @@ pub mod runtime {

tonic::include_proto!("runtime");

impl From<shuttle_common::LogItem> for LogItem {
fn from(log: shuttle_common::LogItem) -> Self {
Self {
id: log.id.into_bytes().to_vec(),
timestamp: Some(Timestamp::from(SystemTime::from(log.timestamp))),
state: LogState::from(log.state) as i32,
level: LogLevel::from(log.level) as i32,
file: log.file,
line: log.line,
target: log.target,
fields: log.fields,
}
}
}

impl From<shuttle_common::deployment::State> for LogState {
fn from(state: shuttle_common::deployment::State) -> Self {
match state {
shuttle_common::deployment::State::Queued => Self::Queued,
shuttle_common::deployment::State::Building => Self::Building,
shuttle_common::deployment::State::Built => Self::Built,
shuttle_common::deployment::State::Loading => Self::Loading,
shuttle_common::deployment::State::Running => Self::Running,
shuttle_common::deployment::State::Completed => Self::Completed,
shuttle_common::deployment::State::Stopped => Self::Stopped,
shuttle_common::deployment::State::Crashed => Self::Crashed,
shuttle_common::deployment::State::Unknown => Self::Unknown,
}
}
}

impl From<shuttle_common::log::Level> for LogLevel {
fn from(level: shuttle_common::log::Level) -> Self {
match level {
Expand All @@ -165,9 +133,9 @@ pub mod runtime {

fn try_from(log: LogItem) -> Result<Self, Self::Error> {
Ok(Self {
id: Uuid::from_slice(&log.id)?,
id: Default::default(),
timestamp: DateTime::from(SystemTime::try_from(log.timestamp.unwrap_or_default())?),
state: LogState::from_i32(log.state).unwrap_or_default().into(),
state: shuttle_common::deployment::State::Running,
level: LogLevel::from_i32(log.level).unwrap_or_default().into(),
file: log.file,
line: log.line,
Expand All @@ -177,22 +145,6 @@ pub mod runtime {
}
}

impl From<LogState> for shuttle_common::deployment::State {
fn from(state: LogState) -> Self {
match state {
LogState::Queued => Self::Queued,
LogState::Building => Self::Building,
LogState::Built => Self::Built,
LogState::Loading => Self::Loading,
LogState::Running => Self::Running,
LogState::Completed => Self::Completed,
LogState::Stopped => Self::Stopped,
LogState::Crashed => Self::Crashed,
LogState::Unknown => Self::Unknown,
}
}
}

impl From<LogLevel> for shuttle_common::log::Level {
fn from(level: LogLevel) -> Self {
match level {
Expand All @@ -216,9 +168,7 @@ pub mod runtime {
let line = if log.line == 0 { None } else { Some(log.line) };

Self {
id: Default::default(),
timestamp: Some(Timestamp::from(SystemTime::from(log.timestamp))),
state: LogState::Running as i32,
level: LogLevel::from(log.level) as i32,
file,
line,
Expand All @@ -240,6 +190,18 @@ pub mod runtime {
}
}

impl From<&tracing::Level> for LogLevel {
fn from(level: &tracing::Level) -> Self {
match *level {
tracing::Level::TRACE => Self::Trace,
tracing::Level::DEBUG => Self::Debug,
tracing::Level::INFO => Self::Info,
tracing::Level::WARN => Self::Warn,
tracing::Level::ERROR => Self::Error,
}
}
}

pub async fn start(
wasm: bool,
storage_manager_type: StorageManagerType,
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ anyhow = { workspace = true }
async-trait = { workspace = true }
chrono = { workspace = true }
clap = { workspace = true }
prost-types = { workspace = true }
serde_json = { workspace = true }
strfmt = "0.2.2"
thiserror = { workspace = true }
Expand All @@ -25,7 +26,6 @@ tonic = { workspace = true }
tower = { workspace = true }
tracing = { workspace = true, features = ["default"] }
tracing-subscriber = { workspace = true, features = ["default", "env-filter", "fmt"] }
uuid = { workspace = true, features = ["v4"] }

# TODO: bump these crates to 6.0 when we bump rust to >= 1.66
cap-std = { version = "1.0.2", optional = true }
Expand Down
Loading