Skip to content

Commit

Permalink
Pass host header in eBPF access log protocol (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrproliu authored Feb 26, 2025
1 parent 045ace9 commit f459a28
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
k8s.io/apimachinery v0.23.5
k8s.io/client-go v0.23.5
k8s.io/utils v0.0.0-20211116205334-6203023598ed
skywalking.apache.org/repo/goapi v0.0.0-20240920052516-d4a23d9da0e0
skywalking.apache.org/repo/goapi v0.0.0-20250225130248-3916480eb467
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1059,5 +1059,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.2.1 h1:bKCqE9GvQ5tiVHn5rfn1r+yao3aLQEaLz
sigs.k8s.io/structured-merge-diff/v4 v4.2.1/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
skywalking.apache.org/repo/goapi v0.0.0-20240920052516-d4a23d9da0e0 h1:7IW+T+mciD/GJXvgglZho414N30KSWgUTzBmEP867eI=
skywalking.apache.org/repo/goapi v0.0.0-20240920052516-d4a23d9da0e0/go.mod h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE=
skywalking.apache.org/repo/goapi v0.0.0-20250225130248-3916480eb467 h1:pXT6UxmC3qAD8faGFYuWmz6ekQPRfW1PcU8lAu6WSB0=
skywalking.apache.org/repo/goapi v0.0.0-20250225130248-3916480eb467/go.mod h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE=
5 changes: 5 additions & 0 deletions pkg/accesslog/collector/protocols/http1.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func (p *HTTP1Protocol) HandleHTTPData(metrics *HTTP1Metrics, connection *Partit
p.CloseStream(originalRequest.Body)
p.CloseStream(originalResponse.Body)
}()
host := request.Headers().Get("Host")
if host == "" && originalRequest.URL != nil {
host = originalRequest.URL.Host
}
forwarder.SendTransferProtocolEvent(p.ctx, details, &v3.AccessLogProtocolLogs{
Protocol: &v3.AccessLogProtocolLogs_Http{
Http: &v3.AccessLogHTTPProtocol{
Expand All @@ -249,6 +253,7 @@ func (p *HTTP1Protocol) HandleHTTPData(metrics *HTTP1Metrics, connection *Partit
Trace: AnalyzeTraceInfo(func(key string) string {
return originalRequest.Header.Get(key)
}, http1Log),
Host: host,
},
Response: &v3.AccessLogHTTPProtocolResponse{
StatusCode: int32(originalResponse.StatusCode),
Expand Down
10 changes: 7 additions & 3 deletions pkg/accesslog/collector/protocols/http2.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type HTTP2Streaming struct {
Status int
RespHeaderBuffer *buffer.Buffer
RespBodyBuffer *buffer.Buffer
connection *PartitionConnection
Connection *PartitionConnection
}

func (r *HTTP2Protocol) GenerateConnection(connectionID, randomID uint64) ProtocolMetrics {
Expand Down Expand Up @@ -178,7 +178,7 @@ func (r *HTTP2Protocol) handleHeader(connection *PartitionConnection, header *ht
ReqHeader: headers,
RespHeader: make(map[string]string),
ReqHeaderBuffer: buf.Slice(true, startPos, buf.Position()),
connection: connection,
Connection: connection,
}
metrics.streams[header.StreamID] = streaming
return enums.ParseResultSuccess, false, nil
Expand Down Expand Up @@ -254,6 +254,10 @@ func (r *HTTP2Protocol) handleWholeStream(stream *HTTP2Streaming) error {
}
idRange.DeleteDetails(stream.ReqHeaderBuffer)

streamHost := stream.ReqHeader[":authority"]
if streamHost == "" {
streamHost = stream.ReqHeader[":host"]
}
forwarder.SendTransferProtocolEvent(r.ctx, details, &v3.AccessLogProtocolLogs{
Protocol: &v3.AccessLogProtocolLogs_Http{
Http: &v3.AccessLogHTTPProtocol{
Expand All @@ -265,7 +269,7 @@ func (r *HTTP2Protocol) handleWholeStream(stream *HTTP2Streaming) error {
Path: stream.ReqHeader[":path"],
SizeOfHeadersBytes: r.BufferSizeOfZero(stream.ReqHeaderBuffer),
SizeOfBodyBytes: r.BufferSizeOfZero(stream.ReqBodyBuffer),

Host: streamHost,
Trace: AnalyzeTraceInfo(func(key string) string {
return stream.ReqHeader[key]
}, http2Log),
Expand Down

0 comments on commit f459a28

Please sign in to comment.