Skip to content

Commit 4d02469

Browse files
committed
review: put connection id into logs where it's missing
1 parent 74a2149 commit 4d02469

File tree

2 files changed

+105
-88
lines changed

2 files changed

+105
-88
lines changed

crates/rproxy/src/server/proxy/http/proxy.rs

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ where
314314

315315
let info = ProxyHttpRequestInfo::new(&clnt_req, clnt_req.conn_data::<ConnectionGuard>());
316316

317-
let id = info.id;
318-
let connection_id = info.connection_id;
317+
let req_id = info.req_id;
318+
let conn_id = info.conn_id;
319319

320320
let bknd_req = this.backend.new_backend_request(&info);
321321
let bknd_req_body = ProxyHttpRequestBody::new(
@@ -331,8 +331,8 @@ where
331331
Err(err) => {
332332
warn!(
333333
proxy = P::name(),
334-
request_id = %id,
335-
connection_id = %connection_id,
334+
request_id = %req_id,
335+
connection_id = %conn_id,
336336
worker_id = %this.id,
337337
backend_url = %this.backend.url,
338338
error = ?err,
@@ -354,7 +354,8 @@ where
354354
let preallocate = this.shared.config().prealloacated_response_buffer_size();
355355
let bknd_res_body = ProxyHttpResponseBody::new(
356356
this,
357-
id,
357+
req_id,
358+
conn_id,
358359
status,
359360
bknd_res.headers().clone(),
360361
bknd_res.into_stream(),
@@ -366,25 +367,26 @@ where
366367
}
367368

368369
fn postprocess_client_request(&self, req: ProxiedHttpRequest) {
369-
let id = req.info.id;
370-
let connection_id = req.info.connection_id;
370+
let id = req.info.req_id;
371+
let conn_id = req.info.conn_id;
371372

372373
if self.requests.insert_sync(id, req).is_err() {
373374
error!(
374375
proxy = P::name(),
375376
request_id = %id,
376-
connection_id = %connection_id,
377+
connection_id = %conn_id,
377378
worker_id = %self.id,
378379
"Duplicate request id",
379380
);
380381
};
381382
}
382383

383384
fn postprocess_backend_response(&self, bknd_res: ProxiedHttpResponse) {
384-
let Some((_, clnt_req)) = self.requests.remove_sync(&bknd_res.info.id) else {
385+
let Some((_, clnt_req)) = self.requests.remove_sync(&bknd_res.info.req_id) else {
385386
error!(
386387
proxy = P::name(),
387-
request_id = %bknd_res.info.id,
388+
request_id = %bknd_res.info.req_id,
389+
connection_id = %bknd_res.info.conn_id,
388390
worker_id = %self.id,
389391
"Proxied http response for unmatching request",
390392
);
@@ -451,8 +453,8 @@ where
451453
Err(err) => {
452454
warn!(
453455
proxy = P::name(),
454-
request_id = %clnt_req.info.id,
455-
connection_id = %clnt_req.info.connection_id,
456+
request_id = %clnt_req.info.req_id,
457+
connection_id = %clnt_req.info.conn_id,
456458
worker_id = %worker_id,
457459
error = ?err,
458460
"Failed to parse json-rpc request",
@@ -518,8 +520,8 @@ where
518520

519521
info!(
520522
proxy = P::name(),
521-
request_id = %req.info.id,
522-
connection_id = %req.info.connection_id,
523+
request_id = %req.info.req_id,
524+
connection_id = %req.info.conn_id,
523525
worker_id = %worker_id,
524526
jrpc_method = %jrpc.method_enriched(),
525527
http_status = res.status(),
@@ -559,8 +561,8 @@ where
559561

560562
info!(
561563
proxy = P::name(),
562-
request_id = %req.info.id,
563-
connection_id = %req.info.connection_id,
564+
request_id = %req.info.req_id,
565+
connection_id = %req.info.conn_id,
564566
worker_id = %worker_id,
565567
jrpc_method = %req.info.jrpc_method_enriched,
566568
http_status = res.status(),
@@ -1001,7 +1003,8 @@ where
10011003
BodySize::None | BodySize::Stream => 0,
10021004
};
10031005
let info = ProxyHttpResponseInfo::new(
1004-
clnt_req.info.id,
1006+
clnt_req.info.req_id,
1007+
clnt_req.info.conn_id,
10051008
bknd_res.status(),
10061009
bknd_res.headers().clone(),
10071010
);
@@ -1021,8 +1024,8 @@ where
10211024
Err(err) => {
10221025
warn!(
10231026
proxy = P::name(),
1024-
request_id = %clnt_req.info.id,
1025-
connection_id = %clnt_req.info.connection_id,
1027+
request_id = %clnt_req.info.req_id,
1028+
connection_id = %clnt_req.info.conn_id,
10261029
error = ?err,
10271030
"Failed to mirror a request",
10281031
);
@@ -1037,8 +1040,8 @@ where
10371040
Err(err) => {
10381041
warn!(
10391042
proxy = P::name(),
1040-
request_id = %clnt_req.info.id,
1041-
connection_id = %clnt_req.info.connection_id,
1043+
request_id = %clnt_req.info.req_id,
1044+
connection_id = %clnt_req.info.conn_id,
10421045
error = ?err,
10431046
"Failed to mirror a request",
10441047
);
@@ -1058,8 +1061,8 @@ where
10581061

10591062
#[derive(Clone)]
10601063
pub(crate) struct ProxyHttpRequestInfo {
1061-
id: Uuid,
1062-
connection_id: Uuid,
1064+
req_id: Uuid,
1065+
conn_id: Uuid,
10631066
remote_addr: Option<String>,
10641067
method: Method,
10651068
path: String,
@@ -1131,8 +1134,8 @@ impl ProxyHttpRequestInfo {
11311134
};
11321135

11331136
Self {
1134-
id: Uuid::now_v7(),
1135-
connection_id: Uuid::now_v7(),
1137+
req_id: Uuid::now_v7(),
1138+
conn_id: Uuid::now_v7(),
11361139
remote_addr,
11371140
method: req.method().clone(),
11381141
path,
@@ -1144,12 +1147,12 @@ impl ProxyHttpRequestInfo {
11441147

11451148
#[inline]
11461149
pub(crate) fn id(&self) -> Uuid {
1147-
self.id
1150+
self.req_id
11481151
}
11491152

11501153
#[inline]
1151-
pub(crate) fn connection_id(&self) -> Uuid {
1152-
self.connection_id
1154+
pub(crate) fn conn_id(&self) -> Uuid {
1155+
self.conn_id
11531156
}
11541157

11551158
#[inline]
@@ -1176,19 +1179,25 @@ impl ProxyHttpRequestInfo {
11761179

11771180
#[derive(Clone)]
11781181
pub(crate) struct ProxyHttpResponseInfo {
1179-
id: Uuid,
1182+
req_id: Uuid,
1183+
conn_id: Uuid,
11801184
status: StatusCode,
11811185
headers: HeaderMap, // TODO: perhaps we don't need all headers, just select ones
11821186
}
11831187

11841188
impl ProxyHttpResponseInfo {
1185-
pub(crate) fn new(id: Uuid, status: StatusCode, headers: HeaderMap) -> Self {
1186-
Self { id, status, headers }
1189+
pub(crate) fn new(req_id: Uuid, conn_id: Uuid, status: StatusCode, headers: HeaderMap) -> Self {
1190+
Self { req_id, conn_id, status, headers }
11871191
}
11881192

11891193
#[inline]
1190-
pub(crate) fn id(&self) -> Uuid {
1191-
self.id
1194+
pub(crate) fn req_id(&self) -> Uuid {
1195+
self.req_id
1196+
}
1197+
1198+
#[inline]
1199+
pub(crate) fn conn_id(&self) -> Uuid {
1200+
self.conn_id
11921201
}
11931202

11941203
fn content_encoding(&self) -> String {
@@ -1269,7 +1278,7 @@ where
12691278
warn!(
12701279
proxy = P::name(),
12711280
request_id = %info.id(),
1272-
connection_id = %info.connection_id(),
1281+
connection_id = %info.conn_id(),
12731282
error = err,
12741283
"Proxy http request stream error",
12751284
);
@@ -1278,6 +1287,7 @@ where
12781287
proxy = P::name(),
12791288
error = err,
12801289
request_id = "unknown",
1290+
connection_id = "unknown",
12811291
"Proxy http request stream error",
12821292
);
12831293
}
@@ -1292,7 +1302,7 @@ where
12921302
warn!(
12931303
proxy = P::name(),
12941304
request_id = %info.id(),
1295-
connection_id = %info.connection_id(),
1305+
connection_id = %info.conn_id(),
12961306
error = ?err,
12971307
"Proxy http request stream error",
12981308
);
@@ -1301,6 +1311,7 @@ where
13011311
proxy = P::name(),
13021312
error = ?err,
13031313
request_id = "unknown",
1314+
connection_id = "unknown",
13041315
"Proxy http request stream error",
13051316
);
13061317
}
@@ -1348,9 +1359,11 @@ where
13481359
C: ConfigProxyHttp,
13491360
P: ProxyHttpInner<C>,
13501361
{
1362+
#[allow(clippy::too_many_arguments)]
13511363
fn new(
13521364
proxy: web::Data<ProxyHttp<C, P>>,
1353-
id: Uuid,
1365+
req_id: Uuid,
1366+
conn_id: Uuid,
13541367
status: StatusCode,
13551368
headers: HeaderMap,
13561369
body: S,
@@ -1364,7 +1377,7 @@ where
13641377
start: timestamp,
13651378
body: Vec::with_capacity(preallocate),
13661379
max_size,
1367-
info: Some(ProxyHttpResponseInfo::new(id, status, headers)),
1380+
info: Some(ProxyHttpResponseInfo::new(req_id, conn_id, status, headers)),
13681381
}
13691382
}
13701383
}
@@ -1394,7 +1407,8 @@ where
13941407
if let Some(info) = mem::take(this.info) {
13951408
warn!(
13961409
proxy = P::name(),
1397-
request_id = %info.id(),
1410+
request_id = %info.req_id(),
1411+
connection_id = %info.conn_id(),
13981412
error = err,
13991413
"Proxy http response stream error",
14001414
);
@@ -1403,6 +1417,7 @@ where
14031417
proxy = P::name(),
14041418
error = err,
14051419
request_id = "unknown",
1420+
connection_id = "unknown",
14061421
"Proxy http response stream error",
14071422
);
14081423
}
@@ -1416,7 +1431,8 @@ where
14161431
if let Some(info) = mem::take(this.info) {
14171432
warn!(
14181433
proxy = P::name(),
1419-
request_id = %info.id(),
1434+
request_id = %info.req_id(),
1435+
connection_id = %info.conn_id(),
14201436
error = ?err,
14211437
"Proxy http response stream error",
14221438
);
@@ -1425,6 +1441,7 @@ where
14251441
proxy = P::name(),
14261442
error = ?err,
14271443
request_id = "unknown",
1444+
connection_id = "unknown",
14281445
"Proxy http response stream error",
14291446
);
14301447
}

0 commit comments

Comments
 (0)