diff --git a/Cargo.lock b/Cargo.lock index ba827d5..5f55ff3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -394,7 +394,6 @@ dependencies = [ "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "config 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "floating-duration 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "fly 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.17 (registry+https://github.com/rust-lang/crates.io-index)", @@ -501,11 +500,6 @@ dependencies = [ "smallvec 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "floating-duration" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "fly" version = "0.1.0" @@ -2603,7 +2597,6 @@ dependencies = [ "checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum fallible-iterator 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea79295a7a3e0d77f19e763cf1fe7189cd95fc2b36735ea0ea6b711a7380f509" -"checksum floating-duration 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2c60b71d9dbcd810a3be879dc9aafac6cec5c50dc2346e245f61f54a61fdf22" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" diff --git a/distributed-fly/Cargo.toml b/distributed-fly/Cargo.toml index 65a2319..f9e3331 100644 --- a/distributed-fly/Cargo.toml +++ b/distributed-fly/Cargo.toml @@ -29,4 +29,3 @@ config = "0.9" sha2 = "0.8" bytes = "*" prometheus = "0.4" -floating-duration = "0.1" \ No newline at end of file diff --git a/distributed-fly/src/main.rs b/distributed-fly/src/main.rs index b5bbbd9..048c66a 100644 --- a/distributed-fly/src/main.rs +++ b/distributed-fly/src/main.rs @@ -48,8 +48,6 @@ use tokio_openssl::SslAcceptorExt; #[macro_use] extern crate prometheus; -use floating_duration::TimeAsFloat; - mod cert; mod metrics; mod proxy; @@ -70,10 +68,6 @@ lazy_static! { .unwrap(); } -static CURVES: &str = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256"; - -use std::time; - fn main() { let env = Env::default().filter_or("LOG_LEVEL", "info"); env_logger::init_from_env(env); @@ -133,7 +127,6 @@ fn main() { openssl::ssl::select_next_proto(b"\x02h2\x08http/1.1", client) .ok_or(openssl::ssl::AlpnError::NOACK) }); - tls_builder.set_cipher_list(CURVES).unwrap(); let certs_path = { match GLOBAL_SETTINGS.read().unwrap().certs_path { @@ -175,12 +168,12 @@ fn main() { .map_err(|e| error!("error in stream: {}", e)) .for_each(move |stream| { let remote_addr = stream.peer_addr().unwrap(); - let start = time::Instant::now(); + let timer = TLS_HANDSHAKE_TIME_HISTOGRAM.start_timer(); tls_acceptor .accept_async(stream) .map_err(|e| error!("error handshake conn: {}", e)) .and_then(move |stream| { - TLS_HANDSHAKE_TIME_HISTOGRAM.observe(start.elapsed().as_fractional_secs()); + timer.observe_duration(); let h = hyper::server::conn::Http::new(); h.serve_connection( stream, diff --git a/distributed-fly/src/runtime_selector.rs b/distributed-fly/src/runtime_selector.rs index 86100b1..5e1c03a 100644 --- a/distributed-fly/src/runtime_selector.rs +++ b/distributed-fly/src/runtime_selector.rs @@ -75,9 +75,9 @@ impl RuntimeSelector for DistributedRuntimeSelector { })), } }; - let mut rt = Runtime::new(Some(rel.app.clone()), &settings); + let mut rt = Runtime::new(Some(rel.app_id.to_string()), Some(rel.version.to_string()), &settings); let merged_conf = rel.clone().parsed_config().unwrap(); - rt.eval( + rt.eval( "", &format!("window.app = {{ config: {} }};", merged_conf), ); diff --git a/src/bin/dns/main.rs b/src/bin/dns/main.rs index bb57814..5e94184 100644 --- a/src/bin/dns/main.rs +++ b/src/bin/dns/main.rs @@ -50,7 +50,7 @@ fn main() { .get_matches(); let entry_file = matches.value_of("input").unwrap(); - let mut runtime = Runtime::new(None, &SETTINGS.read().unwrap()); + let mut runtime = Runtime::new(None, None, &SETTINGS.read().unwrap()); debug!("Loading dev tools"); runtime.eval_file("v8env/dist/dev-tools.js"); diff --git a/src/bin/eval/main.rs b/src/bin/eval/main.rs index e4b0d53..0b216d4 100644 --- a/src/bin/eval/main.rs +++ b/src/bin/eval/main.rs @@ -29,7 +29,7 @@ fn main() { .index(1), ).get_matches(); - let mut runtime = Runtime::new(None, &SETTINGS.read().unwrap()); + let mut runtime = Runtime::new(None, None, &SETTINGS.read().unwrap()); debug!("Loading dev tools"); runtime.eval_file("v8env/dist/dev-tools.js"); runtime.eval("", "installDevTools();"); diff --git a/src/bin/http/main.rs b/src/bin/http/main.rs index 0f4d8ed..15edce1 100644 --- a/src/bin/http/main.rs +++ b/src/bin/http/main.rs @@ -59,7 +59,7 @@ fn main() { info!("V8 version: {}", libfly::version()); let entry_file = matches.value_of("input").unwrap(); - let mut runtime = Runtime::new(None, &SETTINGS.read().unwrap()); + let mut runtime = Runtime::new(None, None, &SETTINGS.read().unwrap()); debug!("Loading dev tools"); runtime.eval_file("v8env/dist/dev-tools.js"); diff --git a/src/bin/test/main.rs b/src/bin/test/main.rs index 02038be..3904ff9 100644 --- a/src/bin/test/main.rs +++ b/src/bin/test/main.rs @@ -34,7 +34,7 @@ fn main() { let env = Env::default().filter_or("LOG_LEVEL", "info"); env_logger::init_from_env(env); - let mut rt = Runtime::new(None, &SETTINGS.read().unwrap()); + let mut rt = Runtime::new(None, None, &SETTINGS.read().unwrap()); rt.eval("mocha.js", str::from_utf8(MOCHA_SOURCE).unwrap()); rt.eval("chai.js", str::from_utf8(CHAI_SOURCE).unwrap()); rt.eval("testing.js", str::from_utf8(FLY_TESTING_SOURCE).unwrap()); diff --git a/src/http_server.rs b/src/http_server.rs index 9db4b7d..9e48abf 100644 --- a/src/http_server.rs +++ b/src/http_server.rs @@ -94,7 +94,7 @@ pub fn serve_http( .status(StatusCode::SERVICE_UNAVAILABLE) .body(Body::empty()) .unwrap(), - Some(rt.name.clone()), + Some((rt.name.clone(), rt.version.clone())), ); } @@ -138,7 +138,7 @@ pub fn serve_http( .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::empty()) .unwrap(), - Some(rt.name.clone()), + Some((rt.name.clone(), rt.version.clone())), ); } @@ -166,7 +166,7 @@ pub fn serve_http( Ok(Response::from_parts(parts, body)) }), - Some(rt.name.clone()), + Some((rt.name.clone(), rt.version.clone())), ) } else { future_response( @@ -174,23 +174,23 @@ pub fn serve_http( .status(StatusCode::SERVICE_UNAVAILABLE) .body(Body::empty()) .unwrap(), - Some(rt.name.clone()), + Some((rt.name.clone(), rt.version.clone())), ) } } -fn future_response(res: Response, name: Option) -> BoxedResponseFuture { - wrap_future(future::ok(res), name) +fn future_response(res: Response, namever: Option<(String, String)>) -> BoxedResponseFuture { + wrap_future(future::ok(res), namever) } -fn wrap_future(fut: F, maybe_name: Option) -> BoxedResponseFuture +fn wrap_future(fut: F, namever: Option<(String, String)>) -> BoxedResponseFuture where F: Future, Error = futures::Canceled> + Send + 'static, { Box::new(fut.and_then(move |res| { - let rt_name = maybe_name.unwrap_or(String::new()); + let (name, ver) = namever.unwrap_or((String::new(), String::new())); metrics::HTTP_RESPONSE_COUNTER - .with_label_values(&[rt_name.as_str(), res.status().as_str()]) + .with_label_values(&[name.as_str(), ver.as_str(), res.status().as_str()]) .inc(); Ok(res) })) diff --git a/src/metrics.rs b/src/metrics.rs index 875a108..e3ed7c2 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -31,13 +31,13 @@ lazy_static! { pub static ref HTTP_RESPONSE_COUNTER: IntCounterVec = register_int_counter_vec!( "fly_http_responses_total", "Total number of HTTP responses made.", - &["runtime", "status"] + &["runtime", "version", "status"] ) .unwrap(); pub static ref HTTP_RESPONSE_TIME_HISTOGRAM: HistogramVec = register_histogram_vec!( "fly_http_response_time_histogram_seconds", "HTTP response times by runtime, in seconds.", - &["runtime"], + &["runtime", "version"], vec![0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 1.0, 5.0, 10.0, 60.0] ) .unwrap(); diff --git a/src/runtime.rs b/src/runtime.rs index 845906b..20a15aa 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -136,6 +136,7 @@ impl JsRuntime { pub struct Runtime { pub ptr: JsRuntime, pub name: String, + pub version: String, pub event_loop: Mutex, timers: Mutex>>, pub responses: Mutex>>, @@ -197,7 +198,7 @@ fn init_event_loop() -> ( } impl Runtime { - pub fn new(name: Option, settings: &Settings) -> Box { + pub fn new(name: Option, version: Option, settings: &Settings) -> Box { JSINIT.call_once(|| unsafe { js_init() }); let (rthandle, txready, rxquit) = init_event_loop(); @@ -205,6 +206,7 @@ impl Runtime { let mut rt = Box::new(Runtime { ptr: JsRuntime(ptr::null() as *const js_runtime), name: name.unwrap_or("v8".to_string()), + version: version.unwrap_or(String::new()), event_loop: Mutex::new(rthandle.clone()), ready_ch: Some(txready), quit_ch: Some(rxquit), diff --git a/v8env/package.json b/v8env/package.json index c434169..11935ad 100644 --- a/v8env/package.json +++ b/v8env/package.json @@ -41,6 +41,7 @@ "@types/expect": "^1.20.3", "@types/flatbuffers": "^1.9.0", "@types/mocha": "^5.2.5", + "@types/pako": "^1.0.0", "@types/query-string": "^6.1.0", "@types/source-map-support": "^0.4.1", "@types/text-encoding": "0.0.33", @@ -48,6 +49,7 @@ "chai": "^4.2.0", "expect": "^23.6.0", "mocha": "^5.2.0", + "pako": "^1.0.7", "rollup": "^0.65.0", "rollup-plugin-commonjs": "^9.1.6", "rollup-plugin-node-builtins": "^2.1.2", diff --git a/v8env/yarn.lock b/v8env/yarn.lock index aa7696d..117f28a 100644 --- a/v8env/yarn.lock +++ b/v8env/yarn.lock @@ -58,6 +58,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-10.11.5.tgz#6489ebda4452592d3fd37aefa57eedc01ed13378" integrity sha512-3j1EFLfrjYRHRFjBb+RIXXwr1YGzcfpQVMP39thZa6tMY+JjVgQddPF+hsdV800JqbuLwpwAWclDpbGSAw44vQ== +"@types/pako@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/pako/-/pako-1.0.0.tgz#eaae8364d1b7f752e263bc3fd68dfec98e6136c5" + integrity sha1-6q6DZNG391LiY7w/1o3+yY5hNsU= + "@types/query-string@^6.1.0": version "6.1.0" resolved "https://registry.yarnpkg.com/@types/query-string/-/query-string-6.1.0.tgz#5f721f9503bdf517d474c66cf4423da5dd2d5698" @@ -1173,6 +1178,11 @@ once@^1.3.0: dependencies: wrappy "1" +pako@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.7.tgz#2473439021b57f1516c82f58be7275ad8ef1bb27" + integrity sha512-3HNK5tW4x8o5mO8RuHZp3Ydw9icZXx0RANAOMzlMzx7LVXhMJ4mo3MOBpzyd7r/+RUu8BmndP47LXT+vzjtWcQ== + parse-asn1@^5.0.0: version "5.1.1" resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.1.tgz#f6bf293818332bd0dab54efb16087724745e6ca8"