Skip to content

Commit

Permalink
Reduce to 2 metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed May 21, 2024
1 parent 9a47c88 commit 0fcade0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
5 changes: 2 additions & 3 deletions docs/src/user-guide/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ 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_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_chain_requests_batch_size` | `chain` | [histogram](#histogram) | The number of requests in each request batch passing through `chain`. |
| `shotover_chain_responses_batch_size` | `chain` | [histogram](#histogram) | The number of responses in each response batch passing through `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
42 changes: 20 additions & 22 deletions shotover/src/transforms/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ pub struct TransformChain {

chain_total: Counter,
chain_failures: Counter,
chain_request_batch_size: Histogram,
chain_run_requests_count: Histogram,
chain_run_responses_count: Histogram,
chain_requests_batch_size: Histogram,
chain_responses_batch_size: Histogram,
chain_latency_seconds: Histogram,
}

Expand Down Expand Up @@ -163,16 +162,20 @@ impl TransformChain {
let start = Instant::now();
wrapper.reset(&mut self.chain);

let requests_len = wrapper.requests.len() as f64;
if !wrapper.requests.is_empty() {
self.chain_request_batch_size.record(requests_len);
self.chain_requests_batch_size
.record(wrapper.requests.len() as f64);
}
self.chain_run_requests_count.record(requests_len);

let result = wrapper.call_next_transform().await;
self.chain_total.increment(1);
match &result {
Ok(result) => self.chain_run_responses_count.record(result.len() as f64),
Ok(responses) => {
if !responses.is_empty() {
self.chain_responses_batch_size
.record(responses.len() as f64);
}
}
Err(_) => self.chain_failures.increment(1),
}

Expand Down Expand Up @@ -224,9 +227,8 @@ pub struct TransformChainBuilder {

chain_total: Counter,
chain_failures: Counter,
chain_request_batch_size: Histogram,
chain_run_responses_count: Histogram,
chain_run_requests_count: Histogram,
chain_responses_batch_size: Histogram,
chain_requests_batch_size: Histogram,
}

impl TransformChainBuilder {
Expand All @@ -240,12 +242,10 @@ impl TransformChainBuilder {
}
).collect();

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_requests_batch_size =
histogram!("shotover_chain_requests_batch_size", "chain" => name);
let chain_responses_batch_size =
histogram!("shotover_chain_responses_batch_size", "chain" => name);
let chain_total = counter!("shotover_chain_total_count", "chain" => name);
let chain_failures = counter!("shotover_chain_failures_count", "chain" => name);

Expand All @@ -254,9 +254,8 @@ impl TransformChainBuilder {
chain,
chain_total,
chain_failures,
chain_request_batch_size,
chain_run_requests_count,
chain_run_responses_count,
chain_requests_batch_size,
chain_responses_batch_size,
}
}

Expand Down Expand Up @@ -386,9 +385,8 @@ impl TransformChainBuilder {
chain,
chain_total: self.chain_total.clone(),
chain_failures: self.chain_failures.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_requests_batch_size: self.chain_requests_batch_size.clone(),
chain_responses_batch_size: self.chain_responses_batch_size.clone(),
chain_latency_seconds: histogram!(
"shotover_chain_latency_seconds",
"chain" => self.name,
Expand Down

0 comments on commit 0fcade0

Please sign in to comment.