diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 748199b4..3c9dcc6c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,40 +18,40 @@ jobs: build: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - with: - submodules: recursive - - - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5 - with: - go-version: '1.22.4' - - - name: Build - run: | - sudo apt update - sudo apt install -y git - sudo apt-get -y install pkg-config - sudo apt install -y libelf-dev - - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - - sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main" - sudo apt update - - sudo apt install -y llvm - sudo apt install -y clang - pwd - ls -l - make clean && make build-bpf && make - - # - name: Test - # run: make test - - - name: Store executable - uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4 - with: - name: kyanos - path: kyanos + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + with: + submodules: recursive + + - name: Set up Go + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5 + with: + go-version: '1.22.4' + + - name: Build + run: | + sudo apt update + sudo apt install -y git + sudo apt-get -y install pkg-config + sudo apt install -y libelf-dev + + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - + sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main" + sudo apt update + + sudo apt install -y llvm + sudo apt install -y clang + pwd + ls -l + make clean && make build-bpf && make + + # - name: Test + # run: make test + + - name: Store executable + uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4 + with: + name: kyanos + path: kyanos e2e-test: @@ -101,7 +101,7 @@ jobs: install-dependencies: 'true' cmd: | chmod +x /host/kyanos/kyanos - + - name: download btf file if: ${{ startsWith(matrix.kernel, '4.') }} run: | @@ -113,7 +113,7 @@ jobs: ls -la data/ find data/ -path "*vmlinuz*" -type f find data/ -path "*btf*" -type f - + - name: copy btf file if: ${{ startsWith(matrix.kernel, '4.') }} uses: cilium/little-vm-helper@97c89f004bd0ab4caeacfe92ebc956e13e362e6b # v0.0.19 @@ -125,7 +125,7 @@ jobs: cat /etc/os-release sudo mkdir -p /var/lib/kyanos/btf/ - + sudo cp /host/data/kernels/4.*/boot/btf-4.* /var/lib/kyanos/btf/current.btf # btf_file=$(find /host/ -path "*btf*" -type f) # sudo cp $btf_file /var/lib/ptcpdump/btf/vmlinux @@ -155,8 +155,22 @@ jobs: #install python pip sudo apt install -y python3 python3-pip pipx - - + - name: Test filter by comm + uses: cilium/little-vm-helper@97c89f004bd0ab4caeacfe92ebc956e13e362e6b # v0.0.19 + with: + provision: 'false' + cmd: | + set -euxo pipefail + uname -a + cat /etc/issue + pushd /host + if [ -f "/var/lib/kyanos/btf/current.btf" ]; then + bash /host/testdata/test_filter_by_comm.sh '/host/kyanos/kyanos $kyanos_log_option --btf /var/lib/kyanos/btf/current.btf' + else + bash /host/testdata/test_filter_by_comm.sh '/host/kyanos/kyanos $kyanos_log_option' + fi + popd + - name: Test gotls uses: cilium/little-vm-helper@97c89f004bd0ab4caeacfe92ebc956e13e362e6b # v0.0.19 with: @@ -172,7 +186,7 @@ jobs: bash /host/testdata/test_gotls.sh '/host/kyanos/kyanos $kyanos_log_option' fi popd - + - name: Test https uses: cilium/little-vm-helper@97c89f004bd0ab4caeacfe92ebc956e13e362e6b # v0.0.19 with: @@ -188,7 +202,7 @@ jobs: bash /host/testdata/test_https.sh '/host/kyanos/kyanos $kyanos_log_option' fi popd - + - name: Test side uses: cilium/little-vm-helper@97c89f004bd0ab4caeacfe92ebc956e13e362e6b # v0.0.19 with: @@ -263,7 +277,7 @@ jobs: else bash /host/testdata/test_kern_evt.sh '/host/kyanos/kyanos $kyanos_log_option' fi - + - name: Test test docker filter by container id uses: cilium/little-vm-helper@97c89f004bd0ab4caeacfe92ebc956e13e362e6b # v0.0.19 with: @@ -347,7 +361,7 @@ jobs: else bash /host/testdata/test_redis.sh '/host/kyanos/kyanos $kyanos_log_option' fi - + - name: Test k8s if: ${{ startsWith(matrix.kernel, '6.') }} uses: cilium/little-vm-helper@97c89f004bd0ab4caeacfe92ebc956e13e362e6b # v0.0.19 diff --git a/testdata/https-request/http_request.go b/testdata/https-request/http_request.go index 2445c825..9ece8812 100644 --- a/testdata/https-request/http_request.go +++ b/testdata/https-request/http_request.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "net/http" "os" "strconv" @@ -42,7 +42,7 @@ func main() { } // 读取并打印响应内容 - body, err := ioutil.ReadAll(response.Body) + body, err := io.ReadAll(response.Body) if err != nil { fmt.Printf("Failed to read response %d: %v\n", i+1, err) response.Body.Close() diff --git a/testdata/start_http_server.py b/testdata/start_http_server.py new file mode 100644 index 00000000..0c186a84 --- /dev/null +++ b/testdata/start_http_server.py @@ -0,0 +1,27 @@ +import http.server +import ssl +from socketserver import ThreadingMixIn + +# 创建自定义的 HTTP 服务器类,支持线程以处理多个连接 +class ThreadedHTTPServer(ThreadingMixIn, http.server.HTTPServer): + # 设置 allow_reuse_address 以支持长连接 + allow_reuse_address = True + +class KeepAliveHandler(http.server.SimpleHTTPRequestHandler): + # 设置响应头以启用长连接 + + # 重写 `do_GET` 方法处理 GET 请求 + def do_GET(self): + self.send_response(200) + self.send_header("Content-type", "text/html") + self.send_header("Connection", "keep-alive") + self.send_header("Content-Length", str(len("Hello, this is an HTTP server with keep-alive support!"))) + self.end_headers() + self.wfile.write(b"Hello, this is an HTTP server with keep-alive support!") + +# 服务器地址和端口 +server_address = ('localhost', 8080) +httpd = ThreadedHTTPServer(server_address, KeepAliveHandler) + +print("HTTP server running on http://localhost:8080 with keep-alive support") +httpd.serve_forever() diff --git a/testdata/test_filter_by_comm.sh b/testdata/test_filter_by_comm.sh new file mode 100644 index 00000000..1833a505 --- /dev/null +++ b/testdata/test_filter_by_comm.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +. $(dirname "$0")/common.sh +set -ex + +CMD="$1" +FILE_PREFIX="/tmp/kyanos" +BEFORE_LNAME="${FILE_PREFIX}_filter_by_comm_before.log" +AFTER_LNAME="${FILE_PREFIX}_filter_by_comm_after.log" + +function test_filter_by_server_comm() { + # server start before kyanos + timeout 40 python3 ./testdata/start_http_server.py & + timeout 30 ${CMD} watch --debug-output http --comm python3 2>&1 | tee "${BEFORE_LNAME}" & + sleep 2 + timeout 25 ./testdata/https-request/https-request 'http://127.0.0.1:8080' 40 & + sleep 10 + wait + + cat "${BEFORE_LNAME}" + cat "${BEFORE_LNAME}" | grep "Host: 127.0.0.1:8080" | grep "\\[side\\]=server" +} + +# skip for https://github.com/hengyoush/kyanos/pull/222#issuecomment-2566106756 +function test_filter_by_client_comm() { + # client start after kyanos + timeout 40 ${CMD} watch --debug-output http --comm https-request 2>&1 | tee "${AFTER_LNAME}" & + sleep 10 + timeout 30 ./testdata/https-request/https-request 'http://ipinfo.io' 40 & + wait + + cat "${AFTER_LNAME}" + cat "${AFTER_LNAME}" | grep "Host: ipinfo.io" | grep "\\[side\\]=client" +} + +function main() { + test_filter_by_server_comm +} + +main \ No newline at end of file