Hacked in support for tokio console-subscriber

This commit is contained in:
Ben Wallis 2021-09-09 11:35:07 +01:00
parent 6cdc620c5d
commit 823120f923
6 changed files with 304 additions and 21 deletions

292
Cargo.lock generated
View File

@ -128,6 +128,12 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "anyhow"
version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf"
[[package]]
name = "approx"
version = "0.3.2"
@ -240,6 +246,27 @@ dependencies = [
"futures-core",
]
[[package]]
name = "async-stream"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625"
dependencies = [
"async-stream-impl",
"futures-core",
]
[[package]]
name = "async-stream-impl"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308"
dependencies = [
"proc-macro2 1.0.27",
"quote 1.0.9",
"syn 1.0.73",
]
[[package]]
name = "async-trait"
version = "0.1.50"
@ -400,9 +427,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "bitvec"
version = "0.22.3"
version = "0.19.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527"
checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321"
dependencies = [
"funty",
"radium",
@ -761,6 +788,37 @@ name = "conrod_winit"
version = "0.63.0"
source = "git+https://gitlab.com/veloren/conrod.git?branch=copypasta_0.7#ca9fd429ca7db854e018acc6dcb2cd8abd9e070d"
[[package]]
name = "console-api"
version = "0.1.0"
source = "git+https://github.com/tokio-rs/console.git?rev=926de99ce4cbfd02c87190f9ec5f1c60b5c305d5#926de99ce4cbfd02c87190f9ec5f1c60b5c305d5"
dependencies = [
"prost",
"prost-types",
"tonic",
"tonic-build",
"tracing-core",
]
[[package]]
name = "console-subscriber"
version = "0.1.0"
source = "git+https://github.com/tokio-rs/console.git?rev=926de99ce4cbfd02c87190f9ec5f1c60b5c305d5#926de99ce4cbfd02c87190f9ec5f1c60b5c305d5"
dependencies = [
"console-api",
"futures",
"hdrhistogram",
"serde",
"serde_json",
"thread_local",
"tokio",
"tokio-stream",
"tonic",
"tracing",
"tracing-core",
"tracing-subscriber",
]
[[package]]
name = "constant_time_eq"
version = "0.1.5"
@ -1778,9 +1836,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "funty"
version = "1.2.0"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e"
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
[[package]]
name = "futures"
@ -2326,6 +2384,19 @@ dependencies = [
"hashbrown 0.9.1",
]
[[package]]
name = "hdrhistogram"
version = "7.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "faa51471caf8069812385974ce947bf4b71a806d7e5a0d1f710af57d6a9a45ad"
dependencies = [
"base64",
"byteorder",
"flate2",
"nom 6.1.2",
"num-traits",
]
[[package]]
name = "heapless"
version = "0.5.6"
@ -2465,6 +2536,18 @@ dependencies = [
"webpki",
]
[[package]]
name = "hyper-timeout"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1"
dependencies = [
"hyper",
"pin-project-lite",
"tokio",
"tokio-io-timeout",
]
[[package]]
name = "iced_core"
version = "0.4.0"
@ -2783,6 +2866,19 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "lexical-core"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
dependencies = [
"arrayvec",
"bitflags",
"cfg-if 1.0.0",
"ryu",
"static_assertions",
]
[[package]]
name = "libc"
version = "0.2.98"
@ -3174,6 +3270,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238"
[[package]]
name = "multimap"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a"
[[package]]
name = "mumble-link"
version = "0.1.0"
@ -3346,6 +3448,9 @@ version = "6.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2"
dependencies = [
"bitvec",
"funty",
"lexical-core",
"memchr",
"version_check 0.9.3",
]
@ -3830,6 +3935,26 @@ dependencies = [
"indexmap",
]
[[package]]
name = "pin-project"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389"
dependencies = [
"proc-macro2 1.0.27",
"quote 1.0.9",
"syn 1.0.73",
]
[[package]]
name = "pin-project-lite"
version = "0.2.7"
@ -4038,6 +4163,57 @@ dependencies = [
"tracing",
]
[[package]]
name = "prost"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de5e2533f59d08fcf364fd374ebda0692a70bd6d7e66ef97f306f45c6c5d8020"
dependencies = [
"bytes",
"prost-derive",
]
[[package]]
name = "prost-build"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "355f634b43cdd80724ee7848f95770e7e70eefa6dcf14fea676216573b8fd603"
dependencies = [
"bytes",
"heck",
"itertools 0.10.1",
"log",
"multimap",
"petgraph 0.5.1",
"prost",
"prost-types",
"tempfile",
"which 4.1.0",
]
[[package]]
name = "prost-derive"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "600d2f334aa05acb02a755e217ef1ab6dea4d51b58b7846588b747edec04efba"
dependencies = [
"anyhow",
"itertools 0.10.1",
"proc-macro2 1.0.27",
"quote 1.0.9",
"syn 1.0.73",
]
[[package]]
name = "prost-types"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "603bbd6394701d13f3f25aada59c7de9d35a6a5887cfc156181234a44002771b"
dependencies = [
"bytes",
"prost",
]
[[package]]
name = "ptr_meta"
version = "0.1.4"
@ -4117,9 +4293,9 @@ dependencies = [
[[package]]
name = "radium"
version = "0.6.2"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb"
checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
[[package]]
name = "radix_trie"
@ -5461,9 +5637,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.8.1"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98c8b05dc14c75ea83d63dd391100353789f5f24b8b3866542a5e85c8be8e985"
checksum = "b4efe6fc2395938c8155973d7be49fe8d03a843726e285e100a8a383cc0154ce"
dependencies = [
"autocfg",
"bytes",
@ -5475,9 +5651,20 @@ dependencies = [
"pin-project-lite",
"signal-hook-registry",
"tokio-macros",
"tracing",
"winapi 0.3.9",
]
[[package]]
name = "tokio-io-timeout"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90c49f106be240de154571dd31fbe48acb10ba6c6dd6f6517ad603abffa42de9"
dependencies = [
"pin-project-lite",
"tokio",
]
[[package]]
name = "tokio-macros"
version = "1.3.0"
@ -5534,6 +5721,75 @@ dependencies = [
"serde",
]
[[package]]
name = "tonic"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "796c5e1cd49905e65dd8e700d4cb1dffcbfdb4fc9d017de08c1a537afd83627c"
dependencies = [
"async-stream",
"async-trait",
"base64",
"bytes",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"hyper",
"hyper-timeout",
"percent-encoding",
"pin-project",
"prost",
"prost-derive",
"tokio",
"tokio-stream",
"tokio-util",
"tower",
"tower-layer",
"tower-service",
"tracing",
"tracing-futures",
]
[[package]]
name = "tonic-build"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12b52d07035516c2b74337d2ac7746075e7dcae7643816c1b12c5ff8a7484c08"
dependencies = [
"proc-macro2 1.0.27",
"prost-build",
"quote 1.0.9",
"syn 1.0.73",
]
[[package]]
name = "tower"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60422bc7fefa2f3ec70359b8ff1caff59d785877eb70595904605bcc412470f"
dependencies = [
"futures-core",
"futures-util",
"indexmap",
"pin-project",
"rand 0.8.4",
"slab",
"tokio",
"tokio-stream",
"tokio-util",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
name = "tower-layer"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62"
[[package]]
name = "tower-service"
version = "0.3.1"
@ -5547,6 +5803,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d"
dependencies = [
"cfg-if 1.0.0",
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
@ -5583,6 +5840,16 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "tracing-futures"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
dependencies = [
"pin-project",
"tracing",
]
[[package]]
name = "tracing-log"
version = "0.1.2"
@ -5937,7 +6204,9 @@ dependencies = [
name = "veloren-common-frontend"
version = "0.10.0"
dependencies = [
"console-subscriber",
"termcolor",
"tokio",
"tracing",
"tracing-appender",
"tracing-log",
@ -6984,12 +7253,9 @@ dependencies = [
[[package]]
name = "wyz"
version = "0.4.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "129e027ad65ce1453680623c3fb5163cbf7107bfe1aa32257e7d0e63f9ced188"
dependencies = [
"tap",
]
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
[[package]]
name = "x11-clipboard"

View File

@ -17,6 +17,10 @@ tracing = { version = "0.1", default-features = false }
tracing-appender = "0.1"
tracing-log = "0.1.1"
tracing-subscriber = { version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec", "tracing-log"]}
console-subscriber = { git = "https://github.com/tokio-rs/console.git", rev = "926de99ce4cbfd02c87190f9ec5f1c60b5c305d5" }
# TODO: required for console-subscriber, don't include by default
tokio = "1.2"
# Tracy
tracing-tracy = { version = "0.6.0", optional = true }

View File

@ -1,6 +1,7 @@
#[cfg(not(feature = "tracy"))] use std::fs;
use std::path::Path;
use console_subscriber::Server;
use termcolor::{ColorChoice, StandardStream};
use tracing::info;
use tracing_appender::non_blocking::WorkerGuard;
@ -32,7 +33,7 @@ const RUST_LOG_ENV: &str = "RUST_LOG";
///
/// By default a few directives are set to `warn` by default, until explicitly
/// overwritten! e.g. `RUST_LOG="gfx_device_gl=debug"`
pub fn init<W2>(log_path_file: Option<(&Path, &str)>, terminal: W2) -> Vec<impl Drop>
pub fn init<W2>(log_path_file: Option<(&Path, &str)>, terminal: W2) -> (Vec<impl Drop>, Server)
where
W2: MakeWriter + 'static,
<W2 as MakeWriter>::Writer: Send + Sync,
@ -67,6 +68,7 @@ where
.add_directive("wgpu_core::swap_chain=info".parse().unwrap())
.add_directive("veloren_network_protocol=info".parse().unwrap())
.add_directive("quinn_proto::connection=info".parse().unwrap())
.add_directive("tokio=trace".parse().unwrap()) // TODO: Only enable when console-subscriber in use
.add_directive(
"veloren_server::persistence::character=info"
.parse()
@ -108,6 +110,8 @@ where
registry.with(tracing_subscriber::fmt::layer().with_writer(non_blocking))
};
let (console_subscriber_layer, console_subscriber_server) =
console_subscriber::TasksLayer::new();
// Try to create the log file's parent folders.
#[cfg(not(feature = "tracy"))]
if let Some((path, file)) = log_path_file {
@ -120,6 +124,7 @@ where
registry
.with(tracing_subscriber::fmt::layer().with_writer(non_blocking_file))
.with(filter)
.with(console_subscriber_layer)
.init();
},
Err(e) => {
@ -148,9 +153,9 @@ where
};
// Return the guards
guards
(guards, console_subscriber_server)
}
pub fn init_stdout(log_path_file: Option<(&Path, &str)>) -> Vec<impl Drop> {
pub fn init_stdout(log_path_file: Option<(&Path, &str)>) -> (Vec<impl Drop>, Server) {
init(log_path_file, || StandardStream::stdout(ColorChoice::Auto))
}

View File

@ -48,10 +48,12 @@ fn main() -> io::Result<()> {
#[cfg(any(target_os = "linux", target_os = "macos"))]
let _ = signal_hook::flag::register(signal_hook::consts::SIGUSR1, Arc::clone(&sigusr1_signal));
let (_guards, _guards2) = if basic {
(vec![], common_frontend::init_stdout(None))
let (_guards, _guards2, console_subscriber_server) = if basic {
let result = common_frontend::init_stdout(None);
(vec![], result.0, result.1)
} else {
(common_frontend::init(None, || LOG.clone()), vec![])
let result = common_frontend::init(None, || LOG.clone());
(result.0, vec![], result.1)
};
// Load settings
@ -81,6 +83,9 @@ fn main() -> io::Result<()> {
.unwrap(),
);
runtime.spawn(console_subscriber_server.serve());
//tokio::spawn(console_subscriber_server.serve());
// Load server settings
let mut server_settings = server::Settings::load(&server_data_dir);
let mut editable_settings = server::EditableSettings::load(&server_data_dir);

View File

@ -40,7 +40,8 @@ fn main() {
// Init logging and hold the guards.
const LOG_FILENAME: &str = "voxygen.log";
let _guards = common_frontend::init_stdout(Some((&logs_dir, LOG_FILENAME)));
let (_guards, console_subscriber_server) =
common_frontend::init_stdout(Some((&logs_dir, LOG_FILENAME)));
info!("Using userdata dir at: {}", userdata_dir.display());
@ -188,6 +189,8 @@ fn main() {
.unwrap(),
);
tokio_runtime.spawn(console_subscriber_server.serve());
#[cfg(feature = "hot-reloading")]
assets::start_hot_reloading();

View File

@ -16,7 +16,7 @@ common_base = { package = "veloren-common-base", path = "../common/base"}
common-net = { package = "veloren-common-net", path = "../common/net" }
bincode = "1.3.1"
bitvec = "0.22"
bitvec = "0.19.5"
enum-iterator = "0.6"
fxhash = "0.2.1"
image = { version = "0.23.12", default-features = false, features = ["png"] }