Skip to content

Commit 183713b

Browse files
committed
Same for bytes_written
1 parent eb20127 commit 183713b

File tree

12 files changed

+55
-11
lines changed

12 files changed

+55
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
## Fixed
9-
- Component name labels have been removed from the `bytes_received` metric to
10-
fix egress throughput optimization goal analysis.
9+
- Labels have been removed from the `bytes_received` and `bytes_written` metrics
10+
to fix some scenarios where they could break optimization goal analysis.
1111
## Changed
1212
- Lading now built with edition 2024
1313

lading/src/generator/file_gen/logrotate.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,11 @@ async fn write_bytes(
411411
fp.write_all(&blk.bytes)
412412
.await
413413
.map_err(|err| Error::IoWriteAll { err })?;
414-
counter!("bytes_written", labels).increment(total_bytes);
414+
415+
// This metric must be written with a single context or it will crash
416+
// analysis. The simple way to accomplish that is to attach no labels to
417+
// it.
418+
counter!("bytes_written").increment(total_bytes);
415419
*total_bytes_written += total_bytes;
416420
}
417421

lading/src/generator/file_gen/logrotate_fs/model.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ impl File {
198198
let diff = now.saturating_sub(self.modified_tick);
199199
let bytes_accum = diff.saturating_mul(self.bytes_per_tick);
200200

201+
// This metric must be written with a single context or it will crash
202+
// analysis. The simple way to accomplish that is to attach no labels to
203+
// it.
201204
counter!("bytes_written").increment(bytes_accum);
205+
202206
self.bytes_written = self.bytes_written.saturating_add(bytes_accum);
203207
self.modified_tick = now;
204208
self.status_tick = now;

lading/src/generator/file_gen/traditional.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ impl Child {
269269

270270
{
271271
fp.write_all(&blk.bytes).await?;
272+
273+
// This metric must be written with a single context or
274+
// it will crash analysis. The simple way to accomplish
275+
// that is to attach no labels to it.
272276
counter!("bytes_written").increment(total_bytes);
273277
total_bytes_written += total_bytes;
274278
}

lading/src/generator/grpc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,11 @@ impl Grpc {
289289

290290
match res {
291291
Ok(res) => {
292-
counter!("bytes_written", &self.metric_labels).increment(block_length as u64);
292+
// This metric must be written with a single context
293+
// or it will crash analysis. The simple way to
294+
// accomplish that is to attach no labels to it.
295+
counter!("bytes_written").increment(block_length as u64);
296+
293297
counter!("request_ok", &self.metric_labels).increment(1);
294298
counter!("response_bytes", &self.metric_labels).increment(res.into_inner() as u64);
295299
}

lading/src/generator/http.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ impl Http {
236236
counter!("requests_sent", &labels).increment(1);
237237
match client.request(request).await {
238238
Ok(response) => {
239-
counter!("bytes_written", &labels).increment(block_length as u64);
239+
// This metric must be written with a single
240+
// context or it will crash analysis. The simple
241+
// way to accomplish that is to attach no labels
242+
// to it.
243+
counter!("bytes_written").increment(block_length as u64);
240244
let status = response.status();
241245
let mut status_labels = labels.clone();
242246
status_labels

lading/src/generator/passthru_file.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ impl PassthruFile {
178178
let blk = rcv.next().await.expect("failed to advance through the blocks"); // actually advance through the blocks
179179
match current_file.write_all(&blk.bytes).await {
180180
Ok(()) => {
181-
counter!("bytes_written", &self.metric_labels).increment(u64::from(blk.total_bytes.get()));
181+
// This metric must be written with a single context
182+
// or it will crash analysis. The simple way to
183+
// accomplish that is to attach no labels to it.
184+
counter!("bytes_written").increment(u64::from(blk.total_bytes.get()));
182185
}
183186
Err(err) => {
184187
warn!("write failed: {}", err);

lading/src/generator/splunk_hec.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,11 @@ where
344344
match tm {
345345
Ok(tm) => match tm {
346346
Ok(response) => {
347-
counter!("bytes_written", &labels).increment(block_length as u64);
347+
// This metric must be written with a single context or
348+
// it will crash analysis. The simple way to accomplish
349+
// that is to attach no labels to it.
350+
counter!("bytes_written").increment(block_length as u64);
351+
348352
let (parts, body) = response.into_parts();
349353
let status = parts.status;
350354
let mut status_labels = labels.clone();

lading/src/generator/tcp.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ impl Tcp {
181181
let blk = rcv.next().await.expect("failed to advance through the blocks"); // actually advance through the blocks
182182
match connection.write_all(&blk.bytes).await {
183183
Ok(()) => {
184-
counter!("bytes_written", &self.metric_labels).increment(u64::from(blk.total_bytes.get()));
184+
// This metric must be written with a single context
185+
// or it will crash analysis. The simple way to
186+
// accomplish that is to attach no labels to it.
187+
counter!("bytes_written").increment(u64::from(blk.total_bytes.get()));
188+
185189
counter!("packets_sent", &self.metric_labels).increment(1);
186190
}
187191
Err(err) => {

lading/src/generator/udp.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ impl Udp {
189189
let blk = rcv.next().await.expect("failed to advance through the blocks"); // actually advance through the blocks
190190
match sock.send_to(&blk.bytes, self.addr).await {
191191
Ok(bytes) => {
192-
counter!("bytes_written", &self.metric_labels).increment(bytes as u64);
192+
// This metric must be written with a single context
193+
// or it will crash analysis. The simple way to
194+
// accomplish that is to attach no labels to it.
195+
counter!("bytes_written").increment(bytes as u64);
196+
193197
counter!("packets_sent", &self.metric_labels).increment(1);
194198
connection = Some(sock);
195199
}

0 commit comments

Comments
 (0)