Skip to content

Commit

Permalink
Fix wrong protocol break handle logic (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrproliu authored Mar 4, 2025
1 parent 1641294 commit 16b0438
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pkg/accesslog/collector/protocols/http2.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (r *HTTP2Protocol) Analyze(connection *PartitionConnection, helper *Analyze

// if the protocol break, then stop the loop and notify the caller to skip analyze all data(just sending the detail)
if protocolBreak {
http2Log.Warnf("the HTTP/2 protocol break, maybe not tracing the connection from beginning, skip all data analyze in this connection, "+
http2Log.Debugf("the HTTP/2 protocol break, maybe not tracing the connection from beginning, skip all data analyze in this connection, "+
"connection ID: %d", http2Metrics.ConnectionID)
helper.ProtocolBreak = true
r.analyzer.OnProtocolBreak(connection, http2Metrics)
Expand Down Expand Up @@ -231,7 +231,7 @@ func (r *HTTP2Protocol) validateIsStreamOpenTooLong(connection *PartitionConnect
return
}
if time.Since(host.Time(socketBuffer.StartTime())) > maxHTTP2StreamingTime {
http2Log.Infof("detect the HTTP/2 stream is too long, split the stream, connection ID: %d, stream ID: %d, headers: %v",
http2Log.Debugf("detect the HTTP/2 stream is too long, split the stream, connection ID: %d, stream ID: %d, headers: %v",
metrics.ConnectionID, id, streaming.ReqHeader)

_ = r.analyzer.HandleWholeStream(connection, streaming)
Expand Down
26 changes: 14 additions & 12 deletions pkg/accesslog/common/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ func (c *ConnectionManager) Find(event events.Event) *ConnectionInfo {
c.connections.Set(connectionKey, connection)
if log.Enable(logrus.DebugLevel) {
log.Debugf("building flushing connection, connection ID: %d, randomID: %d, role: %s, local: %s:%d, remote: %s:%d, "+
"local address: %s, remote address: %s",
"local address: %s, remote address: %s, protocol: %s",
e.GetConnectionID(), e.GetRandomID(), socket.Role, socket.SrcIP, socket.SrcPort, socket.DestIP, socket.DestPort,
localAddress.String(), remoteAddress.String())
localAddress.String(), remoteAddress.String(), connection.RPCConnection.Protocol.String())
}
c.connectionPostHandle(connection, event)
return connection
Expand Down Expand Up @@ -620,6 +620,18 @@ func (c *ConnectionManager) OnBuildConnectionLogFinished() {
}

func (c *ConnectionManager) SkipAllDataAnalyzeAndDowngradeProtocol(conID, ranID uint64) {
// setting connection protocol is break
connectionKey := fmt.Sprintf("%d_%d", conID, ranID)
data, exist := c.connections.Get(connectionKey)
if exist {
connection := data.(*ConnectionInfo)
connection.ProtocolBreak = true
} else {
// setting to the protocol break map for encase the runner not starting building logs
c.connectionProtocolBreakMap.Set(connectionKey, true, time.Minute)
}

// setting the connection skip data upload
var activateConn ActiveConnection
if err := c.activeConnectionMap.Lookup(conID, &activateConn); err != nil {
if errors.Is(err, ebpf.ErrKeyNotExist) {
Expand All @@ -637,16 +649,6 @@ func (c *ConnectionManager) SkipAllDataAnalyzeAndDowngradeProtocol(conID, ranID
if err := c.activeConnectionMap.Update(conID, activateConn, ebpf.UpdateAny); err != nil {
log.Warnf("failed to update the active connection: %d-%d", conID, ranID)
}

connectionKey := fmt.Sprintf("%d_%d", conID, ranID)
data, exist := c.connections.Get(connectionKey)
if exist {
connection := data.(*ConnectionInfo)
connection.ProtocolBreak = true
} else {
// setting to the protocol break map for encase the runner not starting building logs
c.connectionProtocolBreakMap.Set(connectionKey, true, time.Minute)
}
}

func getSocketPairFromConnectEvent(event events.Event) (*events.SocketConnectEvent, *ip.SocketPair) {
Expand Down

0 comments on commit 16b0438

Please sign in to comment.