This is an automated email from the ASF dual-hosted git repository.

liuhan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-rover.git


The following commit(s) were added to refs/heads/main by this push:
     new f459a28  Pass host header in eBPF access log protocol (#179)
f459a28 is described below

commit f459a28e2040fdeed4f3a448d61a61ae26f612a2
Author: mrproliu <741550...@qq.com>
AuthorDate: Wed Feb 26 10:36:37 2025 +0800

    Pass host header in eBPF access log protocol (#179)
---
 go.mod                                     |  2 +-
 go.sum                                     |  4 ++--
 pkg/accesslog/collector/protocols/http1.go |  5 +++++
 pkg/accesslog/collector/protocols/http2.go | 10 +++++++---
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/go.mod b/go.mod
index d1b0f7b..6eb8649 100644
--- a/go.mod
+++ b/go.mod
@@ -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 (
diff --git a/go.sum b/go.sum
index a876042..b1dd69b 100644
--- a/go.sum
+++ b/go.sum
@@ -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=
diff --git a/pkg/accesslog/collector/protocols/http1.go 
b/pkg/accesslog/collector/protocols/http1.go
index 9ad0486..3039f00 100644
--- a/pkg/accesslog/collector/protocols/http1.go
+++ b/pkg/accesslog/collector/protocols/http1.go
@@ -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{
@@ -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),
diff --git a/pkg/accesslog/collector/protocols/http2.go 
b/pkg/accesslog/collector/protocols/http2.go
index 673088e..af81d92 100644
--- a/pkg/accesslog/collector/protocols/http2.go
+++ b/pkg/accesslog/collector/protocols/http2.go
@@ -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 {
@@ -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
@@ -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{
@@ -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),

Reply via email to