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
This commit is contained in:
Lukas Piatkowski 2020-02-14 01:24:14 -08:00 committed by Facebook Github Bot
parent 1ebacd1c26
commit 0ccc5f678a
10 changed files with 113 additions and 14 deletions

View File

@ -1,6 +1,7 @@
[workspace]
members = [
"common/scuba_ext",
"server/session_id",
"sshrelay",
]

View File

@ -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;

View File

@ -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::{

View File

@ -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),

View File

@ -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::{

View File

@ -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};

View File

@ -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::{

View File

@ -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"] }

View File

@ -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<String>) -> Self;
fn add_preamble(&mut self, preamble: &Preamble) -> &mut Self;
fn log_with_msg<S: Into<Option<String>>>(&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<String>) -> 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<S: Into<Option<String>>>(&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)
}
}
}

View File

@ -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)]