Skip to content

Commit 90e2ced

Browse files
committed
Migrate crate reporting to the orchestrator
Goodbye, sandbox.
1 parent c5eadf7 commit 90e2ced

File tree

8 files changed

+113
-327
lines changed

8 files changed

+113
-327
lines changed

compiler/base/orchestrator/Cargo.lock

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/base/orchestrator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ bincode = { version = "1.3", default-features = false }
1212
futures = { version = "0.3.28", default-features = false, features = ["executor"] }
1313
modify-cargo-toml = { path = "../modify-cargo-toml", default-features = false }
1414
serde = { version = "1.0", default-features = false, features = ["derive"] }
15+
serde_json = { version = "1.0.108", default-features = false, features = ["std"] }
1516
snafu = { version = "0.7.4", default-features = false, features = ["futures", "std"] }
1617
tokio = { version = "1.28", default-features = false, features = ["fs", "io-std", "io-util", "macros", "process", "rt", "time", "sync"] }
1718
tokio-stream = { version = "0.1.14", default-features = false }

compiler/base/orchestrator/src/coordinator.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use futures::{
22
future::{BoxFuture, OptionFuture},
33
Future, FutureExt,
44
};
5+
use serde::Deserialize;
56
use snafu::prelude::*;
67
use std::{
78
collections::HashMap,
@@ -163,6 +164,48 @@ pub enum VersionError {
163164
TaskPanic { source: tokio::task::JoinError },
164165
}
165166

167+
#[derive(Debug, Clone)]
168+
pub struct Crate {
169+
pub name: String,
170+
pub version: String,
171+
pub id: String,
172+
}
173+
174+
#[derive(Deserialize)]
175+
struct InternalCrate {
176+
name: String,
177+
version: String,
178+
id: String,
179+
}
180+
181+
impl From<InternalCrate> for Crate {
182+
fn from(other: InternalCrate) -> Self {
183+
let InternalCrate { name, version, id } = other;
184+
Self { name, version, id }
185+
}
186+
}
187+
188+
#[derive(Debug, Snafu)]
189+
pub enum CratesError {
190+
#[snafu(display("Could not start the container"))]
191+
#[snafu(context(false))]
192+
Start { source: Error },
193+
194+
#[snafu(context(false))] // transparent
195+
Container { source: ContainerCratesError },
196+
}
197+
198+
#[derive(Debug, Snafu)]
199+
pub enum ContainerCratesError {
200+
#[snafu(display("Could not read the crate information file"))]
201+
#[snafu(context(false))]
202+
Read { source: CommanderError },
203+
204+
#[snafu(display("Could not parse the crate information file"))]
205+
#[snafu(context(false))]
206+
Deserialization { source: serde_json::Error },
207+
}
208+
166209
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
167210
pub enum AssemblyFlavor {
168211
Att,
@@ -789,6 +832,14 @@ where
789832
})
790833
}
791834

835+
pub async fn crates(&self) -> Result<Vec<Crate>, CratesError> {
836+
self.select_channel(Channel::Stable)
837+
.await?
838+
.crates()
839+
.await
840+
.map_err(Into::into)
841+
}
842+
792843
pub async fn execute(
793844
&self,
794845
request: ExecuteRequest,
@@ -1120,6 +1171,15 @@ impl Container {
11201171
Ok(if o.success { Some(o.stdout) } else { None })
11211172
}
11221173

1174+
async fn crates(&self) -> Result<Vec<Crate>, ContainerCratesError> {
1175+
let read = ReadFileRequest {
1176+
path: "crate-information.json".into(),
1177+
};
1178+
let read = self.commander.one(read).await?;
1179+
let crates = serde_json::from_slice::<Vec<InternalCrate>>(&read.0)?;
1180+
Ok(crates.into_iter().map(Into::into).collect())
1181+
}
1182+
11231183
async fn execute(
11241184
&self,
11251185
request: ExecuteRequest,

ui/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/src/main.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ impl MetricsToken {
162162

163163
#[derive(Debug, Snafu)]
164164
enum Error {
165-
#[snafu(display("Sandbox creation failed: {}", source))]
166-
SandboxCreation { source: sandbox::Error },
167-
#[snafu(display("Caching operation failed: {}", source))]
168-
Caching { source: sandbox::Error },
169165
#[snafu(display("Gist creation failed: {}", source))]
170166
GistCreation { source: octocrab::Error },
171167
#[snafu(display("Gist loading failed: {}", source))]
@@ -219,6 +215,11 @@ enum Error {
219215
#[snafu(display("The WebSocket worker panicked: {}", text))]
220216
WebSocketTaskPanic { text: String },
221217

218+
#[snafu(display("Unable to find the available crates"))]
219+
Crates {
220+
source: orchestrator::coordinator::CratesError,
221+
},
222+
222223
#[snafu(display("Unable to find the available versions"))]
223224
Versions {
224225
source: orchestrator::coordinator::VersionsError,
@@ -464,21 +465,6 @@ struct EvaluateResponse {
464465
error: Option<String>,
465466
}
466467

467-
impl From<Vec<sandbox::CrateInformation>> for MetaCratesResponse {
468-
fn from(me: Vec<sandbox::CrateInformation>) -> Self {
469-
let crates = me
470-
.into_iter()
471-
.map(|cv| CrateInformation {
472-
name: cv.name,
473-
version: cv.version,
474-
id: cv.id,
475-
})
476-
.collect();
477-
478-
MetaCratesResponse { crates }
479-
}
480-
}
481-
482468
impl From<gist::Gist> for MetaGistResponse {
483469
fn from(me: gist::Gist) -> Self {
484470
MetaGistResponse {

ui/src/metrics.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use std::{
1010
time::{Duration, Instant},
1111
};
1212

13-
use crate::sandbox;
14-
1513
lazy_static! {
1614
pub(crate) static ref REQUESTS: HistogramVec = register_histogram_vec!(
1715
"playground_request_duration_seconds",
@@ -204,29 +202,6 @@ impl Labels {
204202
}
205203
}
206204

207-
pub(crate) trait GenerateLabels {
208-
fn generate_labels(&self, outcome: Outcome) -> Labels;
209-
}
210-
211-
impl<T> GenerateLabels for &'_ T
212-
where
213-
T: GenerateLabels,
214-
{
215-
fn generate_labels(&self, outcome: Outcome) -> Labels {
216-
T::generate_labels(self, outcome)
217-
}
218-
}
219-
220-
pub(crate) trait SuccessDetails: Sized {
221-
fn success_details(&self) -> Outcome;
222-
}
223-
224-
impl SuccessDetails for Vec<sandbox::CrateInformation> {
225-
fn success_details(&self) -> Outcome {
226-
Outcome::Success
227-
}
228-
}
229-
230205
pub(crate) async fn track_metric_no_request_async<B, Fut, Resp>(
231206
endpoint: Endpoint,
232207
body: B,

0 commit comments

Comments
 (0)