Skip to content

Commit

Permalink
pelikan-net: make metrics opt-in (#130)
Browse files Browse the repository at this point in the history
Changes the way metrics are included in pelikan-net, moving them
behind a feature flag to make them opt-in.
  • Loading branch information
brayniac authored Jul 2, 2024
1 parent d4ac78c commit 13a6cd8
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 133 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.3.1"
version = "0.3.2"
edition = "2021"
homepage = "https://pelikan.io"
repository = "https://github.com/pelikan-io/pelikan"
Expand Down Expand Up @@ -50,7 +50,7 @@ bytes = "1.5.0"
clap = "4.4.6"
clocksource = "0.8.1"
crossbeam-channel = "0.5.8"
datatier = { path = "./src/storage/datatier", version = "0.1.0"}
datatier = { path = "./src/storage/datatier", version = "0.1.0" }
httparse = "1.8.0"
libc = "0.2.149"
log = "0.4.20"
Expand All @@ -62,7 +62,7 @@ nom = "7.1.3"
openssl = "0.10.64"
openssl-sys = "0.9.102"
parking_lot = "0.12.1"
pelikan-net = { path = "./src/net", version = "0.3.0", default-features = false }
pelikan-net = { path = "./src/net", version = "0.4.0" }
phf = "0.11.2"
proc-macro2 = "1.0.69"
quote = "1.0.33"
Expand Down
3 changes: 1 addition & 2 deletions src/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ license = { workspace = true }
boring = { workspace = true, optional = true }
clocksource = { workspace = true }
metriken = { workspace = true }
pelikan-net = { workspace = true, default-features = false }
pelikan-net = { workspace = true }
ringlog = { workspace = true }
serde = { workspace = true, features = ["derive"] }

[features]
default = ["boringssl"]
boringssl = ["dep:boring", "pelikan-net/boringssl"]
6 changes: 5 additions & 1 deletion src/core/proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ crossbeam-channel = { workspace = true }
entrystore = { path = "../../entrystore" }
logger = { path = "../../logger" }
metriken = { workspace = true }
pelikan-net = { workspace = true }
pelikan-net = { workspace = true, features = ["metrics"] }
protocol-admin = { path = "../../protocol/admin" }
protocol-common = { path = "../../protocol/common" }
session = { path = "../../session" }
slab = { workspace = true }
switchboard = { workspace = true }

[features]
boringssl = ["pelikan-net/boringssl"]
openssl = ["pelikan-net/openssl"]
6 changes: 5 additions & 1 deletion src/core/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ entrystore = { path = "../../entrystore" }
libc = {workspace = true}
logger = { path = "../../logger" }
metriken = { workspace = true }
pelikan-net = { workspace = true }
pelikan-net = { workspace = true, features = ["metrics"] }
protocol-admin = { path = "../../protocol/admin" }
protocol-common = { path = "../../protocol/common" }
session = { path = "../../session" }
signal-hook = {workspace = true}
slab = { workspace = true }
switchboard = { workspace = true }

[features]
boringssl = ["pelikan-net/boringssl"]
openssl = ["pelikan-net/openssl"]
6 changes: 3 additions & 3 deletions src/net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "pelikan-net"
description = "Pelikan project's networking abstractions for non-blocking event loops"
authors = ["Brian Martin <[email protected]>"]
version = "0.3.0"
version = "0.4.0"

edition = { workspace = true }
homepage = { workspace = true }
Expand All @@ -15,12 +15,12 @@ boring-sys = { workspace = true, optional = true }
foreign-types-shared_03 = { package = "foreign-types-shared", version = "0.3.1" }
foreign-types-shared_01 = { package = "foreign-types-shared", version = "0.1.1" }
libc = { workspace = true }
metriken = { workspace = true }
metriken = { workspace = true, optional = true }
mio = { workspace = true, features = ["os-poll", "net"] }
openssl = { workspace = true, optional = true }
openssl-sys = { workspace = true, optional = true }

[features]
default = ["boringssl"]
boringssl = ["boring", "boring-sys"]
metrics = ["metriken"]
openssl = ["dep:openssl", "openssl-sys", "openssl/vendored"]
91 changes: 18 additions & 73 deletions src/net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,82 +24,27 @@ pub mod event {

pub use mio::*;

use core::fmt::Debug;
use core::ops::Deref;
use std::io::{Error, ErrorKind, Read, Write};
use std::net::{SocketAddr, ToSocketAddrs};

use metriken::*;

type Result<T> = std::io::Result<T>;

// stats

#[metric(
name = "tcp_accept",
description = "number of TCP streams passively opened with accept"
)]
pub static TCP_ACCEPT: Counter = Counter::new();

#[metric(
name = "tcp_connect",
description = "number of TCP streams actively opened with connect"
)]
pub static TCP_CONNECT: Counter = Counter::new();

#[metric(name = "tcp_close", description = "number of TCP streams closed")]
pub static TCP_CLOSE: Counter = Counter::new();
#[cfg(feature = "metrics")]
mod metrics;

#[metric(
name = "tcp_conn_curr",
description = "current number of open TCP streams"
)]
pub static TCP_CONN_CURR: Gauge = Gauge::new();
#[cfg(feature = "metrics")]
pub use metrics::*;

#[metric(
name = "tcp_recv_byte",
description = "number of bytes received on TCP streams"
)]
pub static TCP_RECV_BYTE: Counter = Counter::new();

#[metric(
name = "tcp_send_byte",
description = "number of bytes sent on TCP streams"
)]
pub static TCP_SEND_BYTE: Counter = Counter::new();

#[metric(name = "stream_accept", description = "number of calls to accept")]
pub static STREAM_ACCEPT: Counter = Counter::new();

#[metric(
name = "stream_accept_ex",
description = "number of times calling accept resulted in an exception"
)]
pub static STREAM_ACCEPT_EX: Counter = Counter::new();

#[metric(name = "stream_close", description = "number of streams closed")]
pub static STREAM_CLOSE: Counter = Counter::new();
#[cfg(feature = "metrics")]
macro_rules! metric {
{ $( $tt:tt )* } => { $( $tt )* }
}

#[metric(
name = "stream_handshake",
description = "number of times stream handshaking was attempted"
)]
pub static STREAM_HANDSHAKE: Counter = Counter::new();
#[cfg(not(feature = "metrics"))]
macro_rules! metric {
{ $( $tt:tt)* } => {}
}

#[metric(
name = "stream_handshake_ex",
description = "number of exceptions while handshaking"
)]
pub static STREAM_HANDSHAKE_EX: Counter = Counter::new();
pub(crate) use metric;

#[metric(
name = "stream_shutdown",
description = "number of streams gracefully shutdown"
)]
pub static STREAM_SHUTDOWN: Counter = Counter::new();
use core::fmt::Debug;
use core::ops::Deref;
use std::io::{Error, ErrorKind, Read, Write};
use std::net::{SocketAddr, ToSocketAddrs};

#[metric(
name = "stream_shutdown_ex",
description = "number of exceptions while attempting to gracefully shutdown a stream"
)]
pub static STREAM_SHUTDOWN_EX: Counter = Counter::new();
type Result<T> = std::io::Result<T>;
Loading

0 comments on commit 13a6cd8

Please sign in to comment.