Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use span instead of print log_key directly #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore: use span instead of print log_key directly
Signed-off-by: STRRL <[email protected]>
  • Loading branch information
STRRL committed Oct 14, 2022
commit dda50c7c7ddb358f364f1a84e2ea98b7e1b091ad
20 changes: 14 additions & 6 deletions chaos-tproxy-proxy/src/proxy/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ pub async fn serve_https(
stream.peer_addr()?,
stream.local_addr()?
);

let span = span!(Level::TRACE, "TLS Stream", "{}", &log_key);
let _guard = span.enter();

let mut tls_stream = acceptor.accept(stream).await?;
loop {
let (r, parts) = Http::new()
Expand Down Expand Up @@ -214,21 +218,24 @@ impl HttpService {

async fn handle(self, mut request: Request<Body>) -> Result<Response<Body>> {
let log_key = format!("{{remote = {}, target = {} }}", self.remote, self.target);
debug!("{} : Proxy is handling http request", log_key);
let span = span!(Level::TRACE, "handle HTTP Request", "{}", &log_key);
let _guard = span.enter();
debug!("Proxy is handling http request");

let role_ok = self.role_ok();
let request_rules: Vec<_> = self
.config
.rules
.iter()
.filter(|rule| {
role_ok && matches!(rule.target, Target::Request)
role_ok
&& matches!(rule.target, Target::Request)
&& select_request(self.target.port(), &request, &rule.selector)
})
.collect();

for rule in request_rules {
debug!("{} : request matched, rule({:?})", log_key, rule);
debug!("request matched, rule({:?})", rule);
request = apply_request_action(request, &rule.actions).await?;
}

Expand Down Expand Up @@ -279,7 +286,7 @@ impl HttpService {
let mut response = match rsp_fut.await {
Ok(resp) => resp,
Err(err) => {
error!("{} : fail to forward request: {}", log_key, err);
error!("fail to forward request: {}", err);
Response::builder()
.status(StatusCode::BAD_GATEWAY)
.body(Body::empty())?
Expand All @@ -291,7 +298,8 @@ impl HttpService {
.rules
.iter()
.filter(|rule| {
role_ok && matches!(rule.target, Target::Response)
role_ok
&& matches!(rule.target, Target::Response)
&& select_response(
self.target.port(),
&uri,
Expand All @@ -304,7 +312,7 @@ impl HttpService {
.collect();

for rule in response_rules {
debug!("{} : response matched", log_key);
debug!("response matched");
response = apply_response_action(response, &rule.actions).await?;
}
Ok(response)
Expand Down