From 0ccc5f678a8dc136d967d209901ae3f44962028a Mon Sep 17 00:00:00 2001 From: Lukas Piatkowski Date: Fri, 14 Feb 2020 01:24:14 -0800 Subject: [PATCH] mononoke: move facebook/scuba_ext to common/scuba_ext Summary: common/sql_ext will now be buildable in OSS Reviewed By: krallin Differential Revision: D19876764 fbshipit-source-id: 0f51abd1169f6b8108e7e4cab85b5f193c28e2cd --- eden/mononoke/Cargo.toml | 1 + .../common/bounded_traversal/src/common.rs | 3 +- .../common/bounded_traversal/src/dag.rs | 3 +- .../common/bounded_traversal/src/lib.rs | 3 +- .../common/bounded_traversal/src/stream.rs | 3 +- .../common/bounded_traversal/src/tests.rs | 3 +- .../common/bounded_traversal/src/tree.rs | 3 +- eden/mononoke/common/scuba_ext/Cargo.toml | 18 ++++ eden/mononoke/common/scuba_ext/src/lib.rs | 87 +++++++++++++++++++ eden/mononoke/edenapi_server/src/router.rs | 3 +- 10 files changed, 113 insertions(+), 14 deletions(-) create mode 100644 eden/mononoke/common/scuba_ext/Cargo.toml create mode 100644 eden/mononoke/common/scuba_ext/src/lib.rs diff --git a/eden/mononoke/Cargo.toml b/eden/mononoke/Cargo.toml index ac91087f81..17b67d71df 100644 --- a/eden/mononoke/Cargo.toml +++ b/eden/mononoke/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ + "common/scuba_ext", "server/session_id", "sshrelay", ] diff --git a/eden/mononoke/common/bounded_traversal/src/common.rs b/eden/mononoke/common/bounded_traversal/src/common.rs index 094aaccde6..fa28ee6524 100644 --- a/eden/mononoke/common/bounded_traversal/src/common.rs +++ b/eden/mononoke/common/bounded_traversal/src/common.rs @@ -2,8 +2,7 @@ * Copyright (c) Facebook, Inc. and its affiliates. * * This software may be used and distributed according to the terms of the - * GNU General Public License found in the LICENSE file in the root - * directory of this source tree. + * GNU General Public License version 2. */ use futures::ready; diff --git a/eden/mononoke/common/bounded_traversal/src/dag.rs b/eden/mononoke/common/bounded_traversal/src/dag.rs index 9d932086b3..50848eda5e 100644 --- a/eden/mononoke/common/bounded_traversal/src/dag.rs +++ b/eden/mononoke/common/bounded_traversal/src/dag.rs @@ -2,8 +2,7 @@ * Copyright (c) Facebook, Inc. and its affiliates. * * This software may be used and distributed according to the terms of the - * GNU General Public License found in the LICENSE file in the root - * directory of this source tree. + * GNU General Public License version 2. */ use super::{ diff --git a/eden/mononoke/common/bounded_traversal/src/lib.rs b/eden/mononoke/common/bounded_traversal/src/lib.rs index d8ddd5a4e3..cfdde0e918 100644 --- a/eden/mononoke/common/bounded_traversal/src/lib.rs +++ b/eden/mononoke/common/bounded_traversal/src/lib.rs @@ -2,8 +2,7 @@ * Copyright (c) Facebook, Inc. and its affiliates. * * This software may be used and distributed according to the terms of the - * GNU General Public License found in the LICENSE file in the root - * directory of this source tree. + * GNU General Public License version 2. */ //! Read the documentation of [bounded_traversal](crate::bounded_traversal), diff --git a/eden/mononoke/common/bounded_traversal/src/stream.rs b/eden/mononoke/common/bounded_traversal/src/stream.rs index aaad67cd87..e7bfa67d4f 100644 --- a/eden/mononoke/common/bounded_traversal/src/stream.rs +++ b/eden/mononoke/common/bounded_traversal/src/stream.rs @@ -2,8 +2,7 @@ * Copyright (c) Facebook, Inc. and its affiliates. * * This software may be used and distributed according to the terms of the - * GNU General Public License found in the LICENSE file in the root - * directory of this source tree. + * GNU General Public License version 2. */ use futures::{ diff --git a/eden/mononoke/common/bounded_traversal/src/tests.rs b/eden/mononoke/common/bounded_traversal/src/tests.rs index e0d67e6da5..c27f9632db 100644 --- a/eden/mononoke/common/bounded_traversal/src/tests.rs +++ b/eden/mononoke/common/bounded_traversal/src/tests.rs @@ -2,8 +2,7 @@ * Copyright (c) Facebook, Inc. and its affiliates. * * This software may be used and distributed according to the terms of the - * GNU General Public License found in the LICENSE file in the root - * directory of this source tree. + * GNU General Public License version 2. */ use super::{bounded_traversal, bounded_traversal_dag, bounded_traversal_stream}; diff --git a/eden/mononoke/common/bounded_traversal/src/tree.rs b/eden/mononoke/common/bounded_traversal/src/tree.rs index 2ad2b8568f..37e1e74669 100644 --- a/eden/mononoke/common/bounded_traversal/src/tree.rs +++ b/eden/mononoke/common/bounded_traversal/src/tree.rs @@ -2,8 +2,7 @@ * Copyright (c) Facebook, Inc. and its affiliates. * * This software may be used and distributed according to the terms of the - * GNU General Public License found in the LICENSE file in the root - * directory of this source tree. + * GNU General Public License version 2. */ use super::{ diff --git a/eden/mononoke/common/scuba_ext/Cargo.toml b/eden/mononoke/common/scuba_ext/Cargo.toml new file mode 100644 index 0000000000..5e831b5bd5 --- /dev/null +++ b/eden/mononoke/common/scuba_ext/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "scuba_ext" +edition = "2018" +version = "0.1.0" +authors = ['Facebook'] +license = "GPLv2+" +include = ["src/**/*.rs"] + +[dependencies] +sshrelay = { path = "../../sshrelay" } +fbinit = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" } +futures_ext = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" } +futures_stats = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" } +scuba = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" } +time_ext = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" } +tracing = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" } +futures = "0.1" # todo: rename to "futures-old" +rand = { version = "0.7", features = ["small_rng"] } diff --git a/eden/mononoke/common/scuba_ext/src/lib.rs b/eden/mononoke/common/scuba_ext/src/lib.rs new file mode 100644 index 0000000000..8d3fb61693 --- /dev/null +++ b/eden/mononoke/common/scuba_ext/src/lib.rs @@ -0,0 +1,87 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This software may be used and distributed according to the terms of the + * GNU General Public License version 2. + */ + +#![deny(warnings)] + +use fbinit::FacebookInit; +use futures_ext::BoxFuture; +use futures_stats::{FutureStats, StreamStats}; +pub use scuba::{ScubaSampleBuilder, ScubaValue}; +use sshrelay::Preamble; +use time_ext::DurationExt; +use tracing::TraceContext; + +#[cfg(fbcode_build)] +mod facebook; +#[cfg(fbcode_build)] +pub use facebook::*; + +pub trait ScubaSampleBuilderExt { + fn with_opt_table(fb: FacebookInit, scuba_table: Option) -> Self; + fn add_preamble(&mut self, preamble: &Preamble) -> &mut Self; + fn log_with_msg>>(&mut self, log_tag: &'static str, msg: S); + fn add_stream_stats(&mut self, stats: &StreamStats) -> &mut Self; + fn add_future_stats(&mut self, stats: &FutureStats) -> &mut Self; + fn log_with_trace(&mut self, fb: FacebookInit, trace: &TraceContext) -> BoxFuture<(), ()>; +} + +impl ScubaSampleBuilderExt for ScubaSampleBuilder { + fn with_opt_table(fb: FacebookInit, scuba_table: Option) -> Self { + match scuba_table { + None => ScubaSampleBuilder::with_discard(), + Some(scuba_table) => ScubaSampleBuilder::new(fb, scuba_table), + } + } + + fn add_preamble(&mut self, preamble: &Preamble) -> &mut Self { + self.add("repo", preamble.reponame.as_ref()); + for (key, value) in preamble.misc.iter() { + self.add(key, value.as_ref()); + } + self + } + + fn log_with_msg>>(&mut self, log_tag: &'static str, msg: S) { + self.add("log_tag", log_tag); + if let Some(msg) = msg.into() { + self.add("msg", msg); + } + self.log(); + } + + fn add_stream_stats(&mut self, stats: &StreamStats) -> &mut Self { + self.add("poll_count", stats.poll_count) + .add("poll_time_us", stats.poll_time.as_micros_unchecked()) + .add("count", stats.count) + .add( + "completion_time_us", + stats.completion_time.as_micros_unchecked(), + ) + } + + fn add_future_stats(&mut self, stats: &FutureStats) -> &mut Self { + self.add("poll_count", stats.poll_count) + .add("poll_time_us", stats.poll_time.as_micros_unchecked()) + .add( + "completion_time_us", + stats.completion_time.as_micros_unchecked(), + ) + } + + fn log_with_trace(&mut self, fb: FacebookInit, trace: &TraceContext) -> BoxFuture<(), ()> { + #[cfg(not(fbcode_build))] + { + use futures_ext::FutureExt; + let _ = (fb, trace); + futures::future::ok(()).boxify() + } + #[cfg(fbcode_build)] + { + facebook::log_with_trace(self, fb, trace) + } + } +} diff --git a/eden/mononoke/edenapi_server/src/router.rs b/eden/mononoke/edenapi_server/src/router.rs index 487ceed9ea..a35337e046 100644 --- a/eden/mononoke/edenapi_server/src/router.rs +++ b/eden/mononoke/edenapi_server/src/router.rs @@ -2,8 +2,7 @@ * Copyright (c) Facebook, Inc. and its affiliates. * * This software may be used and distributed according to the terms of the - * GNU General Public License found in the LICENSE file in the root - * directory of this source tree. + * GNU General Public License version 2. */ #![deny(warnings)]