Skip to content

Commit

Permalink
feat: send task logs to spaces (#6419)
Browse files Browse the repository at this point in the history
### Description

Start sending task summaries to spaces. As expected this ended up
touching a few parts of the codebase and required some reworking of
them.

I highly recommend reviewing each commit in the PR individually as I
attempted to keep each one fairly small to make this easier to review.

### Testing Instructions

Observe the runs sent via the Rust codepath from my machine (you can
tell it's Rust based on the `command` 😉 )
- [Cache
miss](https://vercel.com/teams/vercel/repos/turbo-monorepo/runs/space_run_59Yj2WWotw4oFnHMAEKWb5JZ)
- [Cache
hit](https://vercel.com/teams/vercel/repos/turbo-monorepo/runs/space_run_kO8iZcJPGkXoQ127qGGcOQXz)


Closes TURBO-1632

---------

Co-authored-by: Chris Olszewski <Chris Olszewski>
  • Loading branch information
chris-olszewski authored Nov 13, 2023
1 parent 0f3496b commit 03bb020
Show file tree
Hide file tree
Showing 7 changed files with 436 additions and 198 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/turborepo-api-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ rustls-tls = ["reqwest/rustls-tls"]

[dev-dependencies]
port_scanner = { workspace = true }
serde_json = { workspace = true }
test-case = { workspace = true }
turborepo-vercel-api-mock = { workspace = true }

[dependencies]
Expand Down
78 changes: 73 additions & 5 deletions crates/turborepo-api-client/src/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,31 @@ pub struct SpaceClientSummary {
pub version: String,
}

#[derive(Default, Debug, Serialize)]
#[derive(Debug, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct SpacesCacheStatus {
pub status: String,
pub source: Option<String>,
pub time_saved: u32,
pub status: CacheStatus,
#[serde(skip_serializing_if = "Option::is_none")]
pub source: Option<CacheSource>,
pub time_saved: u64,
}

#[derive(Debug, Serialize, Copy, Clone)]
#[serde(rename_all = "UPPERCASE")]
pub enum CacheStatus {
Hit,
Miss,
}

#[derive(Debug, Serialize, Copy, Clone)]
#[serde(rename_all = "UPPERCASE")]
pub enum CacheSource {
Local,
Remote,
}

#[derive(Default, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SpaceTaskSummary {
pub key: String,
pub name: String,
Expand All @@ -36,9 +53,10 @@ pub struct SpaceTaskSummary {
pub start_time: i64,
pub end_time: i64,
pub cache: SpacesCacheStatus,
pub exit_code: u32,
pub exit_code: Option<i32>,
pub dependencies: Vec<String>,
pub dependents: Vec<String>,
#[serde(rename = "log")]
pub logs: String,
}

Expand Down Expand Up @@ -187,3 +205,53 @@ impl APIClient {
Ok(())
}
}

impl Default for CacheStatus {
fn default() -> Self {
Self::Miss
}
}

#[cfg(test)]
mod test {
use serde_json::json;
use test_case::test_case;

use super::*;

#[test_case(CacheStatus::Hit, json!("HIT") ; "hit")]
#[test_case(CacheStatus::Miss, json!("MISS") ; "miss")]
#[test_case(CacheSource::Local, json!("LOCAL") ; "local")]
#[test_case(CacheSource::Remote, json!("REMOTE") ; "remote")]
#[test_case(SpacesCacheStatus {
source: None,
status: CacheStatus::Miss,
time_saved: 0,
},
json!({ "status": "MISS", "timeSaved": 0 })
; "cache miss")]
#[test_case(SpaceTaskSummary{
key: "foo#build".into(),
exit_code: Some(0),
..Default::default()},
json!({
"key": "foo#build",
"name": "",
"workspace": "",
"hash": "",
"startTime": 0,
"endTime": 0,
"cache": {
"timeSaved": 0,
"status": "MISS"
},
"exitCode": 0,
"dependencies": [],
"dependents": [],
"log": "",
})
; "spaces task summary")]
fn test_serialization(value: impl serde::Serialize, expected: serde_json::Value) {
assert_eq!(serde_json::to_value(value).unwrap(), expected);
}
}
Loading

0 comments on commit 03bb020

Please sign in to comment.