Skip to content

Commit

Permalink
optimize: filter shortConnErr in tracer (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jin-gou authored Mar 5, 2024
1 parent c6927c4 commit 1f9997c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/protocol/http1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ func (s Server) Serve(c context.Context, conn network.Conn) (err error) {

defer func() {
if s.EnableTrace {
if shouldRecordInTraceError(err) {
ctx.GetTraceInfo().Stats().SetError(err)
}
// in case of error, we need to trigger all events
if eventsToTrigger != nil {
for last := eventsToTrigger.pop(); last != nil; last = eventsToTrigger.pop() {
last(ctx.GetTraceInfo(), err)
}
s.eventStackPool.Put(eventsToTrigger)
}

traceCtl.DoFinish(cc, ctx, err)
if shouldRecordInTraceError(err) {
traceCtl.DoFinish(cc, ctx, err)
} else {
traceCtl.DoFinish(cc, ctx, nil)
}
}

// Hijack may release and close the connection already
Expand Down Expand Up @@ -384,7 +384,11 @@ func (s Server) Serve(c context.Context, conn network.Conn) (err error) {
}
// general case
if s.EnableTrace {
traceCtl.DoFinish(cc, ctx, err)
if shouldRecordInTraceError(err) {
traceCtl.DoFinish(cc, ctx, err)
} else {
traceCtl.DoFinish(cc, ctx, nil)
}
}

ctx.ResetWithoutConn()
Expand Down
1 change: 1 addition & 0 deletions pkg/protocol/http1/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestTraceEventCompleted(t *testing.T) {
assert.False(t, traceInfo.Stats().GetEvent(stats.WriteStart).IsNil())
assert.False(t, traceInfo.Stats().GetEvent(stats.WriteFinish).IsNil())
assert.False(t, traceInfo.Stats().GetEvent(stats.HTTPFinish).IsNil())
assert.Nil(t, traceInfo.Stats().Error())
}

func TestTraceEventReadHeaderError(t *testing.T) {
Expand Down

0 comments on commit 1f9997c

Please sign in to comment.