Skip to content

Commit

Permalink
test: introduce a script to test flag --comm (hengyoush#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
spencercjh authored and XmchxUp committed Dec 31, 2024
1 parent f677d60 commit 537a08a
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 45 deletions.
100 changes: 57 additions & 43 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
install-dependencies: 'true'
cmd: |
chmod +x /host/kyanos/kyanos
- name: download btf file
if: ${{ startsWith(matrix.kernel, '4.') }}
run: |
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testdata/https-request/http_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -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()
Expand Down
27 changes: 27 additions & 0 deletions testdata/start_http_server.py
Original file line number Diff line number Diff line change
@@ -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()
39 changes: 39 additions & 0 deletions testdata/test_filter_by_comm.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 537a08a

Please sign in to comment.