Skip to content

Commit 53f15ad

Browse files
committed
Remove lazy-static, s/example_counter/request_counter
Signed-off-by: Adam Chalmers <[email protected]>
1 parent 5021289 commit 53f15ad

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,10 @@ tide = "0.16"
3636
actix-web = "4"
3737
tokio = { version = "1", features = ["rt-multi-thread", "net", "macros", "signal"] }
3838
hyper = { version = "0.14.16", features = ["server", "http1", "tcp"] }
39-
lazy_static = "1.4"
4039

4140
[build-dependencies]
4241
prost-build = { version = "0.9.0", optional = true }
4342

44-
[[example]]
45-
name = "hyper"
46-
crate-type = ["bin"]
47-
4843
[[bench]]
4944
name = "family"
5045
harness = false

examples/hyper.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,34 @@ use std::{
99
net::{IpAddr, Ipv4Addr, SocketAddr},
1010
pin::Pin,
1111
sync::Arc,
12-
time::Duration,
1312
};
1413
use tokio::signal::unix::{signal, SignalKind};
1514

16-
lazy_static::lazy_static! {
17-
pub static ref EXAMPLE_COUNTER: Counter = Counter::default();
18-
}
19-
2015
#[tokio::main]
2116
async fn main() {
22-
let registry = register_metrics();
17+
let request_counter = Counter::default();
18+
19+
let registry = register_metrics(&request_counter);
2320

2421
// Spawn a server to serve the OpenMetrics endpoint.
2522
let metrics_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8001);
26-
tokio::task::spawn(start_server(metrics_addr, registry));
27-
28-
loop {
29-
EXAMPLE_COUNTER.inc();
30-
tokio::time::sleep(Duration::from_secs(1)).await;
31-
}
23+
tokio::task::spawn(start_metrics_server(metrics_addr, registry));
3224
}
3325

34-
pub fn register_metrics() -> Registry {
26+
pub fn register_metrics(example_counter: &Counter) -> Registry {
3527
let mut registry = <Registry>::with_prefix("tokio_hyper_example");
3628

3729
registry.register(
38-
"example_counter",
39-
"An example counter that will get incremented automatically",
40-
Box::new(EXAMPLE_COUNTER.clone()),
30+
"requests",
31+
"How many requests the application has received",
32+
Box::new(example_counter.clone()),
4133
);
4234

4335
registry
4436
}
4537

4638
/// Start a HTTP server to report metrics.
47-
pub async fn start_server(metrics_addr: SocketAddr, registry: Registry) {
39+
pub async fn start_metrics_server(metrics_addr: SocketAddr, registry: Registry) {
4840
let mut shutdown_stream = signal(SignalKind::terminate()).unwrap();
4941

5042
eprintln!("Starting metrics server on {metrics_addr}");

0 commit comments

Comments
 (0)