Skip to content

Commit 64a9bfd

Browse files
authored
refactor(deps): Update metrics to 0.23. Note: 0.22 was a major change… (#189)
1 parent 443b6ce commit 64a9bfd

File tree

14 files changed

+88
-114
lines changed

14 files changed

+88
-114
lines changed

Diff for: rust+wasm/deny.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ ignore = [
5151
"RUSTSEC-2021-0145", # atty on windows only
5252
"RUSTSEC-2023-0071", # Impacts rsa crate, which is only used in dev, see
5353
# https://github.com/RustCrypto/RSA/pull/394 for remediation
54-
"RUSTSEC-2024-0336", # Ignore a DOS issue w/ rustls-0.20.9. This will go
55-
# away when we update opentelemetry-otlp soon.
56-
{ id = "RUSTSEC-2020-0168", reason = "Not planning to force upgrade to mach2 yet" },
5754
{ id = "RUSTSEC-2024-0320", reason = "Not planning to force upgrade to rust-yaml2 yet" },
5855
]
5956
# Threshold for security vulnerabilities, any vulnerability with a CVSS score
@@ -118,6 +115,7 @@ exceptions = [
118115
# this is not a problem for us. See https://github.com/dtolnay/unicode-ident/pull/9/files
119116
{ allow = ["Unicode-DFS-2016"], name = "unicode-ident", version = "*"},
120117
{ allow = ["OpenSSL"], name = "ring", version = "*" },
118+
{ allow = ["OpenSSL"], name = "aws-lc-sys", version = "*" },
121119
{ allow = ["MPL-2.0"], name = "webpki-roots", version = "*"},
122120
]
123121

Diff for: rust+wasm/{{project-name}}/Cargo.axum.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ axum-extra = { version = "0.9", features = ["typed-header"] }
4545
axum-tracing-opentelemetry = { version = "0.19" }
4646
base64 = "0.21"
4747
chrono = { version = "0.4", default-features = false, features = ["clock"] }
48-
config = "0.13"
48+
config = "0.14"
4949
console-subscriber = { version = "0.1", default-features = false, features = [ "parking_lot" ], optional = true }
5050
const_format = "0.2"
5151
futures = "0.3"
5252
headers = "0.4"
5353
http = "1.1"
5454
http-serde = "2.1"
5555
hyper = "1.0.1"
56-
metrics = "0.20"
57-
metrics-exporter-prometheus = "0.11"
58-
metrics-util = { version = "0.14", default-features = true }
56+
metrics = "0.23"
57+
metrics-exporter-prometheus = "0.15"
58+
metrics-util = { version = "0.17", default-features = true }
5959
mime = "0.3"
6060
num_cpus = "1.0"
6161
once_cell = "1.14"

Diff for: rust+wasm/{{project-name}}/src.axum/metrics/process.rs

+9-20
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,20 @@ async fn get_proc_stats(mut sys: System) -> Result<()> {
8080
let disk = proc.disk_usage();
8181

8282
// cpu-usage divided by # of cores.
83-
metrics::gauge!(
84-
"process_cpu_usage_percentage",
85-
f64::from(proc.cpu_usage() / (cpus as f32))
86-
);
83+
metrics::gauge!("process_cpu_usage_percentage")
84+
.set(f64::from(proc.cpu_usage() / (cpus as f32)));
8785

8886
// The docs for sysinfo indicate that `virtual_memory`
8987
// returns in KB, but that is incorrect.
9088
// See this issue: https://github.com/GuillaumeGomez/sysinfo/issues/428#issuecomment-774098021
9189
// And this PR: https://github.com/GuillaumeGomez/sysinfo/pull/430/files
92-
metrics::gauge!(
93-
"process_virtual_memory_bytes",
94-
(proc.virtual_memory()) as f64
95-
);
96-
metrics::gauge!("process_memory_bytes", (proc.memory() * 1_000) as f64);
97-
metrics::gauge!("process_uptime_seconds", proc.run_time() as f64);
98-
metrics::gauge!(
99-
"process_disk_total_written_bytes",
100-
disk.total_written_bytes as f64,
101-
);
102-
metrics::gauge!("process_disk_written_bytes", disk.written_bytes as f64);
103-
metrics::gauge!(
104-
"process_disk_total_read_bytes",
105-
disk.total_read_bytes as f64,
106-
);
107-
metrics::gauge!("process_disk_read_bytes", disk.read_bytes as f64);
90+
metrics::gauge!("process_virtual_memory_bytes").set(proc.virtual_memory() as f64);
91+
metrics::gauge!("process_memory_bytes").set((proc.memory()) as f64);
92+
metrics::gauge!("process_uptime_seconds").set(proc.run_time() as f64);
93+
metrics::gauge!("process_disk_total_written_bytes").set(disk.total_written_bytes as f64);
94+
metrics::gauge!("process_disk_written_bytes").set(disk.written_bytes as f64);
95+
metrics::gauge!("process_disk_total_read_bytes").set(disk.total_read_bytes as f64);
96+
metrics::gauge!("process_disk_read_bytes").set(disk.read_bytes as f64);
10897
} else {
10998
info!(
11099
subject = "metrics.process_collection",

Diff for: rust+wasm/{{project-name}}/src.axum/middleware/client/metrics.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl ReqwestMiddleware for Metrics {
2929
let now = Instant::now();
3030

3131
let url = request.url().clone();
32-
let request_path: String = url.path().to_string();
32+
let request_path = url.path().to_string();
3333
let method = request.method().clone();
3434

3535
let result = next.run(request, extensions).await;
@@ -38,17 +38,21 @@ impl ReqwestMiddleware for Metrics {
3838
let labels = vec![
3939
("client", self.name.to_string()),
4040
("method", method.to_string()),
41-
("request_path", request_path),
41+
("request_path", request_path.clone()),
4242
];
4343

4444
let extended_labels = extend_labels_for_response(labels, &result);
4545

46-
metrics::increment_counter!("client_http_requests_total", &extended_labels);
47-
metrics::histogram!(
48-
"client_http_request_duration_seconds",
49-
latency,
50-
&extended_labels
51-
);
46+
metrics::counter!("client_http_requests_total").increment(1u64);
47+
metrics::counter!("client_http_requests_total", &extended_labels).increment(1u64);
48+
metrics::counter!("client_http_requests_total", "client" => self.name.to_string())
49+
.increment(1u64);
50+
metrics::counter!("client_http_requests_total", "client" => self.name.to_string(), "request_path" => request_path.clone()).increment(1u64);
51+
metrics::histogram!("client_http_request_duration_seconds").record(latency);
52+
metrics::histogram!("client_http_request_duration_seconds", &extended_labels)
53+
.record(latency);
54+
metrics::histogram!("client_http_request_duration_seconds", "client" => self.name.to_string()).record(latency);
55+
metrics::histogram!("client_http_request_duration_seconds", "client" => self.name.to_string(), "request_path" => request_path.clone()).record(latency);
5256

5357
result
5458
}

Diff for: rust+wasm/{{project-name}}/src.axum/middleware/metrics.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@ use std::time::Instant;
99
pub async fn track(req: Request<Body>, next: Next) -> impl IntoResponse {
1010
let start = Instant::now();
1111

12-
let method = req.method().clone();
13-
let path = req.path();
12+
let path = req.path().to_string();
1413

1514
let res = next.run(req).await;
1615
let latency = start.elapsed().as_secs_f64();
17-
let status = res.status().as_u16().to_string();
18-
19-
let labels = [
20-
("method", method.to_string()),
21-
("request_path", path),
22-
("status", status),
23-
];
24-
25-
metrics::increment_counter!("http_requests_total", &labels);
26-
metrics::histogram!("http_request_duration_seconds", latency, &labels);
16+
let status = res.status().as_u16();
2717

18+
metrics::counter!("http_requests_total").increment(1);
19+
metrics::counter!("http_requests_total", "request_path" => path.clone() ).increment(1);
20+
metrics::counter!("http_requests_total", "request_path" => path.clone(), "status" => status.to_string() ).increment(1);
21+
metrics::histogram!("http_request_duration_seconds").record(latency);
22+
metrics::histogram!("http_request_duration_seconds", "request_path" => path.clone())
23+
.record(latency);
24+
metrics::histogram!("http_request_duration_seconds", "request_path" => path.clone(), "status" => status.to_string()).record(latency);
2825
res
2926
}

Diff for: rust+wasm/{{project-name}}/src.axum/middleware/reqwest_retry.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,23 @@ impl<T: RetryPolicy + Send + Sync> RetryTransientMiddleware<T> {
163163
extensions: &mut Extensions,
164164
next: Next<'a>,
165165
) -> Result<Response> {
166-
let url = request.url().clone();
167-
let request_path: String = url.path().to_string();
166+
let request_path = request.url().path().to_string();
168167
let method = request.method().clone();
169168

170169
let result = next.run(request, extensions).await;
171170

172171
let labels = vec![
173172
("client", self.client_name.to_string()),
174173
("method", method.to_string()),
175-
("request_path", request_path),
174+
("request_path", request_path.clone()),
176175
];
177176

178177
let extended_labels = client::metrics::extend_labels_for_response(labels, &result);
179178

180-
metrics::increment_counter!("client_http_requests_retry_total", &extended_labels);
179+
metrics::counter!("client_http_requests_retry_total").increment(1);
180+
metrics::counter!("client_http_requests_retry_total", "request_path" => request_path)
181+
.increment(1);
182+
metrics::counter!("client_http_requests_retry_total", &extended_labels).increment(1);
181183
result
182184
}
183185
}

Diff for: rust+wasm/{{project-name}}/src.axum/tracing_layers/metrics_layer.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,9 @@ where
6868
// Need to sort labels to remain the same across all metrics.
6969
labels.sort_unstable();
7070

71-
metrics::increment_counter!(format!("{name}_total"), &labels);
72-
metrics::histogram!(
73-
format!("{name}_duration_seconds"),
74-
elapsed_secs_f64,
75-
&labels
76-
);
71+
metrics::counter!(format!("{name}_total"), &labels).increment(1);
72+
metrics::histogram!(format!("{name}_duration_seconds"), &labels)
73+
.record(elapsed_secs_f64);
7774

7875
// Remove storage as this is the last layer.
7976
extensions

Diff for: rust/Cargo.axum.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ axum-extra = { version = "0.9", features = ["typed-header"] }
5252
axum-tracing-opentelemetry = { version = "0.19" }
5353
base64 = "0.21"
5454
chrono = { version = "0.4", default-features = false, features = ["clock"] }
55-
config = "0.13"
55+
config = "0.14"
5656
console-subscriber = { version = "0.1", default-features = false, features = [ "parking_lot" ], optional = true }
5757
const_format = "0.2"
5858
futures = "0.3"
5959
headers = "0.4"
6060
http = "1.1"
6161
http-serde = "2.1"
6262
hyper = "1.0.1"
63-
metrics = "0.20"
64-
metrics-exporter-prometheus = "0.11"
65-
metrics-util = { version = "0.14", default-features = true }
63+
metrics = "0.23"
64+
metrics-exporter-prometheus = "0.15"
65+
metrics-util = { version = "0.17", default-features = true }
6666
mime = "0.3"
6767
num_cpus = "1.0"
6868
once_cell = "1.14"

Diff for: rust/deny.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ ignore = [
5151
"RUSTSEC-2021-0145", # atty on windows only
5252
"RUSTSEC-2023-0071", # Impacts rsa crate, which is only used in dev, see
5353
# https://github.com/RustCrypto/RSA/pull/394 for remediation
54-
"RUSTSEC-2024-0336", # Ignore a DOS issue w/ rustls-0.20.9. This will go
55-
# away when we update opentelemetry-otlp soon.
56-
{ id = "RUSTSEC-2020-0168", reason = "Not planning to force upgrade to mach2 yet" },
5754
{ id = "RUSTSEC-2024-0320", reason = "Not planning to force upgrade to rust-yaml2 yet" },
5855
]
5956
# Threshold for security vulnerabilities, any vulnerability with a CVSS score
@@ -118,6 +115,7 @@ exceptions = [
118115
# this is not a problem for us. See https://github.com/dtolnay/unicode-ident/pull/9/files
119116
{ allow = ["Unicode-DFS-2016"], name = "unicode-ident", version = "*"},
120117
{ allow = ["OpenSSL"], name = "ring", version = "*" },
118+
{ allow = ["OpenSSL"], name = "aws-lc-sys", version = "*" },
121119
{ allow = ["MPL-2.0"], name = "webpki-roots", version = "*"},
122120
]
123121

Diff for: rust/src.axum/metrics/process.rs

+9-20
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,20 @@ async fn get_proc_stats(mut sys: System) -> Result<()> {
8080
let disk = proc.disk_usage();
8181

8282
// cpu-usage divided by # of cores.
83-
metrics::gauge!(
84-
"process_cpu_usage_percentage",
85-
f64::from(proc.cpu_usage() / (cpus as f32))
86-
);
83+
metrics::gauge!("process_cpu_usage_percentage")
84+
.set(f64::from(proc.cpu_usage() / (cpus as f32)));
8785

8886
// The docs for sysinfo indicate that `virtual_memory`
8987
// returns in KB, but that is incorrect.
9088
// See this issue: https://github.com/GuillaumeGomez/sysinfo/issues/428#issuecomment-774098021
9189
// And this PR: https://github.com/GuillaumeGomez/sysinfo/pull/430/files
92-
metrics::gauge!(
93-
"process_virtual_memory_bytes",
94-
(proc.virtual_memory()) as f64
95-
);
96-
metrics::gauge!("process_memory_bytes", (proc.memory() * 1_000) as f64);
97-
metrics::gauge!("process_uptime_seconds", proc.run_time() as f64);
98-
metrics::gauge!(
99-
"process_disk_total_written_bytes",
100-
disk.total_written_bytes as f64,
101-
);
102-
metrics::gauge!("process_disk_written_bytes", disk.written_bytes as f64);
103-
metrics::gauge!(
104-
"process_disk_total_read_bytes",
105-
disk.total_read_bytes as f64,
106-
);
107-
metrics::gauge!("process_disk_read_bytes", disk.read_bytes as f64);
90+
metrics::gauge!("process_virtual_memory_bytes").set(proc.virtual_memory() as f64);
91+
metrics::gauge!("process_memory_bytes").set((proc.memory()) as f64);
92+
metrics::gauge!("process_uptime_seconds").set(proc.run_time() as f64);
93+
metrics::gauge!("process_disk_total_written_bytes").set(disk.total_written_bytes as f64);
94+
metrics::gauge!("process_disk_written_bytes").set(disk.written_bytes as f64);
95+
metrics::gauge!("process_disk_total_read_bytes").set(disk.total_read_bytes as f64);
96+
metrics::gauge!("process_disk_read_bytes").set(disk.read_bytes as f64);
10897
} else {
10998
info!(
11099
subject = "metrics.process_collection",

Diff for: rust/src.axum/middleware/client/metrics.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl ReqwestMiddleware for Metrics {
2929
let now = Instant::now();
3030

3131
let url = request.url().clone();
32-
let request_path: String = url.path().to_string();
32+
let request_path = url.path().to_string();
3333
let method = request.method().clone();
3434

3535
let result = next.run(request, extensions).await;
@@ -38,17 +38,21 @@ impl ReqwestMiddleware for Metrics {
3838
let labels = vec![
3939
("client", self.name.to_string()),
4040
("method", method.to_string()),
41-
("request_path", request_path),
41+
("request_path", request_path.clone()),
4242
];
4343

4444
let extended_labels = extend_labels_for_response(labels, &result);
4545

46-
metrics::increment_counter!("client_http_requests_total", &extended_labels);
47-
metrics::histogram!(
48-
"client_http_request_duration_seconds",
49-
latency,
50-
&extended_labels
51-
);
46+
metrics::counter!("client_http_requests_total").increment(1u64);
47+
metrics::counter!("client_http_requests_total", &extended_labels).increment(1u64);
48+
metrics::counter!("client_http_requests_total", "client" => self.name.to_string())
49+
.increment(1u64);
50+
metrics::counter!("client_http_requests_total", "client" => self.name.to_string(), "request_path" => request_path.clone()).increment(1u64);
51+
metrics::histogram!("client_http_request_duration_seconds").record(latency);
52+
metrics::histogram!("client_http_request_duration_seconds", &extended_labels)
53+
.record(latency);
54+
metrics::histogram!("client_http_request_duration_seconds", "client" => self.name.to_string()).record(latency);
55+
metrics::histogram!("client_http_request_duration_seconds", "client" => self.name.to_string(), "request_path" => request_path.clone()).record(latency);
5256

5357
result
5458
}

Diff for: rust/src.axum/middleware/metrics.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@ use std::time::Instant;
99
pub async fn track(req: Request<Body>, next: Next) -> impl IntoResponse {
1010
let start = Instant::now();
1111

12-
let method = req.method().clone();
13-
let path = req.path();
12+
let path = req.path().to_string();
1413

1514
let res = next.run(req).await;
1615
let latency = start.elapsed().as_secs_f64();
17-
let status = res.status().as_u16().to_string();
18-
19-
let labels = [
20-
("method", method.to_string()),
21-
("request_path", path),
22-
("status", status),
23-
];
24-
25-
metrics::increment_counter!("http_requests_total", &labels);
26-
metrics::histogram!("http_request_duration_seconds", latency, &labels);
16+
let status = res.status().as_u16();
2717

18+
metrics::counter!("http_requests_total").increment(1);
19+
metrics::counter!("http_requests_total", "request_path" => path.clone() ).increment(1);
20+
metrics::counter!("http_requests_total", "request_path" => path.clone(), "status" => status.to_string() ).increment(1);
21+
metrics::histogram!("http_request_duration_seconds").record(latency);
22+
metrics::histogram!("http_request_duration_seconds", "request_path" => path.clone())
23+
.record(latency);
24+
metrics::histogram!("http_request_duration_seconds", "request_path" => path.clone(), "status" => status.to_string()).record(latency);
2825
res
2926
}

Diff for: rust/src.axum/middleware/reqwest_retry.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,23 @@ impl<T: RetryPolicy + Send + Sync> RetryTransientMiddleware<T> {
163163
extensions: &mut Extensions,
164164
next: Next<'a>,
165165
) -> Result<Response> {
166-
let url = request.url().clone();
167-
let request_path: String = url.path().to_string();
166+
let request_path = request.url().path().to_string();
168167
let method = request.method().clone();
169168

170169
let result = next.run(request, extensions).await;
171170

172171
let labels = vec![
173172
("client", self.client_name.to_string()),
174173
("method", method.to_string()),
175-
("request_path", request_path),
174+
("request_path", request_path.clone()),
176175
];
177176

178177
let extended_labels = client::metrics::extend_labels_for_response(labels, &result);
179178

180-
metrics::increment_counter!("client_http_requests_retry_total", &extended_labels);
179+
metrics::counter!("client_http_requests_retry_total").increment(1);
180+
metrics::counter!("client_http_requests_retry_total", "request_path" => request_path)
181+
.increment(1);
182+
metrics::counter!("client_http_requests_retry_total", &extended_labels).increment(1);
181183
result
182184
}
183185
}

Diff for: rust/src.axum/tracing_layers/metrics_layer.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,9 @@ where
6868
// Need to sort labels to remain the same across all metrics.
6969
labels.sort_unstable();
7070

71-
metrics::increment_counter!(format!("{name}_total"), &labels);
72-
metrics::histogram!(
73-
format!("{name}_duration_seconds"),
74-
elapsed_secs_f64,
75-
&labels
76-
);
71+
metrics::counter!(format!("{name}_total"), &labels).increment(1);
72+
metrics::histogram!(format!("{name}_duration_seconds"), &labels)
73+
.record(elapsed_secs_f64);
7774

7875
// Remove storage as this is the last layer.
7976
extensions

0 commit comments

Comments
 (0)