From 1e9f929f978ac7fbad11832176ce7b0190181a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E7=8E=89=E6=A1=94?= Date: Wed, 25 Dec 2019 17:25:09 +0800 Subject: [PATCH] [test/plugin] immigrate test zookeeper scenario. (#4106) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * zookeeper test * update expected data file * fix review code * fixed * bugfix * update version * fix bug * fix Co-authored-by: zhang-wei Co-authored-by: 吴晟 Wu Sheng --- .github/workflows/plugins-test.yaml | 4 +- .../java-agent/Supported-list.md | 2 +- .../zookeeper-scenario/bin/startup.sh | 21 +++ .../config/expectedData.yaml | 133 ++++++++++++++++ .../zookeeper-scenario/configuration.yml | 31 ++++ .../scenarios/zookeeper-scenario/pom.xml | 148 ++++++++++++++++++ .../src/main/assembly/assembly.xml | 41 +++++ .../apm/testcase/zookeeper/Application.java | 35 +++++ .../zookeeper/controller/Zookeeper.java | 46 ++++++ .../controller/ZookeeperController.java | 64 ++++++++ .../src/main/resources/application.properties | 20 +++ .../src/main/resources/log4j2.xml | 30 ++++ .../zookeeper-scenario/support-version.list | 30 ++++ 13 files changed, 603 insertions(+), 2 deletions(-) create mode 100644 test/plugin/scenarios/zookeeper-scenario/bin/startup.sh create mode 100644 test/plugin/scenarios/zookeeper-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/zookeeper-scenario/configuration.yml create mode 100644 test/plugin/scenarios/zookeeper-scenario/pom.xml create mode 100644 test/plugin/scenarios/zookeeper-scenario/src/main/assembly/assembly.xml create mode 100644 test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/Application.java create mode 100644 test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/controller/Zookeeper.java create mode 100644 test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/controller/ZookeeperController.java create mode 100644 test/plugin/scenarios/zookeeper-scenario/src/main/resources/application.properties create mode 100644 test/plugin/scenarios/zookeeper-scenario/src/main/resources/log4j2.xml create mode 100644 test/plugin/scenarios/zookeeper-scenario/support-version.list diff --git a/.github/workflows/plugins-test.yaml b/.github/workflows/plugins-test.yaml index 0fb8c5d57..4b4a433c7 100644 --- a/.github/workflows/plugins-test.yaml +++ b/.github/workflows/plugins-test.yaml @@ -296,7 +296,7 @@ jobs: - name: Run mongodb 3.4.0-3.11.1 (17) run: bash test/plugin/run.sh mongodb-3.x-scenario - Redisson_ShardingSphere: + Redisson_ShardingSphere_Zookeeper: runs-on: ubuntu-18.04 timeout-minutes: 90 strategy: @@ -322,6 +322,8 @@ jobs: run: bash test/plugin/run.sh redisson-scenario - name: Run shardingsphere-3.x-scenario 3.0.0 (1) run: bash test/plugin/run.sh shardingsphere-3.x-scenario + - name: Run zookeeper 3.4.x (14) + run: bash test/plugin/run.sh zookeeper-scenario Spring43: runs-on: ubuntu-18.04 diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md index 92d66c4f1..8d408c625 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -67,7 +67,7 @@ * Service Discovery * [Netflix Eureka](https://github.com/Netflix/eureka) * Distributed Coordination - * [Zookeeper](https://github.com/apache/zookeeper) 3.4.0+ (Optional² & Except 3.4.4) + * [Zookeeper](https://github.com/apache/zookeeper) 3.4.x (Optional² & Except 3.4.4) * Spring Ecosystem * Spring Bean annotations(@Bean, @Service, @Component, @Repository) 3.x and 4.x (Optional²) * Spring Core Async SuccessCallback/FailureCallback/ListenableFutureCallback 4.x diff --git a/test/plugin/scenarios/zookeeper-scenario/bin/startup.sh b/test/plugin/scenarios/zookeeper-scenario/bin/startup.sh new file mode 100644 index 000000000..30c9f35f9 --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/bin/startup.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +home="$(cd "$(dirname $0)"; pwd)" + +java -Dzookeeper.host=${ZK_ADDRESS} -jar ${agent_opts} ${home}/../libs/zookeeper-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/zookeeper-scenario/config/expectedData.yaml b/test/plugin/scenarios/zookeeper-scenario/config/expectedData.yaml new file mode 100644 index 000000000..6fb9f3750 --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/config/expectedData.yaml @@ -0,0 +1,133 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +registryItems: + applications: + - {zookeeper-scenario: 2} + instances: + - {zookeeper-scenario: 1} + operationNames: + - zookeeper-scenario: [Zookeeper/WatchedEvent/NodeDeleted, /zookeeper-scenario/case/zookeeper-case, + /zookeeper-scenario/case/healthCheck] + heartbeat: [] +segmentItems: + - applicationCode: zookeeper-scenario + segmentSize: nq 0 + segments: + - segmentId: not null + spans: + - operationName: Zookeeper/exists + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Cache + startTime: not null + endTime: not null + componentId: 58 + componentName: '' + isError: false + spanType: Exit + peer: not null + peerId: 0 + tags: + - {key: db.type, value: Zookeeper} + - {key: path, value: /path} + - {key: watch, value: 'true'} + - operationName: Zookeeper/WatchedEvent/NodeDeleted + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: not null + endTime: not null + componentId: 58 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: path, value: /path} + - {key: state, value: SyncConnected} + - {key: db.type, value: Zookeeper} + - segmentId: not null + spans: + - operationName: Zookeeper/create + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Cache + startTime: not null + endTime: not null + componentId: 58 + componentName: '' + isError: false + spanType: Exit + peer: not null + peerId: 0 + tags: + - {key: db.type, value: Zookeeper} + - {key: path, value: /path} + - operationName: Zookeeper/exists + operationId: 0 + parentSpanId: 0 + spanId: 2 + spanLayer: Cache + startTime: not null + endTime: not null + componentId: 58 + componentName: '' + isError: false + spanType: Exit + peer: not null + peerId: 0 + tags: + - {key: db.type, value: Zookeeper} + - {key: path, value: /path} + - {key: watch, value: 'true'} + - operationName: Zookeeper/delete + operationId: 0 + parentSpanId: 0 + spanId: 3 + spanLayer: Cache + startTime: not null + endTime: not null + componentId: 58 + componentName: '' + isError: false + spanType: Exit + peer: not null + peerId: 0 + tags: + - {key: db.type, value: Zookeeper} + - {key: path, value: /path} + - {key: version, value: '-1'} + - operationName: /zookeeper-scenario/case/zookeeper-case + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: not null + endTime: not null + componentId: 1 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: url, value: not null} + - {key: http.method, value: GET} \ No newline at end of file diff --git a/test/plugin/scenarios/zookeeper-scenario/configuration.yml b/test/plugin/scenarios/zookeeper-scenario/configuration.yml new file mode 100644 index 000000000..53aca6225 --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/configuration.yml @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +type: jvm +entryService: http://localhost:8080/zookeeper-scenario/case/zookeeper-case +healthCheck: http://localhost:8080/zookeeper-scenario/case/healthCheck +startScript: ./bin/startup.sh +framework: zookeeper +runningMode: with_optional +withPlugins: apm-zookeeper-3.4.x-plugin-*.jar +environment: + - ZK_ADDRESS=zk-server:2181 +depends_on: + - zk-server +dependencies: + zk-server: + image: zookeeper:3.4.10 + hostname: zk-server \ No newline at end of file diff --git a/test/plugin/scenarios/zookeeper-scenario/pom.xml b/test/plugin/scenarios/zookeeper-scenario/pom.xml new file mode 100644 index 000000000..4cbbf00e6 --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/pom.xml @@ -0,0 +1,148 @@ + + + + 4.0.0 + + org.apache.skywalking + zookeeper-scenario + 5.0.0 + + + UTF-8 + 1.8 + 3.4.13 + ${test.framework.version} + 2.6.2 + 4.3.8.RELEASE + 1.5.2.RELEASE + + + skywalking-zookeeper-scenario + + + + org.apache.zookeeper + zookeeper + ${test.framework.version} + + + org.slf4j + * + + + log4j + * + + + + + + org.springframework.boot + spring-boot-starter + ${spring-boot-version} + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} + + + org.apache.logging.log4j + log4j-jcl + ${log4j.version} + + + org.springframework.boot + spring-boot-starter-tomcat + ${spring-boot-version} + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot-version} + + + + + zookeeper-scenario + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + maven-compiler-plugin + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assemble + package + + single + + + + src/main/assembly/assembly.xml + + ./target/ + + + + + + + + + + spring-snapshots + http://repo.spring.io/snapshot + + + spring-milestones + http://repo.spring.io/milestone + + + \ No newline at end of file diff --git a/test/plugin/scenarios/zookeeper-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/zookeeper-scenario/src/main/assembly/assembly.xml new file mode 100644 index 000000000..efdd1b978 --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/zookeeper-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/Application.java b/test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/Application.java new file mode 100644 index 000000000..3c23131f7 --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/Application.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.testcase.zookeeper; + +import org.springframework.boot.SpringApplication; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + try { + SpringApplication.run(Application.class, args); + } catch (Exception e) { + // Never do this + } + } +} diff --git a/test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/controller/Zookeeper.java b/test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/controller/Zookeeper.java new file mode 100644 index 000000000..23e05ea03 --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/controller/Zookeeper.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.testcase.zookeeper.controller; + +import org.apache.zookeeper.ZooKeeper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +import java.io.IOException; + + +@Configuration +@PropertySource("classpath:application.properties") +public class Zookeeper { + + private Logger logger = LoggerFactory.getLogger(Zookeeper.class); + + @Value(value = "${zookeeper.host}") + private String address; + + @Bean + public ZooKeeper zooKeeper() throws IOException { + ZooKeeper zooKeeper = new ZooKeeper(address, 8000, event -> logger.info("process")); + return zooKeeper; + } +} diff --git a/test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/controller/ZookeeperController.java b/test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/controller/ZookeeperController.java new file mode 100644 index 000000000..c4cf47085 --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/src/main/java/org/apache/skywalking/apm/testcase/zookeeper/controller/ZookeeperController.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.testcase.zookeeper.controller; + +import org.apache.zookeeper.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping("/case") +@PropertySource("classpath:application.properties") +public class ZookeeperController { + private Logger logger = LoggerFactory.getLogger(ZookeeperController.class); + + @Autowired + private ZooKeeper zooKeeper; + + @RequestMapping("/zookeeper-case") + @ResponseBody + public String zookeeperCase() throws KeeperException, InterruptedException { + zooKeeper.create("/path", "data".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + zooKeeper.exists("/path", watcher); + zooKeeper.delete("/path", -1); + return "Success"; + } + + @RequestMapping("/healthCheck") + @ResponseBody + public String healthCheck() { + return "healthCheck"; + } + + private Watcher watcher = new Watcher() { + @Override + public void process(WatchedEvent event) { + try { + zooKeeper.exists("/path", this); + } catch (Exception e) { + logger.error("error", e); + } + } + }; +} diff --git a/test/plugin/scenarios/zookeeper-scenario/src/main/resources/application.properties b/test/plugin/scenarios/zookeeper-scenario/src/main/resources/application.properties new file mode 100644 index 000000000..ef8724c4d --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/src/main/resources/application.properties @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +server.port=8080 +server.contextPath=/zookeeper-scenario diff --git a/test/plugin/scenarios/zookeeper-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/zookeeper-scenario/src/main/resources/log4j2.xml new file mode 100644 index 000000000..9849ed5a8 --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/zookeeper-scenario/support-version.list b/test/plugin/scenarios/zookeeper-scenario/support-version.list new file mode 100644 index 000000000..dd9517c47 --- /dev/null +++ b/test/plugin/scenarios/zookeeper-scenario/support-version.list @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +3.4.14 +3.4.13 +3.4.12 +3.4.11 +3.4.10 +3.4.9 +3.4.8 +3.4.7 +3.4.6 +3.4.5 +3.4.3 +3.4.2 +3.4.1 +3.4.0 \ No newline at end of file