🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2024-05-12 10:03:58.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2024-05-12 10:03:58.0 +00:00:00
commit
6d9e9b8e3977981d5239c14fcfd81699505998c0 [patch]
tree
10a26fa763eb5bc24c455d73c2fcbe8f8a4ed722
parent
2afb0b0a247087c1217f54150580a7c89d5fcf36
download
6d9e9b8e3977981d5239c14fcfd81699505998c0.tar.gz

Expose tokio-console



Diff

 .cargo/config.toml |   2 +-
 Cargo.lock         | 356 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 Cargo.toml         |   3 +-
 src/git.rs         |  11 +--
 src/main.rs        |  30 +++--
 5 files changed, 355 insertions(+), 47 deletions(-)

diff --git a/.cargo/config.toml b/.cargo/config.toml
new file mode 100644
index 0000000..bff29e6
--- /dev/null
+++ b/.cargo/config.toml
@@ -0,0 +1,2 @@
[build]
rustflags = ["--cfg", "tokio_unstable"]
diff --git a/Cargo.lock b/Cargo.lock
index 5c9127b..59a72d0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -149,6 +149,28 @@ dependencies = [
]

[[package]]
name = "async-stream"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51"
dependencies = [
 "async-stream-impl",
 "futures-core",
 "pin-project-lite",
]

[[package]]
name = "async-stream-impl"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
dependencies = [
 "proc-macro2",
 "quote",
 "syn 2.0.48",
]

[[package]]
name = "async-trait"
version = "0.1.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -167,19 +189,47 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"

[[package]]
name = "axum"
version = "0.6.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf"
dependencies = [
 "async-trait",
 "axum-core 0.3.4",
 "bitflags 1.3.2",
 "bytes",
 "futures-util",
 "http 0.2.12",
 "http-body 0.4.6",
 "hyper 0.14.28",
 "itoa",
 "matchit",
 "memchr",
 "mime",
 "percent-encoding",
 "pin-project-lite",
 "rustversion",
 "serde",
 "sync_wrapper",
 "tower",
 "tower-layer",
 "tower-service",
]

[[package]]
name = "axum"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e"
dependencies = [
 "async-trait",
 "axum-core",
 "axum-core 0.4.3",
 "axum-macros",
 "bytes",
 "futures-util",
 "http",
 "http-body",
 "http 1.0.0",
 "http-body 1.0.0",
 "http-body-util",
 "hyper",
 "hyper 1.1.0",
 "hyper-util",
 "itoa",
 "matchit",
@@ -202,6 +252,23 @@ dependencies = [

[[package]]
name = "axum-core"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c"
dependencies = [
 "async-trait",
 "bytes",
 "futures-util",
 "http 0.2.12",
 "http-body 0.4.6",
 "mime",
 "rustversion",
 "tower-layer",
 "tower-service",
]

[[package]]
name = "axum-core"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3"
@@ -209,8 +276,8 @@ dependencies = [
 "async-trait",
 "bytes",
 "futures-util",
 "http",
 "http-body",
 "http 1.0.0",
 "http-body 1.0.0",
 "http-body-util",
 "mime",
 "pin-project-lite",
@@ -388,6 +455,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed2490600f404f2b94c167e31d3ed1d5f3c225a0f3b80230053b3e0b7b962bd9"

[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"

[[package]]
name = "bytes"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -570,6 +643,44 @@ dependencies = [
]

[[package]]
name = "console-api"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd326812b3fd01da5bb1af7d340d0d555fd3d4b641e7f1dfcf5962a902952787"
dependencies = [
 "futures-core",
 "prost",
 "prost-types",
 "tonic",
 "tracing-core",
]

[[package]]
name = "console-subscriber"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7481d4c57092cd1c19dd541b92bdce883de840df30aa5d03fd48a3935c01842e"
dependencies = [
 "console-api",
 "crossbeam-channel",
 "crossbeam-utils",
 "futures-task",
 "hdrhistogram",
 "humantime",
 "parking_lot",
 "prost-types",
 "serde",
 "serde_json",
 "thread_local",
 "tokio",
 "tokio-stream",
 "tonic",
 "tracing",
 "tracing-core",
 "tracing-subscriber",
]

[[package]]
name = "const-random"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1020,6 +1131,25 @@ dependencies = [

[[package]]
name = "h2"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8"
dependencies = [
 "bytes",
 "fnv",
 "futures-core",
 "futures-sink",
 "futures-util",
 "http 0.2.12",
 "indexmap 2.2.2",
 "slab",
 "tokio",
 "tokio-util",
 "tracing",
]

[[package]]
name = "h2"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943"
@@ -1029,8 +1159,8 @@ dependencies = [
 "futures-core",
 "futures-sink",
 "futures-util",
 "http",
 "indexmap",
 "http 1.0.0",
 "indexmap 2.2.2",
 "slab",
 "tokio",
 "tokio-util",
@@ -1039,11 +1169,30 @@ dependencies = [

[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"

[[package]]
name = "hashbrown"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"

[[package]]
name = "hdrhistogram"
version = "7.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d"
dependencies = [
 "base64",
 "byteorder",
 "flate2",
 "nom",
 "num-traits",
]

[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1072,6 +1221,17 @@ dependencies = [

[[package]]
name = "http"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1"
dependencies = [
 "bytes",
 "fnv",
 "itoa",
]

[[package]]
name = "http"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea"
@@ -1083,12 +1243,23 @@ dependencies = [

[[package]]
name = "http-body"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"
dependencies = [
 "bytes",
 "http 0.2.12",
 "pin-project-lite",
]

[[package]]
name = "http-body"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643"
dependencies = [
 "bytes",
 "http",
 "http 1.0.0",
]

[[package]]
@@ -1099,8 +1270,8 @@ checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840"
dependencies = [
 "bytes",
 "futures-util",
 "http",
 "http-body",
 "http 1.0.0",
 "http-body 1.0.0",
 "pin-project-lite",
]

@@ -1133,6 +1304,30 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"

[[package]]
name = "hyper"
version = "0.14.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80"
dependencies = [
 "bytes",
 "futures-channel",
 "futures-core",
 "futures-util",
 "h2 0.3.26",
 "http 0.2.12",
 "http-body 0.4.6",
 "httparse",
 "httpdate",
 "itoa",
 "pin-project-lite",
 "socket2",
 "tokio",
 "tower-service",
 "tracing",
 "want",
]

[[package]]
name = "hyper"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75"
@@ -1140,9 +1335,9 @@ dependencies = [
 "bytes",
 "futures-channel",
 "futures-util",
 "h2",
 "http",
 "http-body",
 "h2 0.4.2",
 "http 1.0.0",
 "http-body 1.0.0",
 "httparse",
 "httpdate",
 "itoa",
@@ -1151,6 +1346,18 @@ dependencies = [
]

[[package]]
name = "hyper-timeout"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1"
dependencies = [
 "hyper 0.14.28",
 "pin-project-lite",
 "tokio",
 "tokio-io-timeout",
]

[[package]]
name = "hyper-util"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1158,9 +1365,9 @@ checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa"
dependencies = [
 "bytes",
 "futures-util",
 "http",
 "http-body",
 "hyper",
 "http 1.0.0",
 "http-body 1.0.0",
 "hyper 1.1.0",
 "pin-project-lite",
 "socket2",
 "tokio",
@@ -1184,12 +1391,22 @@ dependencies = [

[[package]]
name = "indexmap"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
 "autocfg",
 "hashbrown 0.12.3",
]

[[package]]
name = "indexmap"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520"
dependencies = [
 "equivalent",
 "hashbrown",
 "hashbrown 0.14.3",
]

[[package]]
@@ -1604,7 +1821,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4d6a8c22fc714f0c2373e6091bf6f5e9b37b1bc0b1184874b7e0a4e303d318f"
dependencies = [
 "dlv-list",
 "hashbrown",
 "hashbrown 0.14.3",
]

[[package]]
@@ -1708,7 +1925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5699cc8a63d1aa2b1ee8e12b9ad70ac790d65788cd36101fa37f87ea46c4cef"
dependencies = [
 "base64",
 "indexmap",
 "indexmap 2.2.2",
 "line-wrap",
 "quick-xml",
 "serde",
@@ -1747,6 +1964,38 @@ dependencies = [
]

[[package]]
name = "prost"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922"
dependencies = [
 "bytes",
 "prost-derive",
]

[[package]]
name = "prost-derive"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9554e3ab233f0a932403704f1a1d08c30d5ccd931adfdfa1e8b5a19b52c1d55a"
dependencies = [
 "anyhow",
 "itertools",
 "proc-macro2",
 "quote",
 "syn 2.0.48",
]

[[package]]
name = "prost-types"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3235c33eb02c1f1e212abdbe34c78b264b038fb58ca612664343271e36e55ffe"
dependencies = [
 "prost",
]

[[package]]
name = "pulldown-cmark"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1903,13 +2152,14 @@ version = "0.1.3"
dependencies = [
 "anyhow",
 "askama",
 "axum",
 "axum 0.7.4",
 "axum-macros",
 "bat",
 "bincode",
 "bytes",
 "clap",
 "comrak",
 "console-subscriber",
 "flate2",
 "futures",
 "git2",
@@ -2119,7 +2369,7 @@ version = "0.9.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e"
dependencies = [
 "indexmap",
 "indexmap 2.2.2",
 "itoa",
 "ryu",
 "serde",
@@ -2443,10 +2693,21 @@ dependencies = [
 "signal-hook-registry",
 "socket2",
 "tokio-macros",
 "tracing",
 "windows-sys 0.48.0",
]

[[package]]
name = "tokio-io-timeout"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf"
dependencies = [
 "pin-project-lite",
 "tokio",
]

[[package]]
name = "tokio-macros"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2483,6 +2744,33 @@ dependencies = [
]

[[package]]
name = "tonic"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d560933a0de61cf715926b9cac824d4c883c2c43142f787595e48280c40a1d0e"
dependencies = [
 "async-stream",
 "async-trait",
 "axum 0.6.20",
 "base64",
 "bytes",
 "h2 0.3.26",
 "http 0.2.12",
 "http-body 0.4.6",
 "hyper 0.14.28",
 "hyper-timeout",
 "percent-encoding",
 "pin-project",
 "prost",
 "tokio",
 "tokio-stream",
 "tower",
 "tower-layer",
 "tower-service",
 "tracing",
]

[[package]]
name = "tower"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2490,9 +2778,13 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"
dependencies = [
 "futures-core",
 "futures-util",
 "indexmap 1.9.3",
 "pin-project",
 "pin-project-lite",
 "rand",
 "slab",
 "tokio",
 "tokio-util",
 "tower-layer",
 "tower-service",
 "tracing",
@@ -2506,8 +2798,8 @@ checksum = "0da193277a4e2c33e59e09b5861580c33dd0a637c3883d0fa74ba40c0374af2e"
dependencies = [
 "bitflags 2.4.2",
 "bytes",
 "http",
 "http-body",
 "http 1.0.0",
 "http-body 1.0.0",
 "http-body-util",
 "pin-project-lite",
 "tower-layer",
@@ -2579,6 +2871,7 @@ dependencies = [
 "matchers",
 "nu-ansi-term 0.46.0",
 "once_cell",
 "parking_lot",
 "regex",
 "sharded-slab",
 "smallvec",
@@ -2595,6 +2888,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3"

[[package]]
name = "try-lock"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"

[[package]]
name = "typed-arena"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2715,6 +3014,15 @@ dependencies = [
]

[[package]]
name = "want"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
dependencies = [
 "try-lock",
]

[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 8545710..d0fe320 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,6 +16,7 @@ axum-macros = "0.4.1"
bat = { version = "0.24.0", default-features = false, features = ["build-assets"] }
bytes = "1.5"
bincode = "1.3"
console-subscriber = { version = "0.2", features = ["parking_lot"] }
comrak = "0.21.0"
clap = { version = "4.4.10", features = ["cargo", "derive"] }
futures = "0.3"
@@ -38,7 +39,7 @@ tar = "0.4"
flate2 = "1.0"
time = { version = "0.3", features = ["serde"] }
timeago = { version = "0.4.2", default-features = false }
tokio = { version = "1.19", features = ["full"] }
tokio = { version = "1.19", features = ["full", "tracing"] }
tokio-util = { version = "0.7.10", features = ["io"] }
tokio-stream = "0.1"
tower = "0.4"
diff --git a/src/git.rs b/src/git.rs
index 1fc0379..7f40cf3 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -518,17 +518,6 @@ impl IntoResponse for Content {
}

#[derive(Debug)]
pub struct Branch {
    pub name: String,
    pub commit: Commit,
}

#[derive(Debug)]
pub struct Remote {
    pub name: String,
}

#[derive(Debug)]
pub enum TaggedObject {
    Commit(String),
    Tree(String),
diff --git a/src/main.rs b/src/main.rs
index b5c2d65..234aa87 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -37,7 +37,7 @@ use tokio::{
use tower_http::cors::CorsLayer;
use tower_layer::layer_fn;
use tracing::{error, info, instrument, warn};
use tracing_subscriber::EnvFilter;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

use crate::{
    database::schema::prefixes::{
@@ -64,9 +64,9 @@ static DARK_HIGHLIGHT_CSS_HASH: OnceCell<Box<str>> = OnceCell::new();
#[derive(Parser, Debug)]
#[clap(author, version, about)]
pub struct Args {
    /// Path to a directory in which the RocksDB database should be stored, will be created if it doesn't already exist
    /// Path to a directory in which the `RocksDB` database should be stored, will be created if it doesn't already exist
    ///
    /// The RocksDB database is very quick to generate, so this can be pointed to temporary storage
    /// The `RocksDB` database is very quick to generate, so this can be pointed to temporary storage
    #[clap(short, long, value_parser)]
    db_store: PathBuf,
    /// The socket address to bind to (eg. 0.0.0.0:3333)
@@ -115,10 +115,21 @@ async fn main() -> Result<(), anyhow::Error> {
        std::env::set_var("RUST_LOG", "info");
    }

    let subscriber = tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env());
    let console_layer = console_subscriber::spawn();

    let logger_layer = tracing_subscriber::fmt::layer();
    #[cfg(debug_assertions)]
    let subscriber = subscriber.pretty();
    subscriber.init();
    let logger_layer = logger_layer.pretty();

    let env_filter = EnvFilter::from_default_env()
        .add_directive("tokio=trace".parse()?)
        .add_directive("runtime=trace".parse()?);

    tracing_subscriber::registry()
        .with(env_filter)
        .with(console_layer)
        .with(logger_layer)
        .init();

    let db = open_db(&args)?;

@@ -200,11 +211,8 @@ async fn main() -> Result<(), anyhow::Error> {
        .layer(CorsLayer::new());

    let listener = TcpListener::bind(&args.bind_address).await?;
    let server = axum::serve(
        listener,
        app.into_make_service_with_connect_info::<SocketAddr>(),
    )
    .into_future();
    let app = app.into_make_service_with_connect_info::<SocketAddr>();
    let server = axum::serve(listener, app).into_future();

    tokio::select! {
        res = server => res.context("failed to run server"),