Skip to content

Commit 49a578c

Browse files
xelavopelkKlepov AlexCopilot
authored
Debug in the enviroment similar enviroment of feature tests (#1526)
Co-authored-by: Klepov Alex <aklepov@rutube.ru> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent bde3e14 commit 49a578c

File tree

10 files changed

+424
-2
lines changed

10 files changed

+424
-2
lines changed

.github/actions/spelling/expect.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ eshkere
112112
etcdctl
113113
etcdqdb
114114
expd
115+
extldflags
115116
FAFBFF
116117
fdw
117118
feauter
@@ -268,6 +269,7 @@ multicoordinator
268269
multidbpool
269270
multidim
270271
multierr
272+
multiclient
271273
multishard
272274
munakoiso
273275
murmurhash

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ build: build_balancer build_coordinator build_coorctl build_router build_mover b
5353

5454
build_images:
5555
docker compose build spqr-base-image
56+
docker compose build spqr-base-image-debug
5657
@if [ "x" != "${POSTGRES_VERSION}x" ]; then\
5758
echo "building ${POSTGRES_VERSION} version";\
5859
docker compose build --build-arg POSTGRES_VERSION=${POSTGRES_VERSION} --build-arg codename=${codename} spqr-shard-image;\

docker-compose.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ services:
1010
dockerfile: ./docker/spqr/Dockerfile
1111
context: .
1212

13+
spqr-base-image-debug:
14+
image: spqr-base-image-debug
15+
build:
16+
dockerfile: ./docker/spqr/Dockerfile.debug
17+
context: .
18+
1319
x-shard-common:
1420
&shard-common
1521
image: spqr-shard-image
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM spqr-base-image-debug
2+
EXPOSE 2345
3+
4+
CMD /go/bin/dlv --listen=:2345 --headless=true --log=true --accept-multiclient --log-output=rpc,dap --check-go-version=true exec /spqr/spqr-coordinator -- -c ${COORDINATOR_CONFIG}

docker/router/Dockerfile.debug

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM spqr-base-image-debug
2+
EXPOSE 2345
3+
4+
RUN apt-get update && apt-get install -y --no-install-recommends krb5-user postgresql-client
5+
COPY ./docker/router/ssl/localhost.crt /etc/spqr/ssl/server.crt
6+
COPY ./docker/router/ssl/localhost.key /etc/spqr/ssl/server.key
7+
8+
ENTRYPOINT ["/spqr/docker/router/entrypoint-debug.sh"]

docker/router/entrypoint-debug.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
function handle_term()
6+
{
7+
ps aux | grep '[s]pqr-router run' | awk '{print $2}' | xargs kill -TERM
8+
wait -n || exit $?
9+
exit
10+
}
11+
12+
trap 'handle_term' TERM
13+
trap
14+
CONFIG_PATH=${ROUTER_CONFIG=/spqr/docker/router/cfg.yaml}
15+
COORD_CONFIG_PATH=${COORDINATOR_CONFIG=/spqr/docker/coordinator/cfg.yaml}
16+
CUR_HOST=$(cat ${CONFIG_PATH} | grep "host:")
17+
sed "s/${CUR_HOST}/${ROUTER_HOST=${CUR_HOST}}/g" -i ${CONFIG_PATH}
18+
rm -f /tmp/.s.PGSQL.*
19+
echo ${CONFIG_PATH}
20+
/go/bin/dlv --listen=:2345 --headless=true --log=true --accept-multiclient --log-output=rpc,dap --check-go-version=true exec /spqr/spqr-router -- run --config ${CONFIG_PATH} &
21+
while true; do sleep 1; done
22+

docker/spqr/Dockerfile.debug

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM spqr-base-image
2+
3+
RUN CGO_ENABLED=0 go install -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@latest

test/feature/README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPQR Feature tests
22

3-
## Run feature tests on linux dev enviroment
3+
## Run feature tests on linux dev environment
44
1. Runing all tests
55
```bash
66
GODOG_FEATURE_DIR=generatedFeatures make feature_test;
@@ -30,4 +30,26 @@ export DOCKER_API_VERSION=1.47
3030
In case you are using Rancher Desktop
3131
> Error: failed to setup compose cluster: Cannot connect to the Docker daemon at unix:///var/run/docker. sock. Is the docker daemon running?
3232
33-
You need enable setting "Allow to acquire administrative credentials (sudo access)" in Preferences -> Application -> General
33+
You need to enable the setting "Allow acquiring of administrative credentials (sudo access)" in the Preferences -> Application -> General section.
34+
35+
36+
## Debug in the environment similar environment of feature tests on linux using VS Code
37+
1. Copy configurations from launch-example.json into .vscode\launch.json configurations for attach router, router2, coordinator and coordinator2.
38+
The following configurations will be available to you:
39+
- Attach router
40+
- Attach router2
41+
- Attach coordinator
42+
- Attach coordinator2
43+
2. Generate images using
44+
```shell
45+
make build_images
46+
```
47+
It generates image `spqr-base-image-debug` with delve in image.
48+
3. run test environment
49+
```shell
50+
docker compose --verbose -f ./test/feature/docker-compose-debug.yaml up
51+
```
52+
4. Attach to the required spqr cluster components in the required order. Only the components you will attach to will work.
53+
54+
### Troubleshooting
55+
- Fix toolchain version in .vscode\launch.json if you have problem in "Step into" action.
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
services:
2+
shard1:
3+
image: spqr-shard-image
4+
environment: &feature-env-common
5+
POSTGRES_USER: regress
6+
POSTGRES_DB: regress
7+
ports:
8+
- "5500:6432"
9+
hostname: spqr_shard_1
10+
container_name: spqr_shard_1
11+
healthcheck: &shard-healthcheck
12+
test: 'pg_isready -U regress --dbname=regress -p 6432'
13+
interval: 10s
14+
timeout: 3s
15+
retries: 50
16+
networks:
17+
- feature_test_network
18+
shard1-replica:
19+
image: spqr-shard-image
20+
environment:
21+
<<: *feature-env-common
22+
PG_MASTER: spqr_shard_1
23+
ports:
24+
- "5600:6432"
25+
hostname: spqr_shard_1_replica
26+
container_name: spqr_shard_1_replica
27+
healthcheck:
28+
<<: *shard-healthcheck
29+
networks:
30+
- feature_test_network
31+
shard2:
32+
image: spqr-shard-image
33+
environment:
34+
<<: *feature-env-common
35+
ports:
36+
- "5501:6432"
37+
hostname: spqr_shard_2
38+
container_name: spqr_shard_2
39+
healthcheck:
40+
<<: *shard-healthcheck
41+
networks:
42+
- feature_test_network
43+
shard2-replica:
44+
image: spqr-shard-image
45+
environment:
46+
<<: *feature-env-common
47+
PG_MASTER: spqr_shard_2
48+
ports:
49+
- "5601:6432"
50+
hostname: spqr_shard_2_replica
51+
container_name: spqr_shard_2_replica
52+
healthcheck:
53+
<<: *shard-healthcheck
54+
networks:
55+
- feature_test_network
56+
shard3:
57+
image: spqr-shard-image
58+
environment:
59+
<<: *feature-env-common
60+
ports:
61+
- "5502:6432"
62+
hostname: spqr_shard_3
63+
container_name: spqr_shard_3
64+
healthcheck:
65+
<<: *shard-healthcheck
66+
networks:
67+
- feature_test_network
68+
shard3-replica:
69+
image: spqr-shard-image
70+
environment:
71+
<<: *feature-env-common
72+
PG_MASTER: spqr_shard_3
73+
ports:
74+
- "5602:6432"
75+
hostname: spqr_shard_3_replica
76+
container_name: spqr_shard_3_replica
77+
healthcheck:
78+
<<: *shard-healthcheck
79+
networks:
80+
- feature_test_network
81+
router:
82+
build:
83+
dockerfile: ./docker/router/Dockerfile.debug
84+
context: ../../
85+
ports:
86+
- "2346:2345"
87+
- "6432:6432"
88+
- "7432:7432"
89+
- "7012:7002"
90+
environment:
91+
- ROUTER_CONFIG=/spqr/test/feature/conf/router.yaml
92+
- ROUTER_LOG=/var/log/spqr-router.log
93+
- COORDINATOR_CONFIG=/spqr/test/feature/conf/coordinator.yaml
94+
hostname: regress_router
95+
container_name: regress_router
96+
depends_on:
97+
shard1:
98+
condition: service_healthy
99+
shard2:
100+
condition: service_healthy
101+
shard1-replica:
102+
condition: service_healthy
103+
shard2-replica:
104+
condition: service_healthy
105+
shard3:
106+
condition: service_healthy
107+
shard3-replica:
108+
condition: service_healthy
109+
kdc:
110+
condition: service_started
111+
healthcheck: &router-healthcheck
112+
test: psql -h regress_router -p 6432 -U regress -d regress
113+
interval: 10s
114+
timeout: 3s
115+
retries: 50
116+
volumes:
117+
- keytab:/keytab
118+
- ./conf/kdc/krb5.conf:/etc/krb5.conf
119+
networks:
120+
- feature_test_network
121+
router2:
122+
build:
123+
dockerfile: ./docker/router/Dockerfile.debug
124+
context: ../../
125+
ports:
126+
- "2347:2345"
127+
- "6433:6432"
128+
- "7433:7432"
129+
- "7022:7002"
130+
environment:
131+
- ROUTER_CONFIG=/spqr/test/feature/conf/router.yaml
132+
- ROUTER_LOG=/var/log/spqr-router.log
133+
- COORDINATOR_CONFIG=/spqr/test/feature/conf/coordinator.yaml
134+
hostname: regress_router_2
135+
container_name: regress_router_2
136+
depends_on:
137+
shard1:
138+
condition: service_healthy
139+
shard2:
140+
condition: service_healthy
141+
shard1-replica:
142+
condition: service_healthy
143+
shard2-replica:
144+
condition: service_healthy
145+
shard3:
146+
condition: service_healthy
147+
shard3-replica:
148+
condition: service_healthy
149+
healthcheck:
150+
<<: *router-healthcheck
151+
test: psql -h regress_router_2 -p 6432 -U regress -d regress
152+
volumes:
153+
- keytab:/keytab
154+
- ./conf/kdc/krb5.conf:/etc/krb5.conf
155+
networks:
156+
- feature_test_network
157+
coordinator:
158+
build:
159+
dockerfile: ./docker/coordinator/Dockerfile.debug
160+
context: ../../
161+
ports:
162+
- "2345:2345"
163+
- "7002:7002"
164+
- "7003:7003"
165+
environment:
166+
- COORDINATOR_CONFIG=/spqr/test/feature/conf/coordinator.yaml
167+
hostname: regress_coordinator
168+
container_name: regress_coordinator
169+
depends_on:
170+
- "router"
171+
- "router2"
172+
- "qdb01"
173+
networks:
174+
- feature_test_network
175+
coordinator2:
176+
build:
177+
dockerfile: ./docker/coordinator/Dockerfile.debug
178+
context: ../../
179+
ports:
180+
- "2348:2345"
181+
- "7032:7002"
182+
- "7033:7003"
183+
environment:
184+
- COORDINATOR_CONFIG=/spqr/test/feature/conf/coordinator2.yaml
185+
hostname: regress_coordinator_2
186+
container_name: regress_coordinator_2
187+
depends_on:
188+
- "router"
189+
- "router2"
190+
- "qdb01"
191+
networks:
192+
- feature_test_network
193+
ldapserver:
194+
image: "osixia/openldap:latest"
195+
hostname: regress_ldap_server
196+
container_name: regress_ldap_server
197+
environment:
198+
- LDAP_ROOT=dc=example,dc=com
199+
- LDAP_ADMIN_USERNAME=admin
200+
- LDAP_ADMIN_PASSWORD=adminpassword
201+
- LDAP_USERS=regress
202+
- LDAP_PASSWORDS=12345678
203+
- LDAP_PORT_NUMBER=389
204+
- LDAP_LDAPS_PORT_NUMBER=636
205+
ports:
206+
- "1389:389"
207+
- "1636:636"
208+
healthcheck: &ldap-healthcheck
209+
test: ldapwhoami -D "cn=regress,ou=users,dc=example,dc=com" -w 12345678
210+
interval: 10s
211+
timeout: 3s
212+
retries: 50
213+
networks:
214+
- feature_test_network
215+
ldapserver2:
216+
image: "osixia/openldap:latest"
217+
hostname: regress_ldap_server_2
218+
container_name: regress_ldap_server_2
219+
environment:
220+
- LDAP_ROOT=dc=example,dc=com
221+
- LDAP_ADMIN_USERNAME=admin
222+
- LDAP_ADMIN_PASSWORD=adminpassword
223+
- LDAP_USERS=regress
224+
- LDAP_PASSWORDS=12345678
225+
- LDAP_PORT_NUMBER=389
226+
- LDAP_LDAPS_PORT_NUMBER=636
227+
ports:
228+
- "2389:389"
229+
- "2636:636"
230+
healthcheck:
231+
<<: *ldap-healthcheck
232+
networks:
233+
- feature_test_network
234+
qdb01:
235+
image: 'quay.io/coreos/etcd:v3.6.4'
236+
hostname: regress_qdb_0_1
237+
container_name: regress_qdb_0_1
238+
environment:
239+
ALLOW_NONE_AUTHENTICATION: "yes"
240+
ETCD_LOG_LEVEL: "debug"
241+
ports:
242+
- "2379:2379"
243+
networks:
244+
- feature_test_network
245+
entrypoint: ["/usr/local/bin/etcd", "--advertise-client-urls", "http://regress_qdb_0_1:2379", "--listen-client-urls", "http://0.0.0.0:2379"]
246+
247+
kdc:
248+
build:
249+
context: ./conf/kdc
250+
volumes:
251+
- ./conf/kdc/start.sh:/start.sh
252+
- keytab:/keytab
253+
networks:
254+
- feature_test_network
255+
volumes:
256+
keytab:
257+
networks:
258+
feature_test_network:
259+
name: feature_test_network
260+

0 commit comments

Comments
 (0)