Skip to content

Commit 05e19d2

Browse files
authored
fix: The way filepath.Join is used when handling package names doesn't properly account for windows. (#219)
1 parent 4776866 commit 05e19d2

15 files changed

Lines changed: 527 additions & 21 deletions

File tree

.github/workflows/windows-plugin-test.yaml

Lines changed: 139 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,148 @@
1616

1717
name: Windows Plugin Tests
1818

19+
concurrency:
20+
group: plugins-${{ github.event.pull_request.number || github.ref }}
21+
cancel-in-progress: true
22+
1923
on:
20-
workflow_dispatch:
24+
pull_request:
2125

2226
jobs:
2327
test-on-windows:
2428
runs-on: windows-latest
2529
steps:
26-
- name: mock
27-
run: echo "mock"
30+
- name: firewall
31+
shell: pwsh
32+
run: |
33+
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
34+
35+
- name: Install and Configure WSL 2
36+
shell: pwsh
37+
run: |
38+
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
39+
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
40+
41+
Invoke-WebRequest -Uri https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi -OutFile wsl_update.msi
42+
Start-Process msiexec.exe -Wait -ArgumentList '/i wsl_update.msi /quiet'
43+
44+
wsl --set-default-version 2
45+
wsl --update
46+
wsl --install -d Ubuntu
47+
48+
@'
49+
@echo off
50+
FOR /F "usebackq tokens=*" %%F IN (`wsl wslpath '%~1'`) DO SET wslpath=%%F
51+
wsl -d Ubuntu sed -i 's/\r$//' %wslpath%
52+
wsl -d Ubuntu --cd %GITHUB_WORKSPACE% bash --noprofile --norc -eo pipefail %wslpath%
53+
'@ | Out-File -FilePath $env:RUNNER_TEMP\wsl-run.bat -Encoding utf8
54+
$env:RUNNER_TEMP >> $env:GITHUB_PATH
55+
56+
- name: WSL - Setup Docker
57+
shell: wsl-run {0}
58+
run: |
59+
# Add Docker's official GPG key:
60+
sudo apt-get update
61+
sudo apt-get install -y ca-certificates curl
62+
sudo install -m 0755 -d /etc/apt/keyrings
63+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
64+
sudo chmod a+r /etc/apt/keyrings/docker.asc
65+
66+
# Add the repository to Apt sources:
67+
echo \
68+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
69+
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
70+
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
71+
sudo apt-get update
72+
73+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
74+
75+
sudo service docker start
76+
77+
curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
78+
sudo chmod +x /usr/local/bin/docker-compose
79+
docker-compose --version
80+
- name: WSL – Install Go 1.19
81+
shell: wsl-run {0}
82+
run: |
83+
wget https://go.dev/dl/go1.19.linux-amd64.tar.gz
84+
sudo tar -C /usr/local -xzf go1.19.linux-amd64.tar.gz
85+
86+
echo 'export GOROOT=/usr/local/go' >> ~/.profile
87+
echo 'export GOPATH=$HOME/go' >> ~/.profile
88+
echo 'export PATH=$GOROOT/bin:$GOPATH/bin:$PATH' >> ~/.profile
89+
90+
export GOROOT=/usr/local/go
91+
export GOPATH=$HOME/go
92+
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
93+
94+
go version
95+
96+
- name: Checkout code
97+
uses: actions/checkout@v4
98+
with:
99+
submodules: true
100+
101+
- name: Copy code to WSL home
102+
shell: wsl-run {0}
103+
run: |
104+
mkdir -p ~/repo
105+
cp -r /mnt/d/a/skywalking-go/* ~/repo/
106+
107+
- name: WSL – Build
108+
shell: wsl-run {0}
109+
run: |
110+
export GOROOT=/usr/local/go
111+
export GOPATH=$HOME/go
112+
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
113+
sudo apt-get install -y build-essential
114+
cd ~/repo/skywalking-go/test/plugins
115+
mkdir -p dist
116+
cd validator && docker build . -t skywalking/agent-test-validator:1.0.0
117+
docker save -o ../dist/skywalking-agent-test-validator-1.0.0.tgz skywalking/agent-test-validator:1.0.0
118+
119+
- name: Copy WSL to Windows
120+
shell: wsl-run {0}
121+
run: |
122+
sudo cp -rf ~/repo/* /mnt/d/a/skywalking-go
123+
124+
- name: Windows Set up Go 1.19
125+
uses: actions/setup-go@v2
126+
with:
127+
go-version: 1.19
128+
- name: WSL Setup Tools
129+
shell: wsl-run {0}
130+
run: |
131+
cd ~/repo/skywalking-go
132+
cp -rf /mnt/d/a/skywalking-go/skywalking-go/test/plugins/dist/* test/plugins/dist/
133+
chmod +x test/plugins/dist/*
134+
if ls test/plugins/dist/skywalking-agent-test-validator-1.0.0.tgz; then
135+
docker load -i test/plugins/dist/skywalking-agent-test-validator-1.0.0.tgz
136+
fi
137+
- name: Run Windows Server
138+
run: |
139+
choco install yq
140+
cd test/plugins
141+
head -n -2 Makefile > temp && rm Makefile && mv temp Makefile
142+
make build os=windows
143+
bash run.sh http
144+
- uses: actions/upload-artifact@v4
145+
name: Upload Agent
146+
if: ${{ failure() }}
147+
with:
148+
path: test/plugins/workspace
149+
name: test-plugins-workspace-http-windows
150+
151+
required:
152+
if: always()
153+
name: Windows Plugin Tests
154+
needs:
155+
- test-on-windows
156+
runs-on: ubuntu-latest
157+
timeout-minutes: 10
158+
steps:
159+
- name: Merge Requirement
160+
run: |
161+
if [[ ${{ needs.test-on-windows.result }} != 'success' ]]; then
162+
exit -1
163+
fi

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ Release Notes.
66
------------------
77
#### Features
88

9+
* Support Windows plugin test.
10+
911
#### Plugins
1012

1113
#### Documentation
1214

1315
#### Bug Fixes
1416

17+
* Fix plugin interceptors bypassed on Windows.
18+
1519
#### Issues and PR
1620
- All issues are [here](https://github.com/apache/skywalking/milestone/238?closed=1)
1721
- All and pull requests are [here](https://github.com/apache/skywalking-go/milestone/8?closed=1)

test/plugins/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ ifeq ($(strip $(GIT_VERSION)),)
2424
endif
2525
VERSION ?= $(GIT_VERSION)
2626

27+
os ?= $(OS)
28+
2729
.PHONY: build
2830
build:
2931
mkdir -p dist
3032
# go agent
31-
@make -C ../../tools/go-agent linux
32-
cp ../../bin/skywalking-go-agent-$(VERSION)-linux-$(shell go env GOARCH) dist/skywalking-go-agent
33+
@if [ "$(os)" = "windows" ]; then \
34+
"$(MAKE)" -C ../../tools/go-agent windows; \
35+
cp ../../bin/skywalking-go-agent-$(VERSION)-windows-$(shell go env GOARCH) dist/skywalking-go-agent.exe; \
36+
else \
37+
"$(MAKE)" -C ../../tools/go-agent linux; \
38+
cp ../../bin/skywalking-go-agent-$(VERSION)-linux-$(shell go env GOARCH) dist/skywalking-go-agent; \
39+
fi
3340
# runner helper
3441
cd runner-helper && $(GO_BUILD) -o ../dist/runner-helper
3542
# validator container

test/plugins/run.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ num_of_testcases=0
2828

2929
start_stamp=`date +%s`
3030

31+
os_name=$(uname)
32+
if [[ "$os_name" =~ "NT" || "$os_name" =~ "MINGW" || "$os_name" =~ "MSYS" ]]; then
33+
os="windows"
34+
fi
35+
3136
replace() {
3237
if [ $# -lt 2 ]; then
3338
echo 1
@@ -207,6 +212,7 @@ for framework_version in $frameworks; do
207212

208213
bash ${case_home}/scenarios.sh > ${case_logs}/scenarios.log
209214
status=$?
215+
210216
if [[ $status == 0 ]]; then
211217
[[ $debug_mode == "off" ]] && remove_dir ${case_home}
212218
else
@@ -215,6 +221,9 @@ for framework_version in $frameworks; do
215221
num_of_testcases=$(($num_of_testcases+1))
216222

217223
done
224+
if [[ $os == "windows" ]]; then
225+
break
226+
fi
218227
done
219228

220229
exitAndClean 0

test/plugins/runner-helper/context.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
"flag"
2323
"os"
2424
"path/filepath"
25+
"runtime"
26+
27+
"github.com/apache/skywalking-go/tools/go-agent/instrument/consts"
2528

2629
"gopkg.in/yaml.v3"
2730
)
@@ -61,6 +64,7 @@ func BuildContext() (*Context, error) {
6164
GoAgentPath: filepath.Clean(*goAgentPath),
6265
DebugMode: *debugMode == "on",
6366
Config: config,
67+
IsWindows: runtime.GOOS == consts.WindowsGOOS,
6468
}, nil
6569
}
6670

@@ -73,6 +77,7 @@ type Context struct {
7377
GoAgentPath string
7478
DebugMode bool
7579
Config *Config
80+
IsWindows bool
7681
}
7782

7883
type Config struct {

test/plugins/runner-helper/main.go

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ func main() {
4141
log.Fatalf("build dockerfile failure: %v", err)
4242
}
4343

44+
// generate scenarios.sh to start the plugin test case
45+
err = RenderScenariosScript(context)
46+
if err != nil {
47+
log.Fatalf("build scenarios failure: %v", err)
48+
}
49+
4450
// generate docker-compose.yml to run the plugin
4551
err = RenderDockerCompose(context)
4652
if err != nil {
@@ -53,10 +59,12 @@ func main() {
5359
log.Fatalf("build validator failure: %v", err)
5460
}
5561

56-
// generate scenarios.sh to start the plugin test case
57-
err = RenderScenariosScript(context)
58-
if err != nil {
59-
log.Fatalf("build scenarios failure: %v", err)
62+
// generate validator.sh to validate the plugin
63+
if context.IsWindows {
64+
err = RenderWSLScenariosScript(context)
65+
if err != nil {
66+
log.Fatalf("windows build wsl-scenarios failure: %v", err)
67+
}
6068
}
6169
}
6270

@@ -89,46 +97,85 @@ func RenderDockerFile(context *Context) error {
8997
return os.WriteFile(filepath.Join(context.WorkSpaceDir, "Dockerfile"), []byte(render), 0o600)
9098
}
9199

100+
func RenderScenariosScript(context *Context) error {
101+
tplName := "scenarios.tpl"
102+
dockerComposeFilePath := filepath.Join(context.WorkSpaceDir, "docker-compose.yml")
103+
if context.IsWindows {
104+
tplName = "windows-scenarios.tpl"
105+
dockerComposeFilePath = strings.ReplaceAll(dockerComposeFilePath, `\`, `/`)
106+
}
107+
108+
render, err := templates.Render(tplName, struct {
109+
DockerComposeFilePath string
110+
Context *Context
111+
}{
112+
DockerComposeFilePath: dockerComposeFilePath,
113+
Context: context,
114+
})
115+
if err != nil {
116+
return err
117+
}
118+
render = strings.ReplaceAll(render, "\r\n", "\n")
119+
return os.WriteFile(filepath.Join(context.WorkSpaceDir, "scenarios.sh"), []byte(render), 0o600)
120+
}
121+
92122
func RenderDockerCompose(context *Context) error {
93123
rel, err := filepath.Rel(context.ProjectDir, filepath.Join(context.WorkSpaceDir, "Dockerfile"))
94124
if err != nil {
95125
return err
96126
}
97-
render, err := templates.Render("docker-compose.tpl", struct {
127+
128+
dir := context.WorkSpaceDir
129+
130+
tplName := "docker-compose.tpl"
131+
if context.IsWindows {
132+
tplName = "windows-docker-compose.tpl"
133+
context.WorkSpaceDir = "/root/repo/skywalking-go/test/plugins/workspace/" + context.ScenarioName + "/" + context.CaseName
134+
}
135+
136+
render, err := templates.Render(tplName, struct {
98137
DockerFilePathRelateToProject string
99138
Context *Context
100139
}{
101140
DockerFilePathRelateToProject: rel,
102141
Context: context,
103142
})
143+
context.WorkSpaceDir = dir
104144
if err != nil {
105145
return err
106146
}
107147
return os.WriteFile(filepath.Join(context.WorkSpaceDir, "docker-compose.yml"), []byte(render), 0o600)
108148
}
109149

110150
func RenderValidatorScript(context *Context) error {
111-
render, err := templates.Render("validator.tpl", struct {
151+
tplName := "validator.tpl"
152+
if context.IsWindows {
153+
tplName = "windows-validator.tpl"
154+
}
155+
render, err := templates.Render(tplName, struct {
112156
Context *Context
113157
}{
114158
Context: context,
115159
})
116160
if err != nil {
117161
return err
118162
}
163+
render = strings.ReplaceAll(render, "\r\n", "\n")
119164
return os.WriteFile(filepath.Join(context.WorkSpaceDir, "validator.sh"), []byte(render), 0o600)
120165
}
121166

122-
func RenderScenariosScript(context *Context) error {
123-
render, err := templates.Render("scenarios.tpl", struct {
124-
DockerComposeFilePath string
125-
Context *Context
167+
func RenderWSLScenariosScript(context *Context) error {
168+
dir := context.WorkSpaceDir
169+
context.WorkSpaceDir = "/root/repo/skywalking-go/test/plugins/workspace/" + context.ScenarioName + "/" + context.CaseName
170+
render, err := templates.Render("wsl-scenarios.tpl", struct {
171+
Context *Context
126172
}{
127-
DockerComposeFilePath: filepath.Join(context.WorkSpaceDir, "docker-compose.yml"),
128-
Context: context,
173+
Context: context,
129174
})
130175
if err != nil {
131176
return err
132177
}
133-
return os.WriteFile(filepath.Join(context.WorkSpaceDir, "scenarios.sh"), []byte(render), 0o600)
178+
render = strings.ReplaceAll(render, "\r\n", "\n")
179+
context.WorkSpaceDir = dir
180+
return os.WriteFile(filepath.Join(context.WorkSpaceDir, "wsl-scenarios.sh"), []byte(render), 0o600)
134181
}

0 commit comments

Comments
 (0)