-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'awick/get-vcpu-ms' into awick/testing-ci
- Loading branch information
Showing
21 changed files
with
280 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ mod upstream; | |
mod upstream_async; | ||
mod upstream_dynamic; | ||
mod upstream_streaming; | ||
mod vcpu_time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::{ | ||
common::{Test, TestResult}, | ||
viceroy_test, | ||
}; | ||
use hyper::{Request, Response, StatusCode}; | ||
|
||
viceroy_test!(vcpu_time_getter_works, |is_component| { | ||
let req = Request::get("/") | ||
.header("Accept", "text/html") | ||
.body("Hello, world!") | ||
.unwrap(); | ||
|
||
let resp = Test::using_fixture("vcpu_time_test.wasm") | ||
.adapt_component(is_component) | ||
.backend("slow-server", "/", None, |_| { | ||
std::thread::sleep(std::time::Duration::from_millis(3000)); | ||
Response::builder() | ||
.status(StatusCode::OK) | ||
.body(vec![]) | ||
.unwrap() | ||
}) | ||
.await | ||
.against(req) | ||
.await?; | ||
|
||
println!("resp.status() = {}", resp.status()); | ||
assert_eq!(resp.status(), StatusCode::OK); | ||
Ok(()) | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,3 +358,4 @@ | |
(typename $has u32) | ||
|
||
(typename $body_length u64) | ||
(typename $vcpu_ms u64) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use super::fastly::api::{types, compute_runtime}; | ||
use crate::session::Session; | ||
use std::sync::atomic::Ordering; | ||
|
||
#[async_trait::async_trait] | ||
impl compute_runtime::Host for Session { | ||
async fn get_vcpu_ms(&mut self) -> Result<u64, types::Error> { | ||
Ok(self.active_cpu_time_us.load(Ordering::SeqCst) / 1000) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use crate::error::Error; | ||
use crate::session::Session; | ||
use crate::wiggle_abi::fastly_compute_runtime::FastlyComputeRuntime; | ||
use std::sync::atomic::Ordering; | ||
use wiggle::GuestMemory; | ||
|
||
impl FastlyComputeRuntime for Session { | ||
fn get_vcpu_ms(&mut self, _memory: &mut GuestMemory<'_>) -> Result<u64, Error> { | ||
// we internally track microseconds, because our wasmtime tick length | ||
// is too short for ms to work. but we want to shrink this to ms to | ||
// try to minimize timing attacks. | ||
Ok(self.active_cpu_time_us.load(Ordering::SeqCst) / 1000) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.