Custom tracing SlabConfig.

This commit is contained in:
Arseny Sher
2022-12-20 00:18:25 +04:00
parent 12e6f443da
commit 8ef87e193a
5 changed files with 120 additions and 45 deletions

131
Cargo.lock generated
View File

@@ -193,7 +193,7 @@ dependencies = [
"time",
"tokio",
"tower",
"tracing",
"tracing 0.1.37",
"zeroize",
]
@@ -208,7 +208,7 @@ dependencies = [
"aws-types",
"http",
"regex",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -226,7 +226,7 @@ dependencies = [
"lazy_static",
"percent-encoding",
"pin-project-lite",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -254,7 +254,7 @@ dependencies = [
"http-body",
"tokio-stream",
"tower",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -312,7 +312,7 @@ dependencies = [
"aws-smithy-http",
"aws-types",
"http",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -332,7 +332,7 @@ dependencies = [
"regex",
"ring",
"time",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -365,7 +365,7 @@ dependencies = [
"pin-project-lite",
"sha1",
"sha2",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -388,7 +388,7 @@ dependencies = [
"pin-project-lite",
"tokio",
"tower",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -422,7 +422,7 @@ dependencies = [
"pin-utils",
"tokio",
"tokio-util",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -437,7 +437,7 @@ dependencies = [
"http-body",
"pin-project-lite",
"tower",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -492,7 +492,7 @@ dependencies = [
"aws-smithy-types",
"http",
"rustc_version",
"tracing",
"tracing 0.1.37",
"zeroize",
]
@@ -1551,7 +1551,7 @@ dependencies = [
"slab",
"tokio",
"tokio-util",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -1726,7 +1726,7 @@ dependencies = [
"socket2",
"tokio",
"tower-service",
"tracing",
"tracing 0.1.37",
"want",
]
@@ -2431,7 +2431,7 @@ dependencies = [
"tokio-postgres",
"tokio-util",
"toml_edit",
"tracing",
"tracing 0.1.37",
"url",
"utils",
"walkdir",
@@ -2730,7 +2730,7 @@ dependencies = [
"rand",
"serde",
"tokio",
"tracing",
"tracing 0.1.37",
"workspace_hack",
]
@@ -2908,8 +2908,8 @@ dependencies = [
"tokio-postgres",
"tokio-postgres-rustls",
"tokio-rustls",
"tracing",
"tracing-subscriber",
"tracing 0.1.37",
"tracing-subscriber 0.3.16",
"url",
"utils",
"uuid 1.2.2",
@@ -3064,7 +3064,7 @@ dependencies = [
"tokio",
"tokio-util",
"toml_edit",
"tracing",
"tracing 0.1.37",
"utils",
"workspace_hack",
]
@@ -3329,7 +3329,7 @@ dependencies = [
"tokio",
"tokio-postgres",
"toml_edit",
"tracing",
"tracing 0.2.0",
"url",
"utils",
"workspace_hack",
@@ -3724,7 +3724,7 @@ dependencies = [
"tokio-stream",
"tonic",
"tonic-build",
"tracing",
"tracing 0.1.37",
"utils",
"workspace_hack",
]
@@ -4083,7 +4083,7 @@ dependencies = [
"futures-sink",
"pin-project-lite",
"tokio",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -4138,7 +4138,7 @@ dependencies = [
"tower",
"tower-layer",
"tower-service",
"tracing",
"tracing 0.1.37",
"tracing-futures",
]
@@ -4172,7 +4172,7 @@ dependencies = [
"tokio-util",
"tower-layer",
"tower-service",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -4215,8 +4215,18 @@ dependencies = [
"cfg-if",
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
"tracing-attributes 0.1.23",
"tracing-core 0.1.30",
]
[[package]]
name = "tracing"
version = "0.2.0"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-attributes 0.2.0",
"tracing-core 0.2.0",
]
[[package]]
@@ -4230,6 +4240,15 @@ dependencies = [
"syn",
]
[[package]]
name = "tracing-attributes"
version = "0.2.0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.30"
@@ -4240,6 +4259,13 @@ dependencies = [
"valuable",
]
[[package]]
name = "tracing-core"
version = "0.2.0"
dependencies = [
"once_cell",
]
[[package]]
name = "tracing-futures"
version = "0.2.5"
@@ -4247,7 +4273,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
dependencies = [
"pin-project",
"tracing",
"tracing 0.1.37",
]
[[package]]
@@ -4258,17 +4284,43 @@ checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922"
dependencies = [
"lazy_static",
"log",
"tracing-core",
"tracing-core 0.1.30",
]
[[package]]
name = "tracing-log"
version = "0.2.0"
dependencies = [
"log",
"once_cell",
"tracing-core 0.2.0",
]
[[package]]
name = "tracing-serde"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1"
version = "0.2.0"
dependencies = [
"serde",
"tracing-core",
"tracing-core 0.2.0",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.0"
dependencies = [
"matchers",
"nu-ansi-term",
"once_cell",
"regex",
"serde",
"serde_json",
"sharded-slab",
"smallvec",
"thread_local",
"tracing 0.2.0",
"tracing-core 0.2.0",
"tracing-log 0.2.0",
"tracing-serde",
]
[[package]]
@@ -4281,15 +4333,12 @@ dependencies = [
"nu-ansi-term",
"once_cell",
"regex",
"serde",
"serde_json",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
"tracing-serde",
"tracing 0.1.37",
"tracing-core 0.1.30",
"tracing-log 0.1.3",
]
[[package]]
@@ -4419,8 +4468,8 @@ dependencies = [
"thiserror",
"tokio",
"tokio-rustls",
"tracing",
"tracing-subscriber",
"tracing 0.1.37",
"tracing-subscriber 0.3.0",
"workspace_hack",
]
@@ -4782,8 +4831,8 @@ dependencies = [
"tokio",
"tokio-util",
"tower",
"tracing",
"tracing-core",
"tracing 0.1.37",
"tracing-core 0.1.30",
"url",
]

View File

@@ -17,7 +17,9 @@ thiserror = "1.0"
tokio = { version = "1.17", features = ["macros"]}
tokio-rustls = "0.23"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
# tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
tracing-subscriber = { path = "/home/ars/rust/tracing/tracing-subscriber", features = ["env-filter", "json"] }
# tracing-subscriber = { git = "/home/ars/rust/tracing/tracing-subscriber", features = ["env-filter", "json"] }
nix = "0.25"
signal-hook = "0.3.10"
rand = "0.8.3"

View File

@@ -3,6 +3,9 @@ use std::str::FromStr;
use anyhow::Context;
use strum_macros::{EnumString, EnumVariantNames};
pub use tracing_subscriber::DefaultSlabConfig;
pub use tracing_subscriber::SlabConfig;
#[derive(EnumString, EnumVariantNames, Eq, PartialEq, Debug, Clone, Copy)]
#[strum(serialize_all = "snake_case")]
pub enum LogFormat {
@@ -22,7 +25,10 @@ impl LogFormat {
}
}
pub fn init(log_format: LogFormat) -> anyhow::Result<()> {
pub fn init<S>(log_format: LogFormat) -> anyhow::Result<()>
where
S: SlabConfig + 'static,
{
let default_filter_str = "info";
// We fall back to printing all spans at info-level or above if
@@ -31,6 +37,7 @@ pub fn init(log_format: LogFormat) -> anyhow::Result<()> {
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new(default_filter_str));
let base_logger = tracing_subscriber::fmt()
.with_slab_config::<S>()
.with_env_filter(env_filter)
.with_target(false)
.with_ansi(false)

View File

@@ -31,7 +31,8 @@ thiserror = "1"
tokio = { version = "1.17", features = ["macros", "fs"] }
tokio-postgres = { git = "https://github.com/neondatabase/rust-postgres.git", rev="43e6db254a97fdecbce33d8bc0890accfd74495e" }
toml_edit = { version = "0.14", features = ["easy"] }
tracing = "0.1.27"
# tracing = "0.1.27"
tracing = { path = "/home/ars/rust/tracing/tracing"}
url = "2.2.2"
metrics = { path = "../libs/metrics" }

View File

@@ -126,12 +126,21 @@ fn main() -> anyhow::Result<()> {
return Ok(());
}
logging::init(LogFormat::from_config(&args.log_format)?)?;
logging::init::<SafekeeperSlabConfig>(LogFormat::from_config(&args.log_format)?)?;
info!("version: {GIT_VERSION}");
// Change into the data directory.
std::env::set_current_dir(&args.datadir)?;
for i in 1..4200 {
thread::spawn(move || loop {
let _enter2 = info_span!("baba", i=%i).entered();
// info!("hi number {} from the spawned thread!", i);
thread::sleep(Duration::from_millis(100000));
});
}
thread::sleep(Duration::from_millis(1000000));
// Set or read our ID.
let id = set_id(&args.datadir, args.id.map(NodeId))?;
if args.init {
@@ -333,6 +342,13 @@ fn parse_remote_storage(storage_conf: &str) -> anyhow::Result<RemoteStorageConfi
})
}
struct SafekeeperSlabConfig {}
impl logging::SlabConfig for SafekeeperSlabConfig {
const INITIAL_PAGE_SIZE: usize = 32;
const MAX_THREADS: usize = 8192;
const MAX_PAGES: usize = logging::DefaultSlabConfig::MAX_PAGES;
}
#[test]
fn verify_cli() {
use clap::CommandFactory;