TUN-6347: Add TCP stream logs with FlowID
This commit is contained in:
parent
4f468b8a5d
commit
69b28e358c
|
@ -132,6 +132,7 @@ type TCPRequest struct {
|
||||||
Dest string
|
Dest string
|
||||||
CFRay string
|
CFRay string
|
||||||
LBProbe bool
|
LBProbe bool
|
||||||
|
FlowID string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadWriteAcker is a readwriter with the ability to Acknowledge to the downstream (edge) that the origin has
|
// ReadWriteAcker is a readwriter with the ability to Acknowledge to the downstream (edge) that the origin has
|
||||||
|
|
|
@ -31,6 +31,8 @@ const (
|
||||||
HTTPMethodKey = "HttpMethod"
|
HTTPMethodKey = "HttpMethod"
|
||||||
// HTTPHostKey is used to get or set http Method in QUIC ALPN if the underlying proxy connection type is HTTP.
|
// HTTPHostKey is used to get or set http Method in QUIC ALPN if the underlying proxy connection type is HTTP.
|
||||||
HTTPHostKey = "HttpHost"
|
HTTPHostKey = "HttpHost"
|
||||||
|
|
||||||
|
QUICMetadataFlowID = "FlowID"
|
||||||
)
|
)
|
||||||
|
|
||||||
// QUICConnection represents the type that facilitates Proxying via QUIC streams.
|
// QUICConnection represents the type that facilitates Proxying via QUIC streams.
|
||||||
|
@ -180,6 +182,7 @@ func (q *QUICConnection) handleDataStream(stream *quicpogs.RequestServerStream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch connectRequest.Type {
|
switch connectRequest.Type {
|
||||||
case quicpogs.ConnectionTypeHTTP, quicpogs.ConnectionTypeWebsocket:
|
case quicpogs.ConnectionTypeHTTP, quicpogs.ConnectionTypeWebsocket:
|
||||||
tracedReq, err := buildHTTPRequest(connectRequest, stream)
|
tracedReq, err := buildHTTPRequest(connectRequest, stream)
|
||||||
|
@ -191,7 +194,9 @@ func (q *QUICConnection) handleDataStream(stream *quicpogs.RequestServerStream)
|
||||||
return originProxy.ProxyHTTP(w, tracedReq, connectRequest.Type == quicpogs.ConnectionTypeWebsocket)
|
return originProxy.ProxyHTTP(w, tracedReq, connectRequest.Type == quicpogs.ConnectionTypeWebsocket)
|
||||||
case quicpogs.ConnectionTypeTCP:
|
case quicpogs.ConnectionTypeTCP:
|
||||||
rwa := &streamReadWriteAcker{stream}
|
rwa := &streamReadWriteAcker{stream}
|
||||||
return originProxy.ProxyTCP(context.Background(), rwa, &TCPRequest{Dest: connectRequest.Dest})
|
metadata := connectRequest.MetadataMap()
|
||||||
|
return originProxy.ProxyTCP(context.Background(), rwa, &TCPRequest{Dest: connectRequest.Dest,
|
||||||
|
FlowID: metadata[QUICMetadataFlowID]})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ const (
|
||||||
LogFieldCFRay = "cfRay"
|
LogFieldCFRay = "cfRay"
|
||||||
LogFieldRule = "ingressRule"
|
LogFieldRule = "ingressRule"
|
||||||
LogFieldOriginService = "originService"
|
LogFieldOriginService = "originService"
|
||||||
|
LogFieldFlowID = "flowID"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Proxy represents a means to Proxy between cloudflared and the origin services.
|
// Proxy represents a means to Proxy between cloudflared and the origin services.
|
||||||
|
@ -96,7 +97,7 @@ func (p *Proxy) ProxyHTTP(
|
||||||
logFields,
|
logFields,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
rule, srv := ruleField(p.ingressRules, ruleNum)
|
rule, srv := ruleField(p.ingressRules, ruleNum)
|
||||||
p.logRequestError(err, cfRay, rule, srv)
|
p.logRequestError(err, cfRay, "", rule, srv)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -109,7 +110,7 @@ func (p *Proxy) ProxyHTTP(
|
||||||
rws := connection.NewHTTPResponseReadWriterAcker(w, req)
|
rws := connection.NewHTTPResponseReadWriterAcker(w, req)
|
||||||
if err := p.proxyStream(req.Context(), rws, dest, originProxy, logFields); err != nil {
|
if err := p.proxyStream(req.Context(), rws, dest, originProxy, logFields); err != nil {
|
||||||
rule, srv := ruleField(p.ingressRules, ruleNum)
|
rule, srv := ruleField(p.ingressRules, ruleNum)
|
||||||
p.logRequestError(err, cfRay, rule, srv)
|
p.logRequestError(err, cfRay, "", rule, srv)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -140,13 +141,17 @@ func (p *Proxy) ProxyTCP(
|
||||||
cfRay: req.CFRay,
|
cfRay: req.CFRay,
|
||||||
lbProbe: req.LBProbe,
|
lbProbe: req.LBProbe,
|
||||||
rule: ingress.ServiceWarpRouting,
|
rule: ingress.ServiceWarpRouting,
|
||||||
|
flowID: req.FlowID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.log.Debug().Str(LogFieldFlowID, req.FlowID).Msg("tcp proxy stream started")
|
||||||
if err := p.proxyStream(serveCtx, rwa, req.Dest, p.warpRouting.Proxy, logFields); err != nil {
|
if err := p.proxyStream(serveCtx, rwa, req.Dest, p.warpRouting.Proxy, logFields); err != nil {
|
||||||
p.logRequestError(err, req.CFRay, "", ingress.ServiceWarpRouting)
|
p.logRequestError(err, req.CFRay, req.FlowID, "", ingress.ServiceWarpRouting)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.log.Debug().Str(LogFieldFlowID, req.FlowID).Msg("tcp proxy stream finished successfully")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,6 +322,7 @@ type logFields struct {
|
||||||
cfRay string
|
cfRay string
|
||||||
lbProbe bool
|
lbProbe bool
|
||||||
rule interface{}
|
rule interface{}
|
||||||
|
flowID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Proxy) logRequest(r *http.Request, fields logFields) {
|
func (p *Proxy) logRequest(r *http.Request, fields logFields) {
|
||||||
|
@ -360,12 +366,15 @@ func (p *Proxy) logOriginResponse(resp *http.Response, fields logFields) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Proxy) logRequestError(err error, cfRay string, rule, service string) {
|
func (p *Proxy) logRequestError(err error, cfRay string, flowID string, rule, service string) {
|
||||||
requestErrors.Inc()
|
requestErrors.Inc()
|
||||||
log := p.log.Error().Err(err)
|
log := p.log.Error().Err(err)
|
||||||
if cfRay != "" {
|
if cfRay != "" {
|
||||||
log = log.Str(LogFieldCFRay, cfRay)
|
log = log.Str(LogFieldCFRay, cfRay)
|
||||||
}
|
}
|
||||||
|
if flowID != "" {
|
||||||
|
log = log.Str(LogFieldFlowID, flowID)
|
||||||
|
}
|
||||||
if rule != "" {
|
if rule != "" {
|
||||||
log = log.Str(LogFieldRule, rule)
|
log = log.Str(LogFieldRule, rule)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue