Skip to content

Commit

Permalink
[sui-edge-proxy] add filters for certain reqs we aren't interested in (
Browse files Browse the repository at this point in the history
…#20908)

## Description 

the new logging feature was including a lot of requests we're not
interested in

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] gRPC:
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
johnjmartin authored Jan 17, 2025
1 parent aa8bec5 commit a16c942
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions crates/sui-edge-proxy/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ async fn proxy_request(
body_bytes.len(),
peer_type
);
if matches!(peer_type, PeerRole::Read) {
let user_agent = parts
.headers
.get("user-agent")
.and_then(|h| h.to_str().ok());
let is_health_check = matches!(user_agent, Some(ua) if ua.contains("GoogleHC/1.0"));
let is_grafana_agent = matches!(user_agent, Some(ua) if ua.contains("GrafanaAgent"));
let is_grpc = parts
.headers
.get("content-type")
.and_then(|h| h.to_str().ok())
.map(|ct| ct.contains("grpc"))
.unwrap_or(false);

let should_sample = !is_health_check && !is_grafana_agent && !is_grpc;
let rate = state.logging_config.read_request_sample_rate;
if should_sample && rand::thread_rng().gen::<f64>() < rate {
tracing::info!(
headers = ?parts.headers,
body = ?body_bytes,
peer_type = ?peer_type,
"Sampled read request"
);
}
}

let metrics = &state.metrics;
let peer_type_str = peer_type.as_str();
Expand Down Expand Up @@ -210,16 +235,5 @@ async fn proxy_request(
}
}

if matches!(peer_type, PeerRole::Read) {
let rate = state.logging_config.read_request_sample_rate;
if rand::thread_rng().gen::<f64>() < rate {
tracing::info!(
headers = ?parts.headers,
body = ?body_bytes,
peer_type = ?peer_type,
"Sampled read request"
);
}
}
Ok(resp)
}

0 comments on commit a16c942

Please sign in to comment.