diff --git a/docs/src/user-guide/observability.md b/docs/src/user-guide/observability.md index 60802b0c3..d953c3f19 100644 --- a/docs/src/user-guide/observability.md +++ b/docs/src/user-guide/observability.md @@ -10,7 +10,9 @@ This interface will serve Prometheus metrics from `/metrics`. The following metr | `shotover_chain_total_count` | `chain` | [counter](#counter) | Counts the amount of times `chain` is used | | `shotover_chain_failures_count` | `chain` | [counter](#counter) | Counts the amount of times `chain` fails | | `shotover_chain_latency_seconds` | `chain` | [histogram](#histogram) | The latency for running `chain` | -| `shotover_chain_messages_per_batch_count` | `chain` | [histogram](#histogram) | The number of messages in each batch passing through `chain`. | +| `shotover_chain_requests_per_request_batch_count` | `chain` | [histogram](#histogram) | The number of requests in each batch passing through `chain`. | +| `shotover_chain_run_requests_count` | `chain` | [histogram](#histogram) | The number of requests in each chain run of `chain`. | +| `shotover_chain_run_responses_count` | `chain` | [histogram](#histogram) | The number of responses in each chain run of `chain`. | | `shotover_available_connections_count` | `source` | [gauge](#gauge) | The number of connections currently connected to `source` | | `shotover_source_to_sink_latency_seconds` | `sink` | [histogram](#histogram) | The milliseconds between reading a request from a source TCP connection and writing it to a sink TCP connection | | `shotover_sink_to_source_latency_seconds` | `source` | [histogram](#histogram) | The milliseconds between reading a response from a sink TCP connection and writing it to a source TCP connection | diff --git a/shotover/src/transforms/chain.rs b/shotover/src/transforms/chain.rs index dc3fca2d9..901150d90 100644 --- a/shotover/src/transforms/chain.rs +++ b/shotover/src/transforms/chain.rs @@ -58,7 +58,9 @@ pub struct TransformChain { chain_total: Counter, chain_failures: Counter, - chain_batch_size: Histogram, + chain_request_batch_size: Histogram, + chain_run_requests_count: Histogram, + chain_run_responses_count: Histogram, chain_latency_seconds: Histogram, } @@ -161,11 +163,17 @@ impl TransformChain { let start = Instant::now(); wrapper.reset(&mut self.chain); - self.chain_batch_size.record(wrapper.requests.len() as f64); + let requests_len = wrapper.requests.len() as f64; + if !wrapper.requests.is_empty() { + self.chain_request_batch_size.record(requests_len); + } + self.chain_run_requests_count.record(requests_len); + let result = wrapper.call_next_transform().await; self.chain_total.increment(1); - if result.is_err() { - self.chain_failures.increment(1); + match &result { + Ok(result) => self.chain_run_responses_count.record(result.len() as f64), + Err(_) => self.chain_failures.increment(1), } self.chain_latency_seconds.record(start.elapsed()); @@ -216,7 +224,9 @@ pub struct TransformChainBuilder { chain_total: Counter, chain_failures: Counter, - chain_batch_size: Histogram, + chain_request_batch_size: Histogram, + chain_run_responses_count: Histogram, + chain_run_requests_count: Histogram, } impl TransformChainBuilder { @@ -230,18 +240,23 @@ impl TransformChainBuilder { } ).collect(); - let chain_batch_size = - histogram!("shotover_chain_messages_per_batch_count", "chain" => name); + let chain_request_batch_size = + histogram!("shotover_chain_requests_per_request_batch_count", "chain" => name); + let chain_run_requests_count = + histogram!("shotover_chain_run_requests_count", "chain" => name); + let chain_run_responses_count = + histogram!("shotover_chain_run_responses_count", "chain" => name); let chain_total = counter!("shotover_chain_total_count", "chain" => name); let chain_failures = counter!("shotover_chain_failures_count", "chain" => name); - // Cant register shotover_chain_latency_seconds because a unique one is created for each client ip address TransformChainBuilder { name, chain, chain_total, chain_failures, - chain_batch_size, + chain_request_batch_size, + chain_run_requests_count, + chain_run_responses_count, } } @@ -371,7 +386,9 @@ impl TransformChainBuilder { chain, chain_total: self.chain_total.clone(), chain_failures: self.chain_failures.clone(), - chain_batch_size: self.chain_batch_size.clone(), + chain_request_batch_size: self.chain_request_batch_size.clone(), + chain_run_responses_count: self.chain_run_responses_count.clone(), + chain_run_requests_count: self.chain_run_requests_count.clone(), chain_latency_seconds: histogram!( "shotover_chain_latency_seconds", "chain" => self.name,