@@ -28,6 +28,7 @@ const (
2828 LogFieldRule = "ingressRule"
2929 LogFieldOriginService = "originService"
3030 LogFieldFlowID = "flowID"
31+ LogFieldConnIndex = "connIndex"
3132
3233 trailerHeaderName = "Trailer"
3334)
@@ -94,9 +95,10 @@ func (p *Proxy) ProxyHTTP(
9495 trace .WithAttributes (attribute .String ("req-host" , req .Host )))
9596 rule , ruleNum := p .ingressRules .FindMatchingRule (req .Host , req .URL .Path )
9697 logFields := logFields {
97- cfRay : cfRay ,
98- lbProbe : lbProbe ,
99- rule : ruleNum ,
98+ cfRay : cfRay ,
99+ lbProbe : lbProbe ,
100+ rule : ruleNum ,
101+ connIndex : tr .ConnIndex ,
100102 }
101103 p .logRequest (req , logFields )
102104 ruleSpan .SetAttributes (attribute .Int ("rule-num" , ruleNum ))
@@ -163,14 +165,14 @@ func (p *Proxy) ProxyTCP(
163165
164166 tracedCtx := tracing .NewTracedContext (serveCtx , req .CfTraceID , p .log )
165167
166- p .log .Debug ().Str (LogFieldFlowID , req .FlowID ).Msg ("tcp proxy stream started" )
168+ p .log .Debug ().Str (LogFieldFlowID , req .FlowID ).Uint8 ( LogFieldConnIndex , req . ConnIndex ). Msg ("tcp proxy stream started" )
167169
168170 if err := p .proxyStream (tracedCtx , rwa , req .Dest , p .warpRouting .Proxy ); err != nil {
169171 p .logRequestError (err , req .CFRay , req .FlowID , "" , ingress .ServiceWarpRouting )
170172 return err
171173 }
172174
173- p .log .Debug ().Str (LogFieldFlowID , req .FlowID ).Msg ("tcp proxy stream finished successfully" )
175+ p .log .Debug ().Str (LogFieldFlowID , req .FlowID ).Uint8 ( LogFieldConnIndex , req . ConnIndex ). Msg ("tcp proxy stream finished successfully" )
174176
175177 return nil
176178}
@@ -320,10 +322,11 @@ func (p *Proxy) appendTagHeaders(r *http.Request) {
320322}
321323
322324type logFields struct {
323- cfRay string
324- lbProbe bool
325- rule interface {}
326- flowID string
325+ cfRay string
326+ lbProbe bool
327+ rule interface {}
328+ flowID string
329+ connIndex uint8
327330}
328331
329332func copyTrailers (w connection.ResponseWriter , response * http.Response ) {
@@ -348,6 +351,7 @@ func (p *Proxy) logRequest(r *http.Request, fields logFields) {
348351 Str ("host" , r .Host ).
349352 Str ("path" , r .URL .Path ).
350353 Interface ("rule" , fields .rule ).
354+ Uint8 (LogFieldConnIndex , fields .connIndex ).
351355 Msg ("Inbound request" )
352356
353357 if contentLen := r .ContentLength ; contentLen == - 1 {
@@ -360,18 +364,18 @@ func (p *Proxy) logRequest(r *http.Request, fields logFields) {
360364func (p * Proxy ) logOriginResponse (resp * http.Response , fields logFields ) {
361365 responseByCode .WithLabelValues (strconv .Itoa (resp .StatusCode )).Inc ()
362366 if fields .cfRay != "" {
363- p .log .Debug ().Msgf ("CF-RAY: %s Status: %s served by ingress %d" , fields .cfRay , resp .Status , fields .rule )
367+ p .log .Debug ().Uint8 ( LogFieldConnIndex , fields . connIndex ). Msgf ("CF-RAY: %s Status: %s served by ingress %d" , fields .cfRay , resp .Status , fields .rule )
364368 } else if fields .lbProbe {
365- p .log .Debug ().Msgf ("Response to Load Balancer health check %s" , resp .Status )
369+ p .log .Debug ().Uint8 ( LogFieldConnIndex , fields . connIndex ). Msgf ("Response to Load Balancer health check %s" , resp .Status )
366370 } else {
367- p .log .Debug ().Msgf ("Status: %s served by ingress %v" , resp .Status , fields .rule )
371+ p .log .Debug ().Uint8 ( LogFieldConnIndex , fields . connIndex ). Msgf ("Status: %s served by ingress %v" , resp .Status , fields .rule )
368372 }
369- p .log .Debug ().Msgf ("CF-RAY: %s Response Headers %+v" , fields .cfRay , resp .Header )
373+ p .log .Debug ().Uint8 ( LogFieldConnIndex , fields . connIndex ). Msgf ("CF-RAY: %s Response Headers %+v" , fields .cfRay , resp .Header )
370374
371375 if contentLen := resp .ContentLength ; contentLen == - 1 {
372- p .log .Debug ().Msgf ("CF-RAY: %s Response content length unknown" , fields .cfRay )
376+ p .log .Debug ().Uint8 ( LogFieldConnIndex , fields . connIndex ). Msgf ("CF-RAY: %s Response content length unknown" , fields .cfRay )
373377 } else {
374- p .log .Debug ().Msgf ("CF-RAY: %s Response content length %d" , fields .cfRay , contentLen )
378+ p .log .Debug ().Uint8 ( LogFieldConnIndex , fields . connIndex ). Msgf ("CF-RAY: %s Response content length %d" , fields .cfRay , contentLen )
375379 }
376380}
377381
0 commit comments