From 92e2e6dba55a21b3b6062470bf7f0b5a496d06a9 Mon Sep 17 00:00:00 2001 From: daizhenyu <1449308021@qq.com> Date: Fri, 2 Aug 2024 11:28:43 +0800 Subject: [PATCH] xds integration optimization Signed-off-by: daizhenyu <1449308021@qq.com> --- .../client-envoy/action.yml | 17 +++++++++++++--- .../sermant-only/action.yml | 20 +++++++++++++++---- .../server-envoy/action.yml | 13 +++++++++++- .../discovery/spring-server-2-replicas.yaml | 6 +++--- .../spring-server-sermant-xds-open.yaml | 6 +++--- .../script/discovery/spring-server.yaml | 6 +++--- .../spring/client/SpringClientController.java | 10 ++++++++++ .../src/main/resources/application.properties | 1 + .../discovery/XdsServiceDiscoveryTest.java | 4 ++-- 9 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 sermant-integration-tests/xds-service-test/spring-server/src/main/resources/application.properties diff --git a/.github/actions/scenarios/xds-service/xds-service-discovery/client-envoy/action.yml b/.github/actions/scenarios/xds-service/xds-service-discovery/client-envoy/action.yml index c4ded7b759..7c4d75f2ac 100644 --- a/.github/actions/scenarios/xds-service/xds-service-discovery/client-envoy/action.yml +++ b/.github/actions/scenarios/xds-service/xds-service-discovery/client-envoy/action.yml @@ -12,20 +12,27 @@ runs: minikube image build -t spring-client:1.0.0 . eval $(minikube docker-env) docker images - - name: start spring-client using envoy + - name: start spring-client using envoy and wait shell: bash run: | kubectl label namespace default istio-injection=enabled kubectl apply -f sermant-integration-tests/xds-service-test/script/discovery/spring-client-sermant-xds-close.yaml kubectl wait --for=condition=ready pod -l app=spring-client --timeout=10s - kubectl port-forward svc/spring-client 8080:8080 & + sleep 10s + nohup kubectl port-forward svc/spring-client 8080:8080 & + sleep 2s + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8080/checkStatus 150 kubectl label namespace default istio-injection- - - name: Wait for spring-client pod to be ready + - name: start spring-server and wait shell: bash run: | kubectl apply -f sermant-integration-tests/xds-service-test/script/discovery/spring-server-sermant-xds-open.yaml kubectl wait --for=condition=ready pod -l app=spring-server --timeout=10s sleep 10s + nohup kubectl port-forward svc/spring-server 8081:8081 & + sleep 2s + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8081/hello 150 + pkill -f "kubectl port-forward svc/spring-server" - name: test one server shell: bash run: | @@ -47,6 +54,10 @@ runs: kubectl apply -f sermant-integration-tests/xds-service-test/script/discovery/spring-server-sermant-xds-open.yaml kubectl wait --for=condition=ready pod -l app=spring-server --timeout=10s sleep 10s + nohup kubectl port-forward svc/spring-server 8081:8081 & + sleep 2s + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8081/hello 150 + pkill -f "kubectl port-forward svc/spring-server" - name: test the number of spring-server instances changes from 0 to 1 shell: bash run: | diff --git a/.github/actions/scenarios/xds-service/xds-service-discovery/sermant-only/action.yml b/.github/actions/scenarios/xds-service/xds-service-discovery/sermant-only/action.yml index a3f14afd00..bb19ae758d 100644 --- a/.github/actions/scenarios/xds-service/xds-service-discovery/sermant-only/action.yml +++ b/.github/actions/scenarios/xds-service/xds-service-discovery/sermant-only/action.yml @@ -17,13 +17,19 @@ runs: run: | kubectl apply -f sermant-integration-tests/xds-service-test/script/discovery/spring-client-sermant-xds-open.yaml kubectl apply -f sermant-integration-tests/xds-service-test/script/discovery/spring-server.yaml - - name: Wait for spring-client pod to be ready + - name: Wait for spring-client pod and spring-server pod to be ready shell: bash run: | kubectl wait --for=condition=ready pod -l app=spring-client --timeout=10s kubectl wait --for=condition=ready pod -l app=spring-server --timeout=10s - kubectl port-forward svc/spring-client 8080:8080 & sleep 10s + nohup kubectl port-forward svc/spring-client 8080:8080 & + sleep 2s + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8080/checkStatus 150 + nohup kubectl port-forward svc/spring-server 8081:8081 & + sleep 2s + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8081/hello 150 + pkill -f "kubectl port-forward svc/spring-server" - name: test one server shell: bash run: | @@ -45,6 +51,10 @@ runs: kubectl apply -f sermant-integration-tests/xds-service-test/script/discovery/spring-server-2-replicas.yaml kubectl wait --for=condition=ready pod -l app=spring-server --timeout=10s sleep 10s + nohup kubectl port-forward svc/spring-server 8081:8081 & + sleep 2s + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8081/hello 150 + pkill -f "kubectl port-forward svc/spring-server" - name: test the number of spring-server instances changes from 0 to 2 shell: bash run: | @@ -66,9 +76,11 @@ runs: sleep 10s kubectl apply -f sermant-integration-tests/xds-service-test/script/discovery/spring-client-sermant-xds-subscribe-secure.yaml kubectl wait --for=condition=ready pod -l app=spring-client --timeout=10s - pkill -f "kubectl port-forward svc/spring-client" - kubectl port-forward svc/spring-client 8080:8080 & sleep 10s + pkill -f "kubectl port-forward svc/spring-client" + nohup kubectl port-forward svc/spring-client 8080:8080 & + sleep 2s + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8080/checkStatus 150 - name: test sermant xds service use security mode shell: bash run: | diff --git a/.github/actions/scenarios/xds-service/xds-service-discovery/server-envoy/action.yml b/.github/actions/scenarios/xds-service/xds-service-discovery/server-envoy/action.yml index f46e5fa5de..621bdc885c 100644 --- a/.github/actions/scenarios/xds-service/xds-service-discovery/server-envoy/action.yml +++ b/.github/actions/scenarios/xds-service/xds-service-discovery/server-envoy/action.yml @@ -17,7 +17,10 @@ runs: run: | kubectl apply -f sermant-integration-tests/xds-service-test/script/discovery/spring-client-sermant-xds-open.yaml kubectl wait --for=condition=ready pod -l app=spring-client --timeout=10s - kubectl port-forward svc/spring-client 8080:8080 & + sleep 10s + nohup kubectl port-forward svc/spring-client 8080:8080 & + sleep 2s + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8080/checkStatus 150 - name: start spring-server with envoy shell: bash run: | @@ -26,6 +29,10 @@ runs: kubectl apply -f sermant-integration-tests/xds-service-test/script/discovery/spring-server.yaml kubectl wait --for=condition=ready pod -l app=spring-server --timeout=10s sleep 10s + nohup kubectl port-forward svc/spring-server 8081:8081 & + sleep 2s + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8081/hello 150 + pkill -f "kubectl port-forward svc/spring-server" - name: test one server shell: bash run: | @@ -47,6 +54,10 @@ runs: kubectl apply -f sermant-integration-tests/xds-service-test/script/discovery/spring-server-2-replicas.yaml kubectl wait --for=condition=ready pod -l app=spring-server --timeout=10s sleep 10s + nohup kubectl port-forward svc/spring-server 8081:8081 & + sleep 2s + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8081/hello 150 + pkill -f "kubectl port-forward svc/spring-server" - name: test the number of spring-server instances changes from 0 to 2 shell: bash run: | diff --git a/sermant-integration-tests/xds-service-test/script/discovery/spring-server-2-replicas.yaml b/sermant-integration-tests/xds-service-test/script/discovery/spring-server-2-replicas.yaml index df6eeb1b67..c3ff585353 100644 --- a/sermant-integration-tests/xds-service-test/script/discovery/spring-server-2-replicas.yaml +++ b/sermant-integration-tests/xds-service-test/script/discovery/spring-server-2-replicas.yaml @@ -17,7 +17,7 @@ spec: image: spring-server:1.0.0 imagePullPolicy: Never ports: - - containerPort: 8080 + - containerPort: 8081 imagePullSecrets: - name: default-secret --- @@ -28,8 +28,8 @@ metadata: spec: type: ClusterIP ports: - - port: 8080 - targetPort: 8080 + - port: 8081 + targetPort: 8081 protocol: TCP name: http selector: diff --git a/sermant-integration-tests/xds-service-test/script/discovery/spring-server-sermant-xds-open.yaml b/sermant-integration-tests/xds-service-test/script/discovery/spring-server-sermant-xds-open.yaml index e10869ad20..794537a721 100644 --- a/sermant-integration-tests/xds-service-test/script/discovery/spring-server-sermant-xds-open.yaml +++ b/sermant-integration-tests/xds-service-test/script/discovery/spring-server-sermant-xds-open.yaml @@ -17,7 +17,7 @@ spec: image: spring-server:1.0.0 imagePullPolicy: Never ports: - - containerPort: 8080 + - containerPort: 8081 env: - name: JAVA_TOOL_OPTIONS value: "-javaagent:/home/agent/sermant-agent.jar" @@ -31,8 +31,8 @@ metadata: spec: type: ClusterIP ports: - - port: 8080 - targetPort: 8080 + - port: 8081 + targetPort: 8081 protocol: TCP name: http selector: diff --git a/sermant-integration-tests/xds-service-test/script/discovery/spring-server.yaml b/sermant-integration-tests/xds-service-test/script/discovery/spring-server.yaml index 952e0f5483..1d255c9711 100644 --- a/sermant-integration-tests/xds-service-test/script/discovery/spring-server.yaml +++ b/sermant-integration-tests/xds-service-test/script/discovery/spring-server.yaml @@ -17,7 +17,7 @@ spec: image: spring-server:1.0.0 imagePullPolicy: Never ports: - - containerPort: 8080 + - containerPort: 8081 imagePullSecrets: - name: default-secret --- @@ -28,8 +28,8 @@ metadata: spec: type: ClusterIP ports: - - port: 8080 - targetPort: 8080 + - port: 8081 + targetPort: 8081 protocol: TCP name: http selector: diff --git a/sermant-integration-tests/xds-service-test/spring-client/src/main/java/io/sermant/demo/spring/client/SpringClientController.java b/sermant-integration-tests/xds-service-test/spring-client/src/main/java/io/sermant/demo/spring/client/SpringClientController.java index b5f6579c78..12c7e02b03 100644 --- a/sermant-integration-tests/xds-service-test/spring-client/src/main/java/io/sermant/demo/spring/client/SpringClientController.java +++ b/sermant-integration-tests/xds-service-test/spring-client/src/main/java/io/sermant/demo/spring/client/SpringClientController.java @@ -85,6 +85,16 @@ public String hello(String address) { return httpGet(urlBuilder.toString()); } + /** + * check service status + * + * @return result + */ + @RequestMapping("checkStatus") + public String checkStatus() { + return "ok"; + } + private String httpGet(String url) { HttpGet httpGet = new HttpGet(url); try (CloseableHttpResponse response = httpClient.execute(httpGet)) { diff --git a/sermant-integration-tests/xds-service-test/spring-server/src/main/resources/application.properties b/sermant-integration-tests/xds-service-test/spring-server/src/main/resources/application.properties new file mode 100644 index 0000000000..bafddced85 --- /dev/null +++ b/sermant-integration-tests/xds-service-test/spring-server/src/main/resources/application.properties @@ -0,0 +1 @@ +server.port=8081 \ No newline at end of file diff --git a/sermant-integration-tests/xds-service-test/xds-service-integration-test/src/test/java/io/sermant/xds/service/discovery/XdsServiceDiscoveryTest.java b/sermant-integration-tests/xds-service-test/xds-service-integration-test/src/test/java/io/sermant/xds/service/discovery/XdsServiceDiscoveryTest.java index 05bdd4efa3..4660d27303 100644 --- a/sermant-integration-tests/xds-service-test/xds-service-integration-test/src/test/java/io/sermant/xds/service/discovery/XdsServiceDiscoveryTest.java +++ b/sermant-integration-tests/xds-service-test/xds-service-integration-test/src/test/java/io/sermant/xds/service/discovery/XdsServiceDiscoveryTest.java @@ -96,7 +96,7 @@ public void testDiscoveryWithSubscribe() { "DISCOVERY_ONE_SERVER_INSTANCE_ENVOY") public void testDiscoveryWithClientUsingEnvoyAndOneInstance() { Assertions.assertEquals("hello", HttpRequestUtils.doGet("http://127.0.0.1:8080/hello?address=spring-server" - + ".default.svc.cluster.local:8080")); + + ".default.svc.cluster.local:8081")); } /** @@ -107,7 +107,7 @@ public void testDiscoveryWithClientUsingEnvoyAndOneInstance() { "DISCOVERY_ZERO_SERVER_INSTANCE_ENVOY") public void testDiscoveryWithClientUsingEnvoyAndZeroInstance() { Assertions.assertEquals("", HttpRequestUtils.doGet("http://127.0.0.1:8080/hello?address=spring-server" - + ".default.svc.cluster.local:8080")); + + ".default.svc.cluster.local:8081")); } private String[] splitResult(String result) {