Skip to content

Commit

Permalink
fix chain metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed May 21, 2024
1 parent 4c0bf18 commit 9a47c88
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
4 changes: 3 additions & 1 deletion docs/src/user-guide/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
37 changes: 27 additions & 10 deletions shotover/src/transforms/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9a47c88

Please sign in to comment.