Skip to content

Commit 24c8646

Browse files
committed
Remove lazy_static dependency.
1 parent 58ad101 commit 24c8646

File tree

5 files changed

+42
-38
lines changed

5 files changed

+42
-38
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
prost = "0.13"
3232
prost-types = "0.13"
3333
prometheus-client = "0.23"
34-
lazy_static = "1.5"
3534
anyhow = "1.0"
3635

3736
[package.metadata.deb]

src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#[macro_use]
2-
extern crate lazy_static;
3-
#[macro_use]
42
extern crate log;
53
#[macro_use]
64
extern crate anyhow;

src/metrics.rs

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::io::{Read, Write};
22
use std::net::{TcpListener, TcpStream};
3-
use std::sync::RwLock;
3+
use std::sync::{LazyLock, RwLock};
44
use std::thread;
55

6-
use prometheus_client::encoding::text::encode;
76
use prometheus_client::encoding::EncodeLabelSet;
7+
use prometheus_client::encoding::text::encode;
88
use prometheus_client::metrics::counter::Counter;
99
use prometheus_client::metrics::family::Family;
1010
use prometheus_client::registry::{Metric, Registry};
@@ -15,34 +15,43 @@ struct UdpLabels {
1515
r#type: String,
1616
}
1717

18-
lazy_static! {
19-
static ref REGISTRY: RwLock<Registry> = RwLock::new(<Registry>::default());
20-
21-
// UDP sent
22-
static ref UDP_SENT_COUNT: Family<UdpLabels, Counter> = {
23-
let counter = Family::<UdpLabels, Counter>::default();
24-
register("udp_sent_count", "Number of UDP datagrams sent", counter.clone());
25-
counter
26-
};
27-
static ref UDP_SENT_BYTES: Family<UdpLabels, Counter> = {
28-
let counter = Family::<UdpLabels, Counter>::default();
29-
register("udp_sent_bytes", "Number of bytes sent over UDP", counter.clone());
30-
counter
31-
};
32-
33-
34-
// UDP received
35-
static ref UDP_RECEIVED_COUNT: Family<UdpLabels, Counter> = {
36-
let counter = Family::<UdpLabels, Counter>::default();
37-
register("udp_received_count", "Number of UDP datagrams received", counter.clone());
38-
counter
39-
};
40-
static ref UDP_RECEIVED_BYTES: Family<UdpLabels, Counter> = {
41-
let counter = Family::<UdpLabels, Counter>::default();
42-
register("udp_received_bytes", "Number of bytes received over UDP", counter.clone());
43-
counter
44-
};
45-
}
18+
static REGISTRY: LazyLock<RwLock<Registry>> = LazyLock::new(|| RwLock::new(Registry::default()));
19+
static UDP_SENT_COUNT: LazyLock<Family<UdpLabels, Counter>> = LazyLock::new(|| {
20+
let counter = Family::<UdpLabels, Counter>::default();
21+
register(
22+
"udp_sent_count",
23+
"Number of UDP datagrams sent",
24+
counter.clone(),
25+
);
26+
counter
27+
});
28+
static UDP_SENT_BYTES: LazyLock<Family<UdpLabels, Counter>> = LazyLock::new(|| {
29+
let counter = Family::<UdpLabels, Counter>::default();
30+
register(
31+
"udp_sent_bytes",
32+
"Number of bytes sent over UDP",
33+
counter.clone(),
34+
);
35+
counter
36+
});
37+
static UDP_RECEIVED_COUNT: LazyLock<Family<UdpLabels, Counter>> = LazyLock::new(|| {
38+
let counter = Family::<UdpLabels, Counter>::default();
39+
register(
40+
"udp_received_count",
41+
"Number of UDP datagrams received",
42+
counter.clone(),
43+
);
44+
counter
45+
});
46+
static UDP_RECEIVED_BYTES: LazyLock<Family<UdpLabels, Counter>> = LazyLock::new(|| {
47+
let counter = Family::<UdpLabels, Counter>::default();
48+
register(
49+
"udp_received_bytes",
50+
"Number of bytes received over UDP",
51+
counter.clone(),
52+
);
53+
counter
54+
});
4655

4756
fn register(name: &str, help: &str, metric: impl Metric) {
4857
let mut registry_w = REGISTRY.write().unwrap();

src/socket.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use std::sync::Mutex;
1+
use std::sync::{LazyLock, Mutex};
22

3-
lazy_static! {
4-
pub static ref ZMQ_CONTEXT: Mutex<zmq::Context> = Mutex::new(zmq::Context::new());
5-
}
3+
pub static ZMQ_CONTEXT: LazyLock<Mutex<zmq::Context>> =
4+
LazyLock::new(|| Mutex::new(zmq::Context::new()));

0 commit comments

Comments
 (0)