提交 0114391d 编写于 作者: D Daming 提交者: wu-sheng

test/plugin autotest (#3528)

Provide the codebase of plugin tests. Make the plugin test in the CI loop.
上级 0a8c8643
/*
* 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.
*
*/
pipeline {
agent {
label 'skywalking'
}
options {
timestamps()
timeout(time: 5, unit: 'HOURS')
}
tools {
jdk 'JDK 1.8 (latest)'
}
environment {
MAVEN_OPTS = '-Dmaven.repo.local=.m2/repository -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:-UseGCOverheadLimit -Xmx3g'
}
stages {
stage('Checkout Source Code') {
steps {
deleteDir()
checkout scm
sh 'git submodule update --init'
}
}
stage('Compile agent Codes') {
steps {
sh './mvnw -Pagent clean package -DskipTests'
}
}
stage('Compile plugin-test tools Codes') {
steps {
sh './mvnw -f test/plugin/pom.xml -Pagent clean package -DskipTests -Dbuild_id=${BUILD_ID} docker:build'
}
}
stage('httpclient 4.3.x-4.5.x') {
steps {
sh 'bash test/plugin/run.sh --build_id=${BUILD_ID} httpclient-4.3.x-scenario'
}
}
}
post {
always {
deleteDir()
}
}
}
# 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.
FROM openjdk:7
MAINTAINER zhangxin@apache.org
ADD docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
RUN ["/bin/bash"]
#!/bin/sh
# 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.
/usr/local/skywalking-agent-scenario/skywalking-mock-collector/collector-startup.sh &
sleep 30
# start applications
exec "$@" &
sleep 60
curl ${SCENARIO_ENTRY_SERVICE}
sleep 40
curl http://localhost:12800/receiveData > ${SCENARIO_DATA}/${SCENARIO_NAME}_${SCENARIO_VERSION}/actualData.yaml
#
echo "Scenario[${SCENARIO_NAME}, ${SCENARIO_VERSION}] build successfully!"
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>org.apache.skywalking.plugin</groupId>
<artifactId>containers</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>jvm-container</artifactId>
<name>agent-test-jvm</name>
<properties>
<skip.docker>false</skip.docker>
</properties>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<parent>
<groupId>org.apache.skywalking.plugin</groupId>
<artifactId>apache-skywalking-test-plugin</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>containers</artifactId>
<modules>
<module>tomcat-container</module>
<module>jvm-container</module>
</modules>
<properties>
<skip.docker>true</skip.docker>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker-maven-plugin.version}</version>
<configuration>
<imageTags>${build_id}</imageTags>
<imageName>skywalking/${project.name}</imageName>
<dockerDirectory>${project.basedir}/docker</dockerDirectory>
<skipDocker>${skip.docker}</skipDocker>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.basedir}/../../dist</directory>
<include>skywalking-mock-collector.tar.gz</include>
<include>skywalking-validator-tools.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>
# 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.
FROM tomcat:8.5.42-jdk8-openjdk
MAINTAINER zhangxin@apache.org
WORKDIR /usr/local/skywalking/tools
COPY run.sh /
COPY catalina.sh /usr/local/tomcat/bin/
COPY skywalking-validator-tools.jar /usr/local/skywalking/tools
COPY skywalking-mock-collector.tar.gz /usr/local/skywalking/tools
RUN tar -xvf skywalking-mock-collector.tar.gz -C /usr/local/skywalking/tools
RUN chmod +x /usr/local/tomcat/bin/catalina.sh && chmod +x /run.sh
WORKDIR /usr/local/skywalking/scenario
CMD ["/run.sh"]
#!/usr/bin/env 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.
function exitOnError() {
echo -e "\033[31m[ERROR] $1\033[0m">&2
exitAndClean 1
}
function exitAndClean() {
[[ -f ${SCENARIO_HOME}/data/actualData.yaml ]] && rm -rf ${SCENARIO_HOME}/data/actualData.yaml
[[ -d ${SCENARIO_HOME}/logs ]] && rm -rf ${SCENARIO_HOME}/logs
exit $1
}
function healthCheck() {
HEALTH_CHECK_URL=$1
for ((i=1; i<=10; i++));
do
STATUS_CODE="$(curl -Is ${HEALTH_CHECK_URL} | head -n 1)"
if [[ $STATUS_CODE == *"200"* ]]; then
echo "${HEALTH_CHECK_URL}: ${STATUS_CODE}"
return 0
fi
sleep 2
done
exitOnError "${SCENARIO_NAME}-${SCENARIO_VERSION} health check failed!"
}
TOOLS_HOME=/usr/local/skywalking/tools
SCENARIO_HOME=/usr/local/skywalking/scenario
# Speed up launch tomcat
rm /usr/local/tomcat/webapps/* -rf # remove needn't app
sed -i "s%securerandom.source=file:/dev/random%securerandom.source=file:/dev/urandom%g" $JAVA_HOME/jre/lib/security/java.security
# To deploy testcase
cp ${SCENARIO_HOME}/*.war /usr/local/tomcat/webapps/
# start mock collector
echo "To start mock collector"
${TOOLS_HOME}/skywalking-mock-collector/bin/collector-startup.sh 1>/dev/null &
healthCheck http://localhost:12800/receiveData
echo "To start tomcat"
/usr/local/tomcat/bin/catalina.sh start 1>/dev/null &
healthCheck ${SCENARIO_HEALTH_CHECK_URL}
echo "To visit entry service"
curl -s ${SCENARIO_ENTRY_SERVICE}
sleep 5
echo "To receive actual data"
curl -s http://localhost:12800/receiveData > ${SCENARIO_HOME}/data/actualData.yaml
[[ ! -f ${SCENARIO_HOME}/data/actualData.yaml ]] && exitOnError "${SCENARIO_NAME}-${SCENARIO_VERSION}, 'actualData.yaml' Not Found!"
echo "To validate"
java -jar \
-Dv2=true \
-Xmx256m -Xms256m \
-DtestDate="`date +%Y-%m-%d-%H-%M`" \
-DtestCasePath=${SCENARIO_HOME}/data/ \
${TOOLS_HOME}/skywalking-validator-tools.jar 1>/dev/null
status=$?
if [[ $status -eq 0 ]]; then
echo "Scenario[${SCENARIO_NAME}-${SCENARIO_VERSION}] passed!" >&2
else
cat ${SCENARIO_HOME}/data/actualData.yaml >&2
exitOnError "Scenario[${SCENARIO_NAME}-${SCENARIO_VERSION}] failed!"
fi
exitAndClean $status
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>org.apache.skywalking.plugin</groupId>
<artifactId>containers</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>tomcat-container</artifactId>
<name>agent-test-tomcat</name>
<properties>
<skip.docker>false</skip.docker>
</properties>
</project>
#!/usr/bin/env 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.
PRG="$0"
PRGDIR=`dirname "$PRG"`
[ -z "$COLLECTOR_HOME" ] && COLLECTOR_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
_RUNJAVA=${JAVA_HOME}/bin/java
[ -z "$JAVA_HOME" ] && _RUNJAVA=`java`
CLASSPATH="$COLLECTOR_HOME/config:$CLASSPATH"
for i in "$COLLECTOR_HOME"/libs/*.jar
do
CLASSPATH="$i:$CLASSPATH"
done
JAVA_OPTS="${JAVA_OPTS} -Xmx256m -Xms256m"
JAVA_OPTS="${JAVA_OPTS} -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 "
$_RUNJAVA ${JAVA_OPTS} -classpath $CLASSPATH org.apache.skywalking.plugin.test.mockcollector.Main
# 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.
FROM openjdk:8-jdk
ENV GRPC_BIND_HOST=127.0.0.1 \
GRPC_BIND_PORT=19876
ADD skywalking-mock-collector.tar.gz /usr/local
ADD config.properties /usr/local/skywalking-mock-collector/config/config.properties
EXPOSE 12800
EXPOSE 5005
ADD docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/usr/local/skywalking-mock-collector/bin/collector-startup.sh"]
# 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.
grpc_bind_host={GRPC_BIND_HOST}
grpc_bind_port={GRPC_BIND_PORT}
#!/usr/bin/env 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.
echo "replace GRPC_BIND_HOST with $GRPC_BIND_HOST"
eval sed -i -e 's/\{GRPC_BIND_HOST\}/$GRPC_BIND_HOST/' /usr/local/skywalking-mock-collector/config/config.properties
echo "replace GRPC_BIND_PORT with $GRPC_BIND_PORT"
eval sed -i -e 's/\{GRPC_BIND_PORT\}/$GRPC_BIND_PORT/' /usr/local/skywalking-mock-collector/config/config.properties
exec "$@"
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.skywalking.plugin</groupId>
<artifactId>apache-skywalking-test-plugin</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>skywalking-mock-collector</artifactId>
<version>6.0.0-2018</version>
<packaging>jar</packaging>
<name>skywalking-mock-collector</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<grpc.version>1.4.0</grpc.version>
<netty.version>4.1.12.Final</netty.version>
<jetty.version>9.4.2.v20170220</jetty.version>
<gson.version>2.8.0</gson.version>
<snakeyaml.version>1.18</snakeyaml.version>
<docker.image.name>skywalking/mock-collector</docker.image.name>
<docker.image.version>${project.version}</docker.image.version>
</properties>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>${grpc.version}</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http2</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-handler-proxy</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http2</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
</dependencies>
<build>
<finalName>skywalking-mock-collector</finalName>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier}
</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}
</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<outputDirectory>${project.basedir}/../dist</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<skipDocker>true</skipDocker>
<imageName>${docker.image.name}</imageName>
<imageTags>
<imageTag>${docker.image.version}</imageTag>
</imageTags>
<dockerDirectory>${project.basedir}/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.basedir}/../dist</directory>
<include>${build.finalName}.tar.gz</include>
</resource>
</resources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<excludes>
<exclude>*.properties</exclude>
<exclude>*.yaml</exclude>
<exclude>*.xml</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
<!--
~ 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.
~
-->
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id></id>
<formats>
<format>tar.gz</format>
</formats>
<dependencySets>
<dependencySet>
<outputDirectory>/libs</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.basedir}/bin</directory>
<outputDirectory>/bin</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>collector.properties</include>
<include>log4j2.xml</include>
</includes>
<outputDirectory>/config</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/libs</outputDirectory>
<includes>
<include>${build.finalName}.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
/*
* 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.plugin.test.mockcollector;
import io.grpc.netty.NettyServerBuilder;
import io.netty.channel.local.LocalAddress;
import java.net.InetSocketAddress;
import org.apache.skywalking.plugin.test.mockcollector.service.*;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
public class Main {
public static void main(String[] args) throws Exception {
NettyServerBuilder.forAddress(LocalAddress.ANY).forPort(19876)
.maxConcurrentCallsPerConnection(12).maxMessageSize(16777216)
.addService(new MockRegisterService())
.addService(new MockInstancePingService())
.addService(new MockJVMMetricsService())
.addService(new MockTraceSegmentV1Service())
.addService(new MockApplicationRegisterService())
.addService(new MockInstanceDiscoveryService())
.addService(new MockJVMMetricsV1Service())
.addService(new MockNetworkAddressRegisterService())
.addService(new MockServiceNameDiscoveryService())
.addService(new MockTraceSegmentService())
.addService(new MockJVMMetricReportService())
.build().start();
Server jettyServer = new Server(new InetSocketAddress("0.0.0.0",
Integer.valueOf(12800)));
String contextPath = "/";
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
servletContextHandler.setContextPath(contextPath);
servletContextHandler.addServlet(GrpcAddressHttpService.class, GrpcAddressHttpService.SERVLET_PATH);
servletContextHandler.addServlet(ReceiveDataService.class, ReceiveDataService.SERVLET_PATH);
servletContextHandler.addServlet(ClearReceiveDataService.class, ClearReceiveDataService.SERVLET_PATH);
jettyServer.setHandler(servletContextHandler);
jettyServer.start();
}
}
/*
* 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.plugin.test.mockcollector.entity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.skywalking.apm.network.language.agent.SpanType;
public class RegistryItem {
/**
* applicationCode, applicationId
*/
private final Map<String, Integer> applications;
/**
* applicationCode, operationName
*/
private final Map<String, Set<String>> operationNames;
/**
* applicationCode, instanceId
*/
private final Map<String, List<Integer>> instanceMapping;
/**
* applicationCode, count
*/
private final Map<String, Integer> heartBeats;
public RegistryItem() {
applications = new HashMap<>();
operationNames = new HashMap<>();
instanceMapping = new HashMap<>();
heartBeats = new HashMap<>();
}
public void registryApplication(Application application) {
applications.putIfAbsent(application.applicationCode, application.applicationId);
}
public void registryOperationName(OperationName operationName) {
String applicationCode = findApplicationCode(operationName.applicationId);
Set<String> operationNameList = operationNames.get(applicationCode);
if (operationNameList == null) {
operationNameList = new HashSet<>();
operationNames.put(applicationCode, operationNameList);
}
operationNameList.add(operationName.operationName);
}
public void registryInstance(Instance instance) {
String applicationCode = findApplicationCode(instance.applicationId);
List<Integer> instances = instanceMapping.get(applicationCode);
if (instances == null) {
instances = new ArrayList<>();
instanceMapping.put(applicationCode, instances);
}
if (!instances.contains(instance)) {
instances.add(instance.instanceId);
}
}
public String findApplicationCode(int id) {
for (Map.Entry<String, Integer> entry : applications.entrySet()) {
if (entry.getValue() == id) {
return entry.getKey();
}
}
throw new RuntimeException("Cannot found the code of applicationID[" + id + "].");
}
public void registryHeartBeat(HeartBeat heartBeat) {
for (Map.Entry<String, List<Integer>> entry : instanceMapping.entrySet()) {
if (entry.getValue().contains(heartBeat.instanceID)) {
Integer count = heartBeats.get(entry.getKey());
if (count != null) {
heartBeats.put(entry.getKey(), 0);
heartBeats.put(entry.getKey(), count++);
}
}
}
}
public static class OperationName {
int applicationId;
String operationName;
public OperationName(int applicationId, String operationName) {
this.applicationId = applicationId;
this.operationName = operationName;
}
}
public static class Application {
String applicationCode;
int applicationId;
public Application(String applicationCode, int applicationId) {
this.applicationCode = applicationCode;
this.applicationId = applicationId;
}
}
public static class Instance {
int applicationId;
int instanceId;
public Instance(int applicationId, int instanceId) {
this.applicationId = applicationId;
this.instanceId = instanceId;
}
}
public static class HeartBeat {
private int instanceID;
public HeartBeat(int instanceID) {
this.instanceID = instanceID;
}
}
public Map<String, Integer> getApplications() {
return applications;
}
public Map<String, Set<String>> getOperationNames() {
return operationNames;
}
public Map<String, List<Integer>> getInstanceMapping() {
return instanceMapping;
}
public Map<String, Integer> getHeartBeats() {
return heartBeats;
}
}
/*
* 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.plugin.test.mockcollector.entity;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
public class RegistryItemSerializer implements JsonSerializer<RegistryItem> {
@Override
public JsonElement serialize(RegistryItem src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject jsonObject = new JsonObject();
JsonArray applicationArrays = new JsonArray();
src.getApplications().forEach((applicationCode, applicationId) -> {
JsonObject applicationJson = new JsonObject();
applicationJson.addProperty(applicationCode, applicationId);
applicationArrays.add(applicationJson);
});
jsonObject.add("applications", applicationArrays);
JsonArray instanceArrays = new JsonArray();
src.getInstanceMapping().forEach((applicationCode, instanceIds) -> {
JsonObject instanceJson = new JsonObject();
instanceJson.addProperty(applicationCode, instanceIds.size());
instanceArrays.add(instanceJson);
});
jsonObject.add("instances", instanceArrays);
JsonArray operationNameArrays = new JsonArray();
src.getOperationNames().forEach((applicationCode, operationNames) -> {
JsonObject instanceJson = new JsonObject();
instanceJson.add(applicationCode, new Gson().toJsonTree(operationNames));
operationNameArrays.add(instanceJson);
});
jsonObject.add("operationNames", operationNameArrays);
JsonArray heartBeatArrays = new JsonArray();
src.getHeartBeats().forEach((applicationCode, count) -> {
JsonObject instanceJson = new JsonObject();
instanceJson.addProperty(applicationCode, count);
heartBeatArrays.add(instanceJson);
});
jsonObject.add("heartbeat", heartBeatArrays);
return jsonObject;
}
}
/*
* 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.plugin.test.mockcollector.entity;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.ToString;
import org.apache.skywalking.apm.network.language.agent.UniqueId;
@ToString
@Builder
@AllArgsConstructor
public class Segment {
private String segmentId;
private List<Span> spans;
public static class SegmentBuilder {
public SegmentBuilder addSpan(Span.SpanBuilder spanBuilder) {
if (spans == null) {
this.spans = new ArrayList<>();
}
spans.add(spanBuilder.build());
return this;
}
public SegmentBuilder segmentId(UniqueId segmentUniqueId) {
segmentId = String.join(".", Long.toString(segmentUniqueId.getIdParts(0)), Long.toString(segmentUniqueId.getIdParts(1)), Long.toString(segmentUniqueId.getIdParts(2)));
return this;
}
}
}
/*
* 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.plugin.test.mockcollector.entity;
import java.util.ArrayList;
import java.util.List;
public class SegmentItem {
private String applicationCode;
private List<Segment> segments;
public SegmentItem(String applicationCode) {
this.applicationCode = applicationCode;
segments = new ArrayList<>();
}
public void addSegments(Segment item) {
segments.add(item);
}
public String getApplicationCode() {
return applicationCode;
}
public List<Segment> getSegments() {
return segments;
}
}
/*
* 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.plugin.test.mockcollector.entity;
import java.util.HashMap;
import java.util.Map;
public class SegmentItems {
private Map<String, SegmentItem> segmentItems;
public SegmentItems() {
this.segmentItems = new HashMap<>();
}
public SegmentItems addSegmentItem(int applicationId, Segment segment) {
String applicationCode = ValidateData.INSTANCE.getRegistryItem().findApplicationCode(applicationId);
SegmentItem segmentItem = segmentItems.get(applicationCode);
if (segmentItem == null) {
segmentItem = new SegmentItem(applicationCode);
segmentItems.put(applicationCode, segmentItem);
}
segmentItem.addSegments(segment);
return this;
}
public Map<String, SegmentItem> getSegmentItems() {
return segmentItems;
}
}
/*
* 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.plugin.test.mockcollector.entity;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
public class SegmentItemsSerializer implements JsonSerializer<SegmentItems> {
@Override
public JsonElement serialize(SegmentItems src, Type typeOfSrc, JsonSerializationContext context) {
JsonArray applicationSegmentItems = new JsonArray();
src.getSegmentItems().forEach((applicationCode, segmentItem) -> {
JsonObject segmentJson = new JsonObject();
segmentJson.addProperty("applicationCode", applicationCode);
segmentJson.addProperty("segmentSize", segmentItem.getSegments().size());
JsonArray segments = new JsonArray();
segmentItem.getSegments().forEach(segment -> {
segments.add(new Gson().toJsonTree(segment));
});
segmentJson.add("segments", segments);
applicationSegmentItems.add(segmentJson);
});
return applicationSegmentItems;
}
}
/*
* 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.
*/
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.apache.skywalking.plugin.test.mockcollector.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
import org.apache.skywalking.apm.network.language.agent.KeyWithStringValue;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentReference;
import org.apache.skywalking.apm.network.language.agent.UniqueId;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentReference;
import java.util.ArrayList;
import java.util.List;
@Builder
@ToString
@AllArgsConstructor
public class Span {
private String operationName;
private int operationId;
private int parentSpanId;
private int spanId;
private String spanLayer;
private long startTime;
private long endTime;
private int componentId;
private String componentName;
private boolean isError;
private String spanType;
private String peer;
private int peerId;
private List<KeyValuePair> tags = new ArrayList<>();
private List<LogEvent> logs = new ArrayList<>();
private List<SegmentRef> refs = new ArrayList<>();
public static class LogEvent {
private List<KeyValuePair> logEvent;
public LogEvent() {
this.logEvent = new ArrayList<>();
}
}
public static class SpanBuilder {
public SpanBuilder logEvent(List<KeyStringValuePair> eventMessage) {
if (logs == null) {
logs = new ArrayList<>();
}
LogEvent event = new LogEvent();
for (KeyStringValuePair value : eventMessage) {
event.logEvent.add(new KeyValuePair(value.getKey(), value.getValue()));
}
logs.add(event);
return this;
}
public SpanBuilder tags(String key, String value) {
if (tags == null) {
tags = new ArrayList<>();
}
tags.add(new KeyValuePair(key, value));
return this;
}
public SpanBuilder ref(SegmentRef segmentRefBuilder) {
if (refs == null) {
refs = new ArrayList<>();
}
refs.add(segmentRefBuilder);
return this;
}
public SpanBuilder logEventV1(List<KeyWithStringValue> dataList) {
if (logs == null) {
logs = new ArrayList<>();
}
LogEvent event = new LogEvent();
for (KeyWithStringValue value : dataList) {
event.logEvent.add(new KeyValuePair(value.getKey(), value.getValue()));
}
logs.add(event);
return this;
}
}
public static class KeyValuePair {
@Getter
private String key;
@Getter
private String value;
public KeyValuePair(String key, String value) {
this.key = key;
this.value = value;
}
}
@ToString
public static class SegmentRef {
@Getter
private int parentEndpointId;
@Getter
private String parentEndpoint;
@Getter
private int networkAddressId;
@Getter
private int entryEndpointId;
@Getter
private String refType;
@Getter
private int parentSpanId;
@Getter
private String parentTraceSegmentId;
@Getter
private int parentServiceInstanceId;
@Getter
private String networkAddress;
@Getter
private String entryEndpoint;
@Getter
private int entryServiceInstanceId;
public SegmentRef(SegmentReference ref) {
UniqueId segmentUniqueId = ref.getParentTraceSegmentId();
this.parentTraceSegmentId = String.join(".", Long.toString(segmentUniqueId.getIdParts(0)), Long.toString(segmentUniqueId.getIdParts(1)), Long.toString(segmentUniqueId.getIdParts(2)));
this.refType = ref.getRefType().toString();
this.parentSpanId = ref.getParentSpanId();
this.entryEndpointId = ref.getEntryEndpointId();
this.networkAddressId = ref.getNetworkAddressId();
this.parentServiceInstanceId = ref.getParentServiceInstanceId();
this.parentEndpointId = ref.getParentEndpointId();
this.parentEndpoint = ref.getParentEndpoint();
this.networkAddress = ref.getNetworkAddress();
this.entryEndpoint = ref.getEntryEndpoint();
this.entryServiceInstanceId = ref.getEntryServiceInstanceId();
}
public SegmentRef(TraceSegmentReference ref) {
UniqueId segmentUniqueId = ref.getParentTraceSegmentId();
this.parentTraceSegmentId = String.join(".", Long.toString(segmentUniqueId.getIdParts(0)), Long.toString(segmentUniqueId.getIdParts(1)), Long.toString(segmentUniqueId.getIdParts(2)));
this.refType = ref.getRefType().toString();
this.parentSpanId = ref.getParentSpanId();
this.entryEndpointId = ref.getEntryServiceId();
this.networkAddressId = ref.getNetworkAddressId();
this.parentServiceInstanceId = ref.getParentApplicationInstanceId();
this.parentEndpointId = ref.getParentServiceId();
this.parentEndpoint = ref.getParentServiceName();
this.networkAddress = ref.getNetworkAddress();
this.entryEndpoint = ref.getEntryServiceName();
this.entryServiceInstanceId = ref.getEntryApplicationInstanceId();
}
}
}
/*
* 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.plugin.test.mockcollector.entity;
public class ValidateData {
public static ValidateData INSTANCE = new ValidateData();
private RegistryItem registryItem;
private SegmentItems segmentItem;
public ValidateData() {
registryItem = new RegistryItem();
segmentItem = new SegmentItems();
}
public RegistryItem getRegistryItem() {
return registryItem;
}
public SegmentItems getSegmentItem() {
return segmentItem;
}
public static void clearData(){
System.out.println("Clear Data");
INSTANCE.segmentItem = new SegmentItems();
INSTANCE.registryItem.getOperationNames().clear();
}
}
/*
* 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.plugin.test.mockcollector.entity;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
/**
* Created by xin on 2017/7/14.
*/
public class ValidateDataSerializer implements JsonSerializer<ValidateData> {
@Override
public JsonElement serialize(ValidateData src, Type typeOfSrc, JsonSerializationContext context) {
Gson gson = new GsonBuilder().registerTypeAdapter(RegistryItem.class, new RegistryItemSerializer())
.registerTypeAdapter(SegmentItems.class, new SegmentItemsSerializer()).create();
JsonObject jsonObject = new JsonObject();
jsonObject.add("registryItems", gson.toJsonTree(src.getRegistryItem()));
jsonObject.add("segmentItems", gson.toJsonTree(src.getSegmentItem()));
return jsonObject;
}
}
/*
* 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.plugin.test.mockcollector.service;
import java.io.IOException;
import java.io.Writer;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData;
public class ClearReceiveDataService extends HttpServlet {
public static final String SERVLET_PATH = "/receiveData/clear";
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/json");
resp.setCharacterEncoding("utf-8");
resp.setStatus(200);
ValidateData.clearData();
Writer out = resp.getWriter();
out.flush();
out.close();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
/*
* 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.plugin.test.mockcollector.service;
import com.google.gson.JsonArray;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.skywalking.plugin.test.mockcollector.util.ConfigReader;
public class GrpcAddressHttpService extends HttpServlet {
public static String SERVLET_PATH = "/agent/gRPC";
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
JsonArray jsonArray = new JsonArray();
jsonArray.add(ConfigReader.getGrpcBindHost() + ":" + ConfigReader.getGrpcBindPort());
resp.setContentType("text/json");
resp.setCharacterEncoding("utf-8");
resp.setStatus(200);
PrintWriter out = resp.getWriter();
out.print(jsonArray.toString());
out.flush();
out.close();
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doPost(req, resp);
}
}
/*
* 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.plugin.test.mockcollector.service;
import io.grpc.stub.StreamObserver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.skywalking.apm.network.language.agent.Application;
import org.apache.skywalking.apm.network.language.agent.ApplicationMapping;
import org.apache.skywalking.apm.network.language.agent.ApplicationRegisterServiceGrpc;
import org.apache.skywalking.apm.network.language.agent.KeyWithIntegerValue;
import org.apache.skywalking.plugin.test.mockcollector.entity.RegistryItem;
import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData;
/**
* Created by xin on 2017/7/11.
*/
public class MockApplicationRegisterService extends ApplicationRegisterServiceGrpc.ApplicationRegisterServiceImplBase {
private Logger logger = LogManager.getLogger(MockTraceSegmentService.class);
@Override
public void applicationCodeRegister(Application request, StreamObserver<ApplicationMapping> responseObserver) {
logger.debug("receive application register.");
String applicationCode = request.getApplicationCode();
ApplicationMapping.Builder builder = ApplicationMapping.newBuilder();
if (applicationCode.startsWith("localhost") || applicationCode.startsWith("127.0.0.1") || applicationCode.contains(":") || applicationCode.contains("/")) {
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
return;
}
Integer applicationId = Sequences.SERVICE_MAPPING.get(applicationCode);
if (applicationId == null) {
applicationId = Sequences.ENDPOINT_SEQUENCE.incrementAndGet();
Sequences.SERVICE_MAPPING.put(applicationCode, applicationId);
ValidateData.INSTANCE.getRegistryItem().registryApplication(new RegistryItem.Application(applicationCode,
applicationId));
}
builder.setApplication(KeyWithIntegerValue.newBuilder().setKey(applicationCode).setValue(applicationId));
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}
}
/*
* 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.plugin.test.mockcollector.service;
import org.apache.skywalking.apm.network.language.agent.v2.CLRMetricReportServiceGrpc;
/**
* Author Daming
* Email zteny@foxmail.com
**/
public class MockCLRMetricReportService extends CLRMetricReportServiceGrpc.CLRMetricReportServiceImplBase {
}
/*
* 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.plugin.test.mockcollector.service;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.plugin.test.mockcollector.entity.RegistryItem;
import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData;
public class MockInstanceDiscoveryService extends InstanceDiscoveryServiceGrpc.InstanceDiscoveryServiceImplBase {
@Override
public void heartbeat(ApplicationInstanceHeartbeat request, StreamObserver<Downstream> responseObserver) {
ValidateData.INSTANCE.getRegistryItem().registryHeartBeat(new RegistryItem.HeartBeat(request.getApplicationInstanceId()));
responseObserver.onNext(Downstream.getDefaultInstance());
responseObserver.onCompleted();
}
@Override
public void registerInstance(ApplicationInstance request,
StreamObserver<ApplicationInstanceMapping> responseObserver) {
int instanceId = Sequences.INSTANCE_SEQUENCE.incrementAndGet();
ValidateData.INSTANCE.getRegistryItem().registryInstance(new RegistryItem.Instance(request.getApplicationId(), instanceId));
responseObserver.onNext(ApplicationInstanceMapping.newBuilder().setApplicationId(request.getApplicationId())
.setApplicationInstanceId(instanceId).build());
responseObserver.onCompleted();
}
}
/*
* 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.plugin.test.mockcollector.service;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.common.Commands;
import org.apache.skywalking.apm.network.register.v2.ServiceInstancePingGrpc;
import org.apache.skywalking.apm.network.register.v2.ServiceInstancePingPkg;
import org.apache.skywalking.plugin.test.mockcollector.entity.RegistryItem;
import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData;
public class MockInstancePingService extends ServiceInstancePingGrpc.ServiceInstancePingImplBase {
@Override
public void doPing(ServiceInstancePingPkg request, StreamObserver<Commands> responseObserver) {
ValidateData.INSTANCE.getRegistryItem().registryHeartBeat(new RegistryItem.HeartBeat(request.getServiceInstanceId()));
responseObserver.onNext(Commands.getDefaultInstance());
responseObserver.onCompleted();
}
}
/*
* 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.plugin.test.mockcollector.service;
import org.apache.skywalking.apm.network.language.agent.v2.JVMMetricReportServiceGrpc;
/**
* Author Daming
* Email zteny@foxmail.com
**/
public class MockJVMMetricReportService extends JVMMetricReportServiceGrpc.JVMMetricReportServiceImplBase {
}
/*
* 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.plugin.test.mockcollector.service;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.language.agent.Downstream;
import org.apache.skywalking.apm.network.language.agent.JVMMetrics;
import org.apache.skywalking.apm.network.language.agent.JVMMetricsServiceGrpc;
/**
* Created by xin on 2017/7/11.
*/
public class MockJVMMetricsService extends JVMMetricsServiceGrpc.JVMMetricsServiceImplBase {
@Override
public void collect(JVMMetrics request, StreamObserver<Downstream> responseObserver) {
responseObserver.onNext(Downstream.getDefaultInstance());
responseObserver.onCompleted();
}
}
/*
* 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.plugin.test.mockcollector.service;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.language.agent.Downstream;
import org.apache.skywalking.apm.network.language.agent.JVMMetrics;
import org.apache.skywalking.apm.network.language.agent.JVMMetricsServiceGrpc;
/**
* Created by xin on 2017/7/11.
*/
public class MockJVMMetricsV1Service extends JVMMetricsServiceGrpc.JVMMetricsServiceImplBase {
@Override
public void collect(JVMMetrics request, StreamObserver<Downstream> responseObserver) {
responseObserver.onNext(Downstream.getDefaultInstance());
responseObserver.onCompleted();
}
}
/*
* 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.plugin.test.mockcollector.service;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.language.agent.NetworkAddressMappings;
import org.apache.skywalking.apm.network.language.agent.NetworkAddressRegisterServiceGrpc;
import org.apache.skywalking.apm.network.language.agent.NetworkAddresses;
public class MockNetworkAddressRegisterService extends NetworkAddressRegisterServiceGrpc.NetworkAddressRegisterServiceImplBase {
@Override
public void batchRegister(NetworkAddresses request, StreamObserver<NetworkAddressMappings> responseObserver) {
responseObserver.onNext(NetworkAddressMappings.getDefaultInstance());
responseObserver.onCompleted();
}
}
/*
* 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.plugin.test.mockcollector.service;
import io.grpc.stub.StreamObserver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.skywalking.apm.network.common.KeyIntValuePair;
import org.apache.skywalking.apm.network.register.v2.*;
import org.apache.skywalking.plugin.test.mockcollector.entity.RegistryItem;
import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData;
public class MockRegisterService extends RegisterGrpc.RegisterImplBase {
private Logger logger = LogManager.getLogger(MockTraceSegmentService.class);
@Override
public void doEndpointRegister(Enpoints request, StreamObserver<EndpointMapping> responseObserver) {
for (Endpoint endpoint : request.getEndpointsList()) {
ValidateData.INSTANCE.getRegistryItem().registryOperationName(new RegistryItem.OperationName(endpoint.getServiceId(),
endpoint.getEndpointName()));
}
responseObserver.onNext(EndpointMapping.getDefaultInstance());
responseObserver.onCompleted();
}
@Override
public void doNetworkAddressRegister(NetAddresses request, StreamObserver<NetAddressMapping> responseObserver) {
responseObserver.onNext(NetAddressMapping.getDefaultInstance());
responseObserver.onCompleted();
}
@Override
public void doServiceInstanceRegister(ServiceInstances request, StreamObserver<ServiceInstanceRegisterMapping> responseObserver) {
if (request.getInstancesCount() <= 0) {
responseObserver.onNext(ServiceInstanceRegisterMapping.getDefaultInstance());
responseObserver.onCompleted();
return;
}
for (ServiceInstance serviceInstance : request.getInstancesList()) {
int instanceId = Sequences.INSTANCE_SEQUENCE.incrementAndGet();
ValidateData.INSTANCE.getRegistryItem().registryInstance(new RegistryItem.Instance(serviceInstance.getServiceId(), instanceId));
responseObserver.onNext(ServiceInstanceRegisterMapping.newBuilder().addServiceInstances(KeyIntValuePair.newBuilder()
.setKey(serviceInstance.getInstanceUUID()).setValue(instanceId).build()).build());
responseObserver.onCompleted();
}
}
@Override
public void doServiceRegister(Services request, StreamObserver<ServiceRegisterMapping> responseObserver) {
logger.debug("receive application register.");
if (request.getServicesCount() <= 0) {
logger.warn("The service count is empty. return the default service register mapping");
responseObserver.onNext(ServiceRegisterMapping.getDefaultInstance());
responseObserver.onCompleted();
return;
}
for (Service service : request.getServicesList()) {
String applicationCode = service.getServiceName();
ServiceRegisterMapping.Builder builder = ServiceRegisterMapping.newBuilder();
if (applicationCode.startsWith("localhost") || applicationCode.startsWith("127.0.0.1") || applicationCode.contains(":") || applicationCode.contains("/")) {
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
return;
}
Integer applicationId = Sequences.SERVICE_MAPPING.get(applicationCode);
if (applicationId == null) {
applicationId = Sequences.ENDPOINT_SEQUENCE.incrementAndGet();
Sequences.SERVICE_MAPPING.put(applicationCode, applicationId);
ValidateData.INSTANCE.getRegistryItem().registryApplication(new RegistryItem.Application(applicationCode,
applicationId));
}
builder.addServices(KeyIntValuePair.newBuilder().setKey(applicationCode).setValue(applicationId).build());
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}
}
}
/*
* 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.plugin.test.mockcollector.service;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.language.agent.ServiceNameCollection;
import org.apache.skywalking.apm.network.language.agent.ServiceNameDiscoveryServiceGrpc;
import org.apache.skywalking.apm.network.language.agent.ServiceNameElement;
import org.apache.skywalking.apm.network.language.agent.ServiceNameMappingCollection;
import org.apache.skywalking.plugin.test.mockcollector.entity.RegistryItem;
import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData;
public class MockServiceNameDiscoveryService extends ServiceNameDiscoveryServiceGrpc.ServiceNameDiscoveryServiceImplBase {
@Override
public void discovery(ServiceNameCollection request,
StreamObserver<ServiceNameMappingCollection> responseObserver) {
for (ServiceNameElement element : request.getElementsList()) {
ValidateData.INSTANCE.getRegistryItem().registryOperationName(new RegistryItem.OperationName(element.getApplicationId(),
element.getServiceName()));
}
responseObserver.onNext(ServiceNameMappingCollection.getDefaultInstance());
responseObserver.onCompleted();
}
}
/*
* 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.plugin.test.mockcollector.service;
import com.google.protobuf.InvalidProtocolBufferException;
import io.grpc.stub.StreamObserver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.skywalking.apm.network.common.Commands;
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.v2.*;
import org.apache.skywalking.plugin.test.mockcollector.entity.Segment;
import org.apache.skywalking.plugin.test.mockcollector.entity.Span;
import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData;
public class MockTraceSegmentService extends TraceSegmentReportServiceGrpc.TraceSegmentReportServiceImplBase {
private Logger logger = LogManager.getLogger(MockTraceSegmentService.class);
@Override
public StreamObserver<UpstreamSegment> collect(StreamObserver<Commands> responseObserver) {
return new StreamObserver<UpstreamSegment>() {
@Override public void onNext(UpstreamSegment value) {
try {
SegmentObject traceSegmentObject = SegmentObject.parseFrom(value.getSegment());
Segment.SegmentBuilder segmentBuilder = Segment.builder().segmentId(traceSegmentObject.getTraceSegmentId());
logger.debug("Receive segment: ServiceID[{}], TraceSegmentId[{}]",
traceSegmentObject.getServiceId(),
traceSegmentObject.getTraceSegmentId());
for (SpanObjectV2 spanObject : traceSegmentObject.getSpansList()) {
Span.SpanBuilder spanBuilder = Span.builder().operationName(spanObject.getOperationName()).parentSpanId(spanObject.getParentSpanId())
.spanId(spanObject.getSpanId()).componentId(spanObject.getComponentId()).componentName(spanObject.getComponent())
.spanLayer(spanObject.getSpanLayer().toString()).endTime(spanObject.getEndTime())
.startTime(spanObject.getStartTime()).spanType(spanObject.getSpanType().toString())
.peer(spanObject.getPeer()).peerId(spanObject.getPeerId()).operationId(spanObject.getOperationNameId());
for (Log logMessage : spanObject.getLogsList()) {
spanBuilder.logEvent(logMessage.getDataList());
}
for (KeyStringValuePair tags : spanObject.getTagsList()) {
spanBuilder.tags(tags.getKey(), tags.getValue());
}
for (SegmentReference ref : spanObject.getRefsList()) {
spanBuilder.ref(new Span.SegmentRef(ref));
}
segmentBuilder.addSpan(spanBuilder);
}
ValidateData.INSTANCE.getSegmentItem().addSegmentItem(traceSegmentObject.getServiceId(), segmentBuilder.build());
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
@Override public void onError(Throwable t) {
}
@Override public void onCompleted() {
responseObserver.onNext(Commands.newBuilder().build());
responseObserver.onCompleted();
}
};
}
}
/*
* 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.plugin.test.mockcollector.service;
import com.google.protobuf.InvalidProtocolBufferException;
import io.grpc.stub.StreamObserver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.plugin.test.mockcollector.entity.Segment;
import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData;
import org.apache.skywalking.plugin.test.mockcollector.entity.Span;
public class MockTraceSegmentV1Service extends TraceSegmentServiceGrpc.TraceSegmentServiceImplBase {
private Logger logger = LogManager.getLogger(MockTraceSegmentService.class);
@Override
public StreamObserver<UpstreamSegment> collect(final StreamObserver<Downstream> responseObserver) {
return new StreamObserver<UpstreamSegment>() {
@Override public void onNext(UpstreamSegment value) {
try {
TraceSegmentObject traceSegmentObject = TraceSegmentObject.parseFrom(value.getSegment());
Segment.SegmentBuilder segmentBuilder = Segment.builder().segmentId(traceSegmentObject.getTraceSegmentId());
logger.debug("Receive segment: Application[{}], TraceSegmentId[{}]",
traceSegmentObject.getApplicationId(),
traceSegmentObject.getTraceSegmentId());
for (SpanObject spanObject : traceSegmentObject.getSpansList()) {
Span.SpanBuilder spanBuilder = Span.builder().operationName(spanObject.getOperationName()).parentSpanId(spanObject.getParentSpanId())
.spanId(spanObject.getSpanId()).componentId(spanObject.getComponentId()).componentName(spanObject.getComponent())
.spanLayer(spanObject.getSpanLayer().toString()).endTime(spanObject.getEndTime())
.startTime(spanObject.getStartTime()).spanType(spanObject.getSpanType().toString())
.peer(spanObject.getPeer()).peerId(spanObject.getPeerId()).operationId(spanObject.getOperationNameId());
for (LogMessage logMessage : spanObject.getLogsList()) {
spanBuilder.logEventV1(logMessage.getDataList());
}
for (KeyWithStringValue tags : spanObject.getTagsList()) {
spanBuilder.tags(tags.getKey(), tags.getValue());
}
for (TraceSegmentReference ref : spanObject.getRefsList()) {
spanBuilder.ref(new Span.SegmentRef(ref));
}
segmentBuilder.addSpan(spanBuilder);
}
ValidateData.INSTANCE.getSegmentItem().addSegmentItem(traceSegmentObject.getApplicationId(), segmentBuilder.build());
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
@Override public void onError(Throwable t) {
}
@Override public void onCompleted() {
responseObserver.onNext(Downstream.getDefaultInstance());
responseObserver.onCompleted();
}
};
}
}
/*
* 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.plugin.test.mockcollector.service;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.io.Writer;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData;
import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateDataSerializer;
import org.yaml.snakeyaml.Yaml;
public class ReceiveDataService extends HttpServlet {
public static final String SERVLET_PATH = "/receiveData";
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/json");
resp.setCharacterEncoding("utf-8");
resp.setStatus(200);
Gson gson = new GsonBuilder().registerTypeAdapter(ValidateData.class, new ValidateDataSerializer()).create();
System.out.println();
Yaml yaml = new Yaml();
Writer out = resp.getWriter();
out.write(yaml.dump(yaml.load(gson.toJson(ValidateData.INSTANCE))));
out.flush();
out.close();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
/*
* 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.plugin.test.mockcollector.service;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
public class Sequences {
public static final AtomicInteger INSTANCE_SEQUENCE = new AtomicInteger();
public static final AtomicInteger ENDPOINT_SEQUENCE = new AtomicInteger(1);
public static final ConcurrentHashMap<String, Integer> SERVICE_MAPPING = new ConcurrentHashMap<String, Integer>();
}
/*
* 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.plugin.test.mockcollector.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ConfigReader {
private static Properties config = new Properties();
static {
InputStream inputStream = ConfigReader.class.getClassLoader().getResourceAsStream("config.properties");
try {
config.load(inputStream);
} catch (IOException e) {
System.err.println("Failed to load config.");
System.exit(-1);
}
}
public static String getGrpcBindHost() {
return config.getProperty("grpc_bind_host","127.0.0.1");
}
public static int getGrpcBindPort() {
return Integer.parseInt(config.getProperty("grpc_bind_port","19876"));
}
}
# Apache SkyWalking data collect protocol
Apache SkyWalking can collect data from different sources. Each kind of source should follow the protocols in this repo.
## License
Apache 2.0
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "common/common.proto";
message CLRMetric {
int64 time = 1;
CPU cpu = 2;
ClrGC gc = 3;
ClrThread thread = 4;
}
message ClrGC {
int64 Gen0CollectCount = 1;
int64 Gen1CollectCount = 2;
int64 Gen2CollectCount = 3;
int64 HeapMemory = 4;
}
message ClrThread {
int32 AvailableCompletionPortThreads = 1;
int32 AvailableWorkerThreads = 2;
int32 MaxCompletionPortThreads = 3;
int32 MaxWorkerThreads = 4;
}
\ No newline at end of file
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "common/common.proto";
message JVMMetric {
int64 time = 1;
CPU cpu = 2;
repeated Memory memory = 3;
repeated MemoryPool memoryPool = 4;
repeated GC gc = 5;
}
message Memory {
bool isHeap = 1;
int64 init = 2;
int64 max = 3;
int64 used = 4;
int64 committed = 5;
}
message MemoryPool {
PoolType type = 1;
int64 init = 2;
int64 max = 3;
int64 used = 4;
int64 commited = 5;
}
enum PoolType {
CODE_CACHE_USAGE = 0;
NEWGEN_USAGE = 1;
OLDGEN_USAGE = 2;
SURVIVOR_USAGE = 3;
PERMGEN_USAGE = 4;
METASPACE_USAGE = 5;
}
message GC {
GCPhrase phrase = 1;
int64 count = 2;
int64 time = 3;
}
enum GCPhrase {
NEW = 0;
OLD = 1;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.common";
option csharp_namespace = "SkyWalking.NetworkProtocol";
message KeyStringValuePair {
string key = 1;
string value = 2;
}
message KeyIntValuePair {
string key = 1;
int32 value = 2;
}
message CPU {
double usagePercent = 2;
}
// In most cases, detect point should be `server` or `client`.
// Even in service mesh, this means `server`/`client` side sidecar
// `proxy` is reserved only.
enum DetectPoint {
client = 0;
server = 1;
proxy = 2;
}
message Commands {
repeated Command commands = 1;
}
message Command {
string command = 1;
repeated KeyStringValuePair args = 2;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
message UpstreamSegment {
repeated UniqueId globalTraceIds = 1;
bytes segment = 2; // the byte array of TraceSegmentObject
}
enum SpanType {
Entry = 0;
Exit = 1;
Local = 2;
}
message UniqueId {
repeated int64 idParts = 1;
}
enum RefType {
CrossProcess = 0;
CrossThread = 1;
}
enum SpanLayer {
Unknown = 0;
Database = 1;
RPCFramework = 2;
Http = 3;
MQ = 4;
Cache = 5;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent.v2";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "common/common.proto";
import "common/CLR.proto";
service CLRMetricReportService {
rpc collect (CLRMetricCollection) returns (Commands) {
}
}
message CLRMetricCollection {
repeated CLRMetric metrics = 1;
int32 serviceInstanceId = 2;
}
\ No newline at end of file
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent.v2";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "common/common.proto";
import "common/JVM.proto";
service JVMMetricReportService {
rpc collect (JVMMetricCollection) returns (Commands) {
}
}
message JVMMetricCollection {
repeated JVMMetric metrics = 1;
int32 serviceInstanceId = 2;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent.v2";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "common/common.proto";
import "common/trace-common.proto";
service TraceSegmentReportService {
rpc collect (stream UpstreamSegment) returns (Commands) {
}
}
message SegmentObject {
UniqueId traceSegmentId = 1;
repeated SpanObjectV2 spans = 2;
int32 serviceId = 3;
int32 serviceInstanceId = 4;
bool isSizeLimited = 5;
}
message SegmentReference {
RefType refType = 1;
UniqueId parentTraceSegmentId = 2;
int32 parentSpanId = 3;
int32 parentServiceInstanceId = 4;
string networkAddress = 5;
int32 networkAddressId = 6;
int32 entryServiceInstanceId = 7;
string entryEndpoint = 8;
int32 entryEndpointId = 9;
string parentEndpoint = 10;
int32 parentEndpointId = 11;
}
message SpanObjectV2 {
int32 spanId = 1;
int32 parentSpanId = 2;
int64 startTime = 3;
int64 endTime = 4;
repeated SegmentReference refs = 5;
int32 operationNameId = 6;
string operationName = 7;
int32 peerId = 8;
string peer = 9;
SpanType spanType = 10;
SpanLayer spanLayer = 11;
int32 componentId = 12;
string component = 13;
bool isError = 14;
repeated KeyStringValuePair tags = 15;
repeated Log logs = 16;
}
message Log {
int64 time = 1;
repeated KeyStringValuePair data = 2;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "language-agent/KeyWithIntegerValue.proto";
//register service for ApplicationCode, this service is called when service starts.
service ApplicationRegisterService {
rpc applicationCodeRegister (Application) returns (ApplicationMapping) {
}
}
message Application {
string applicationCode = 1;
}
message ApplicationMapping {
KeyWithIntegerValue application = 1;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "language-agent/Downstream.proto";
import "common/trace-common.proto";
service InstanceDiscoveryService {
rpc registerInstance (ApplicationInstance) returns (ApplicationInstanceMapping) {
}
rpc heartbeat (ApplicationInstanceHeartbeat) returns (Downstream) {
}
}
message ApplicationInstance {
int32 applicationId = 1;
string agentUUID = 2;
int64 registerTime = 3;
OSInfo osinfo = 4;
}
message ApplicationInstanceMapping {
int32 applicationId = 1;
int32 applicationInstanceId = 2;
}
message ApplicationInstanceRecover {
int32 applicationId = 1;
int32 applicationInstanceId = 2;
int64 registerTime = 3;
OSInfo osinfo = 4;
}
message ApplicationInstanceHeartbeat {
int32 applicationInstanceId = 1;
int64 heartbeatTime = 2;
}
message OSInfo {
string osName = 1;
string hostname = 2;
int32 processNo = 3;
repeated string ipv4s = 4;
}
//discovery service for ServiceName by Network address or application code
service ServiceNameDiscoveryService {
rpc discovery (ServiceNameCollection) returns (ServiceNameMappingCollection) {
}
}
message ServiceNameCollection {
repeated ServiceNameElement elements = 1;
}
message ServiceNameMappingCollection {
repeated ServiceNameMappingElement elements = 1;
}
message ServiceNameMappingElement {
int32 serviceId = 1;
ServiceNameElement element = 2;
}
message ServiceNameElement {
string serviceName = 1;
int32 applicationId = 2;
SpanType srcSpanType = 3;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
// nothing down stream from collector yet.
message Downstream {
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "language-agent/Downstream.proto";
import "common/JVM.proto";
service JVMMetricsService {
rpc collect (JVMMetrics) returns (Downstream) {
}
}
message JVMMetrics {
repeated JVMMetric metrics = 1;
int32 applicationInstanceId = 2;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
message KeyWithIntegerValue {
string key = 1;
int32 value = 2;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
message KeyWithStringValue {
string key = 1;
string value = 2;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "language-agent/KeyWithIntegerValue.proto";
service NetworkAddressRegisterService {
rpc batchRegister (NetworkAddresses) returns (NetworkAddressMappings) {
}
}
message NetworkAddresses {
repeated string addresses = 1;
}
message NetworkAddressMappings {
repeated KeyWithIntegerValue addressIds = 1;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.language.agent";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "language-agent/Downstream.proto";
import "language-agent/KeyWithStringValue.proto";
import "common/trace-common.proto";
service TraceSegmentService {
rpc collect (stream UpstreamSegment) returns (Downstream) {
}
}
message TraceSegmentObject {
UniqueId traceSegmentId = 1;
repeated SpanObject spans = 2;
int32 applicationId = 3;
int32 applicationInstanceId = 4;
bool isSizeLimited = 5;
}
message TraceSegmentReference {
RefType refType = 1;
UniqueId parentTraceSegmentId = 2;
int32 parentSpanId = 3;
int32 parentApplicationInstanceId = 4;
string networkAddress = 5;
int32 networkAddressId = 6;
int32 entryApplicationInstanceId = 7;
string entryServiceName = 8;
int32 entryServiceId = 9;
string parentServiceName = 10;
int32 parentServiceId = 11;
}
message SpanObject {
int32 spanId = 1;
int32 parentSpanId = 2;
int64 startTime = 3;
int64 endTime = 4;
repeated TraceSegmentReference refs = 5;
int32 operationNameId = 6;
string operationName = 7;
int32 peerId = 8;
string peer = 9;
SpanType spanType = 10;
SpanLayer spanLayer = 11;
int32 componentId = 12;
string component = 13;
bool isError = 14;
repeated KeyWithStringValue tags = 15;
repeated LogMessage logs = 16;
}
message LogMessage {
int64 time = 1;
repeated KeyWithStringValue data = 2;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.register.v2";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "common/common.proto";
service ServiceInstancePing {
rpc doPing (ServiceInstancePingPkg) returns (Commands) {
}
}
message ServiceInstancePingPkg {
int32 serviceInstanceId = 1;
int64 time = 2;
string serviceInstanceUUID = 3;
}
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.register.v2";
option csharp_namespace = "SkyWalking.NetworkProtocol";
import "common/common.proto";
//register service for ApplicationCode, this service is called when service starts.
service Register {
rpc doServiceRegister (Services) returns (ServiceRegisterMapping) {
}
rpc doServiceInstanceRegister (ServiceInstances) returns (ServiceInstanceRegisterMapping) {
}
rpc doEndpointRegister (Enpoints) returns (EndpointMapping) {
}
rpc doNetworkAddressRegister (NetAddresses) returns (NetAddressMapping) {
}
rpc doServiceAndNetworkAddressMappingRegister (ServiceAndNetworkAddressMappings) returns(Commands) {
}
}
// Service register
message Services {
repeated Service services = 1;
}
message Service {
string serviceName = 1;
repeated KeyStringValuePair tags = 3;
repeated KeyStringValuePair properties = 4;
}
message ServiceRegisterMapping {
repeated KeyIntValuePair services = 1;
}
// Service Instance register
message ServiceInstances {
repeated ServiceInstance instances = 1;
}
message ServiceInstance {
int32 serviceId = 1;
string instanceUUID = 2;
int64 time = 3;
repeated KeyStringValuePair tags = 4;
repeated KeyStringValuePair properties = 5;
}
message ServiceInstanceRegisterMapping {
repeated KeyIntValuePair serviceInstances = 1;
}
// Network address register
// Only known use case is the language agent.
// Network address represents the ip/hostname:port, which is usually used at client side of RPC.
message NetAddresses {
repeated string addresses = 1;
}
message NetAddressMapping {
repeated KeyIntValuePair addressIds = 1;
}
// Endpint register
message Enpoints {
repeated Endpoint endpoints = 1;
}
message Endpoint {
int32 serviceId = 1;
string endpointName = 2;
repeated KeyStringValuePair tags = 3;
repeated KeyStringValuePair properties = 4;
// For endpoint
// from DetectPoint is either `client` or `server`. No chance to be `proxy`.
DetectPoint from = 5;
}
message EndpointMapping {
repeated EndpointMappingElement elements = 1;
}
message EndpointMappingElement {
int32 serviceId = 1;
string endpointName = 2;
int32 endpointId = 3;
DetectPoint from = 4;
}
message ServiceAndNetworkAddressMappings {
repeated ServiceAndNetworkAddressMapping mappings = 1;
}
message ServiceAndNetworkAddressMapping {
int32 serviceId = 1;
int32 serviceInstanceId = 2;
string networkAddress = 3;
int32 networkAddressId = 4;
}
---
title: Apache SkyWalking
description: Adapter to deliver metrics to Apache SkyWalking.
location: https://istio.io/docs/reference/config/policy-and-telemetry/adapters/apache-skywalking.html
layout: protoc-gen-docs
generator: protoc-gen-docs
provider: Apache SkyWalking
contact_email: dev@skywalking.apache.org
support_link:
source_link: https://github.com/apache/skywalking
latest_release_link: https://skywalking.apache.org/downloads/
helm_chart_link:
istio_versions: "1.0.3, 1.0.4, 1.1.0, 1.1.1"
supported_templates: metric
logo_link: https://github.com/apache/skywalking-website/raw/master/docs/.vuepress/public/assets/logo.svg
number_of_entries: 1
---
<!-- 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. -->
<p>The SkyWalking adapter uses the <code>Istio bypass</code> adapter to collect metrics and make them available to
<a href="https://skywalking.apache.org/">Apache SkyWalking</a>. SkyWalking provides a topology map and metrics graph
to visualize the whole mesh.</p>
<p>This adapter supports the <a href="https://istio.io/docs/reference/config/policy-and-telemetry/templates/metric/">metric template</a>.</p>
<p>Follow the <a href="https://github.com/apache/skywalking/blob/master/docs/README.md">official Apache SkyWalking documentation</a>
and <a href="https://github.com/apache/skywalking-kubernetes">SkyWalking k8s documentation</a> for details on configuring SkyWalking and the Istio bypass adapter.</p>
/*
* 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.
*
*/
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.servicemesh";
import "common/common.proto";
service ServiceMeshMetricService {
rpc collect(stream ServiceMeshMetric) returns (MeshProbeDownstream) {
}
}
message ServiceMeshMetric {
int64 startTime = 1;
int64 endTime = 2;
string sourceServiceName = 3;
int32 sourceServiceId = 4;
string sourceServiceInstance = 5;
int32 sourceServiceInstanceId = 6;
string destServiceName = 7;
int32 destServiceId = 8;
string destServiceInstance = 9;
int32 destServiceInstanceId = 10;
string endpoint = 11;
int32 latency = 12;
int32 responseCode = 13;
bool status = 14;
Protocol protocol = 15;
DetectPoint detectPoint = 16;
}
enum Protocol {
HTTP = 0;
gRPC = 1;
}
message MeshProbeDownstream {
}
# 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.
grpc_bind_host=127.0.0.1
grpc_bind_port=19876
# 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.
expectData:
- registryItem:
- applications:
- test-applicationCode1: nq 0 // the application id of test-applicationCode is 3
- test-applicationCode2: nq 0
- operationNames:
- test-applicationCode1: {testOperationName, testOperationName1} // there are three operation names in test-applicationCode1 has been registery
- instances:
- test-applicationCode1: eq 3 // test-applicationCode1 has 3 instances
- test-applicationCode2: 1 // test-applicationCode2 has 1 instance
- heartbeat:
- test-applicationCode1: gt 2 // there are 3 instance of test-applicationCode has been send heartbeat
- segmentsItems:
-
test-applicationCode: 1 // test-applicationCode has seend 1 segment.
segments:
-
segmentId: not null
refs:
- parentSpanId: 1
- parentTraceSegmentId: ${test-applicationCode2[0]}
- networkAddress: xxx
- parentServiceId: 1
- parentServiceName: not null
- networkAddressId: 1
- entryServiceId: 1
- refType: xx
- parentApplicationInstanceId: 1
- entryServiceName: xx
spans:
-
operationName: testOperationName
parentSpanId: 0
spanId: 1
spanLayer: HTTP
logs:
- xx: xx
- bb: bb
tags:
- xx: xx
- aa: aa
stattime: not empty
endtime: not empty
componentId: 1
componentName:
spanType: Entry
isError: false
-
test-applicationCode2: 2
segments:
-
segmentId: not null
spans:
-
operationName: testOperationName
parentSpanId: 0
spanId: 1
spanLayer: HTTP
logs:
- xx: xx
- bb: bb
globalSegmentId:
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<Configuration status="ERROR">
<Appenders>
<Console name="Console" target="SYSTEM_ERR">
<PatternLayout charset="UTF-8" pattern="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%p] - %l - %m%n" />
</Console>
</Appenders>
<Loggers>
<Root level="ERROR">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
# 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.
#
validateData:
- registryItem:
- applications:
- test-applicationCode1: 3 // the application id of test-applicationCode is 3
- test-applicationCode2: 1
- operationNames:
- test-applicationCode1: {testOperationName, testOperationName1} // there are three operation names in test-applicationCode1 has been registery
- instances:
- test-applicationCode1: 3 // test-applicationCode1 has 3 instances
- test-applicationCode2: 1 // test-applicationCode2 has 1 instance
- heartbeat:
- test-applicationCode1: 3 // there are 3 instance of test-applicationCode has been send heartbeat
- segmentsItems:
-
test-applicationCode: 1 // test-applicationCode has seend 1 segment.
segments:
-
segmentId: xxxx
refs:
- parentSpanId: 1
- parentTraceSegmentId: ${test-applicationCode2[0]}
- networkAddress: xxx
- parentServiceId: 1
- parentServiceName: not null
- networkAddressId: 1
- entryServiceId: 1
- refType: xx
- parentApplicationInstanceId: 1
- entryServiceName: xx
spans:
-
operationName: testOperationName
parentSpanId: 0
spanId: 1
spanLayer: HTTP
logs:
- xx: xx
- bb: bb
tags:
- xx: xx
- aa: aa
stattime: 141
endtime: 141
componentId: 1
componentName:
spanType: Entry
isError: false
-
test-applicationCode2: 2
segments:
//.....
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.skywalking.plugin</groupId>
<artifactId>apache-skywalking-test-plugin</artifactId>
<version>1.0.0</version>
<name>SkyWalking Plugins Tests</name>
<packaging>pom</packaging>
<modules>
<module>runner</module>
<module>validator</module>
<module>mock-collector</module>
<module>containers</module>
</modules>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.11</junit.version>
<guava.version>20.0</guava.version>
<gson.version>2.8.5</gson.version>
<lombok.version>1.18.4</lombok.version>
<snakeyaml.version>1.24</snakeyaml.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
<docker.image.version>1.0.0</docker.image.version>
<skip.docker>true</skip.docker>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.source}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker-maven-plugin.version}</version>
<configuration>
<imageName>skywalking/${project.name}</imageName>
<dockerDirectory>${project.basedir}/docker</dockerDirectory>
<skipDocker>${skip.docker}</skipDocker>
</configuration>
</plugin>
</plugins>
</build>
</project>
#!/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)"
scenario_name="empty"
parallel_run_size=1
build_id="latest"
mvnw=${home}/../../mvnw
agent_home=${home}"/../../skywalking-agent"
scenarios_home="${home}/scenarios"
_positionals=()
parse_commandline() {
_positionals_count=0
while test $# -gt 0
do
_key="$1"
case "$_key" in
--build_id)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
build_id="$2"
shift
;;
--build_id=*)
build_id="${_key##--build_id=}"
;;
--parallel_run_size)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
parallel_run_size="$2"
shift
;;
--parallel_run_size=*)
parallel_run_size="${_key##--parallel_run_size=}"
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
scenario_name=$1
;;
esac
shift
done
}
exitWithMessage() {
echo -e "\033[31m[ERROR] $1\033[0m">&2
exitAndClean 1
}
exitAndClean() {
if [[ "${build_id}" =~ "latest" ]]; then
docker images -q "skywalking/agent-test-*:${build_id}" | xargs -r docker rmi -f
fi
elapsed=$(( `date +%s` - $start_stamp ))
num_of_testcases="`ls -l ${task_state_house} |grep -c FINISH`"
printf "Scenarios: %s, Testcases: %d, parallel_run_size: %d, Elapsed: %02d:%02d:%02d \n" \
${scenario_name} "${num_of_testcases}" "${parallel_run_size}" \
$(( ${elapsed}/3600 )) $(( ${elapsed}%3600/60 )) $(( ${elapsed}%60 ))
exit $1
}
waitForAvailable() {
while [[ `ls -l ${task_state_house} |grep -c RUNNING` -ge ${parallel_run_size} ]]
do
sleep 2
done
if [[ `ls -l ${task_state_house} |grep -c FAILURE` -gt 0 ]]; then
exitAndClean 1
fi
}
parse_commandline "$@"
start_stamp=`date +%s` ### start
workspace="${home}/workspace/${scenario_name}"
task_state_house="${workspace}/.states"
[[ -d ${workspace} ]] && rm -rf $workspace
mkdir -p ${task_state_house}
plugin_autotest_helper="${home}/dist/plugin-autotest-helper.jar"
if [[ ! -f ${plugin_autotest_helper} ]]; then
exitWithMessage "plugin autotest helper not exist!"
fi
echo "start submit job"
scenario_home=${scenarios_home}/${scenario_name} && cd ${scenario_home}
supported_version_file=${scenario_home}/support-version.list
if [[ ! -f $supported_version_file ]]; then
exitWithMessage "cannot found 'support-version.list' in directory ${scenario_name}"
fi
supported_versions=`grep -v -E "^$|^#" ${supported_version_file}`
for version in ${supported_versions}
do
waitForAvailable
testcase_name="${scenario_name}-${version}"
# testcase working directory, there are logs, data and packages.
case_work_base=${workspace}/${version}
mkdir -p ${case_work_base}/{data,logs}
case_work_logs_dir=${case_work_base}/logs
# copy expectedData.yml
cp ./config/expectedData.yaml ${case_work_base}/data
# echo "build ${testcase_name}"
${mvnw} clean package -P${testcase_name}
mv ./target/${scenario_name}.war ${case_work_base}
java -jar \
-Xmx256m -Xms256m \
-Dconfigure.file=${scenario_home}/configuration.yml \
-Dscenario.home=${case_work_base} \
-Dscenario.name=${scenario_name} \
-Dscenario.version=${version} \
-Doutput.dir=${case_work_base} \
-Dagent.dir=${agent_home} \
-Ddocker.image.version=${build_id} \
${plugin_autotest_helper} 1>${case_work_logs_dir}/helper.log
[[ $? -ne 0 ]] && exitWithMessage "${testcase_name}, generate script failure!"
echo "start container of testcase.name=${testcase_name}"
bash ${case_work_base}/scenario.sh ${task_state_house} 1>${case_work_logs_dir}/${testcase_name}.log &
sleep 3
done
echo -e "\033[33m${scenario_name} has already sumbitted\033[0m"
# wait to finish
while [[ `ls -l ${task_state_house} |grep -c RUNNING` -gt 0 ]]; do
sleep 1
done
if [[ `ls -l ${task_state_house} |grep -c FAILURE` -gt 0 ]]; then
exitAndClean 1
fi
exitAndClean 0
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.skywalking.plugin</groupId>
<artifactId>apache-skywalking-test-plugin</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>runner</artifactId>
<name>plugin-autotest-helper</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.28</version>
</dependency>
</dependencies>
<build>
<finalName>plugin-autotest-helper</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>org.apache.skywalking.plugin.test.helper.Main</Main-Class>
</manifestEntries>
</transformer>
</transformers>
<outputFile>../dist/${project.build.finalName}.jar</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/*
* 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.plugin.test.helper;
import freemarker.template.Configuration;
import freemarker.template.TemplateExceptionHandler;
import java.io.File;
import java.io.FileWriter;
import java.lang.invoke.MethodHandles;
import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.skywalking.plugin.test.helper.exception.GenerateFailedException;
public abstract class AbstractRunningGenerator implements ScenarioRunningScriptGenerator {
private Logger logger = LogManager.getLogger(MethodHandles.lookup().lookupClass());
protected final Configuration cfg;
protected AbstractRunningGenerator() {
cfg = new Configuration(Configuration.VERSION_2_3_28);
try {
cfg.setClassLoaderForTemplateLoading(this.getClass().getClassLoader(), "/");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
cfg.setWrapUncheckedExceptions(true);
} catch (Exception e) {
// never to do this
}
}
@Override
public final void generate(IConfiguration configuration) throws GenerateFailedException {
generateAdditionFiles(configuration);
Map<String, Object> root = new HashMap<>();
root.put("running_script", runningScript(configuration));
root.put("scenario_name", configuration.scenarioName());
root.put("scenario_version", configuration.scenarioVersion());
try {
cfg.getTemplate("scenario.sh").process(root,
new FileWriter(new File(configuration.outputDir() + File.separator + "scenario.sh")));
} catch (Exception e) {
logger.error("Failed to write scenario.sh", e);
}
}
public abstract void generateAdditionFiles(IConfiguration configuration) throws GenerateFailedException;
public abstract String runningScript(IConfiguration configuration);
}
/*
* 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.plugin.test.helper;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.UUID;
import org.apache.skywalking.plugin.test.helper.exception.ConfigureFileNotFoundException;
import org.apache.skywalking.plugin.test.helper.util.StringUtils;
import org.apache.skywalking.plugin.test.helper.vo.CaseConfiguration;
import org.yaml.snakeyaml.Yaml;
public class ConfigurationImpl implements IConfiguration {
private CaseConfiguration configuration;
private final String scenarioHome;
public ConfigurationImpl() throws FileNotFoundException, ConfigureFileNotFoundException {
String configureFile = System.getProperty("configure.file");
if (StringUtils.isBlank(configureFile)) {
throw new ConfigureFileNotFoundException();
}
this.configuration = new Yaml().loadAs(new FileReader(new File(configureFile)), CaseConfiguration.class);
this.scenarioHome = System.getProperty("scenario.home");
}
@Override
public String agentHome() {
return System.getProperty("agent.dir");
}
@Override public RunningType runningType() {
return (configuration.getDependencies() != null && configuration.getDependencies().size() > 0) ?
RunningType.DockerCompose :
RunningType.Container;
}
@Override public ScenarioRunningScriptGenerator scenarioGenerator() {
switch (runningType()) {
case DockerCompose:
return new DockerComposeV2RunningGenerator();
case Container:
return new DockerContainerRunningGenerator();
default:
throw new RuntimeException();
}
}
@Override public CaseConfiguration caseConfiguration() {
return this.configuration;
}
@Override public String scenarioName() {
return System.getProperty("scenario.name");
}
@Override public String scenarioVersion() {
return System.getProperty("scenario.version");
}
@Override public String testFramework() {
return this.configuration.getFramework();
}
@Override public String entryService() {
return this.configuration.getEntryService();
}
@Override public String healthCheck() {
return this.configuration.getHealthCheck();
}
@Override public String dockerImageName() {
switch (this.configuration.getType().toLowerCase()) {
case "tomcat" :
return "skywalking/agent-test-tomcat";
case "jvm" :
return "skywalking/agent-test-jvm";
}
throw new RuntimeException("Illegal type!");
}
@Override
public String dockerImageVersion() {
return System.getProperty("docker.image.version", "latest");
}
@Override
public String dockerContainerName() {
return scenarioName() + "-" + scenarioVersion() + "-" + Long.toHexString(System.nanoTime());
}
@Override public String scenarioHome() {
return this.scenarioHome;
}
@Override public String outputDir(){
return System.getProperty("output.dir");
}
}
/*
* 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.plugin.test.helper;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.skywalking.plugin.test.helper.exception.GenerateFailedException;
import org.apache.skywalking.plugin.test.helper.vo.DockerCompose;
import org.apache.skywalking.plugin.test.helper.vo.DockerService;
import org.apache.skywalking.plugin.test.helper.vo.DockerServiceReader;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
public class DockerComposeRunningGenerator extends AbstractRunningGenerator {
@Override
public void generateAdditionFiles(IConfiguration configuration) throws GenerateFailedException {
DockerCompose dockerCompose = convertDockerCompose(configuration);
try {
getFileWriter().dump(dockerCompose, new FileWriter(new File(configuration.outputDir(), "docker-compose" +
".yml")));
} catch (IOException e) {
throw new GenerateFailedException();
}
}
private DockerCompose convertDockerCompose(IConfiguration configuration) {
DockerCompose dockerCompose = new DockerCompose();
dockerCompose.setVersion("2.1");
HashMap<String, DockerService> dockerServices = new HashMap<>();
DockerService container = new DockerService();
container.setImage(String.format("%s:latest", configuration.dockerImageName()));
configuration.caseConfiguration().getDependencies().forEach((name, dependencyComponent) -> {
DockerService dockerService = new DockerService();
DockerServiceReader serviceReader = dependencyComponent;
dockerService.setEnvironments(serviceReader.environment());
dockerService.setImage(serviceReader.image());
dockerServices.put(name, dockerService);
});
container.setLinks(new ArrayList<>(configuration.caseConfiguration().getDependencies().keySet()));
List<String> environment = new ArrayList<String>();
environment.add(String.format("SCENARIO_VERSION=%s", configuration.scenarioVersion()));
environment.add(String.format("SCENARIO_SUPPORT_FRAMEWORK=%s", configuration.testFramework()));
environment.add(String.format("SCENARIO_ENTRY_SERVICE=%s", configuration.entryService()));
environment.add(String.format("SCENARIO_HEALTH_CHECK_URL=%s", configuration.healthCheck()));
List<String> volumes = new ArrayList<>();
volumes.add(String.format("%s:/usr/local/skywalking-agent-scenario/agent", configuration.agentHome()));
container.setVolumes(volumes);
container.setEnvironments(environment);
dockerServices.put(String.format("skywalking-agent-test-%s-%s", configuration.testFramework(),
configuration.scenarioVersion())
, container);
dockerCompose.setServices(dockerServices);
return dockerCompose;
}
private Yaml getFileWriter() {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Representer representer = new Representer() {
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
Tag customTag) {
if (propertyValue == null) {
return null;
} else {
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
}
};
representer.addClassTag(DockerCompose.class, Tag.MAP);
return new Yaml(representer, dumperOptions);
}
@Override
public String runningScript(IConfiguration configuration) {
return String.format("docker-compose -f %s up", configuration.outputDir() + File.separator + "docker-compose" +
".yml");
}
}
/*
* 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.plugin.test.helper;
import com.google.common.collect.Lists;
import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.skywalking.plugin.test.helper.vo.DependencyComponent;
import org.apache.skywalking.plugin.test.helper.vo.DockerService;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DockerComposeV2RunningGenerator extends AbstractRunningGenerator {
private static Logger logger = LogManager.getLogger(MethodHandles.lookup().lookupClass());
protected DockerComposeV2RunningGenerator() {
}
@Override
public void generateAdditionFiles(IConfiguration configuration) {
Map<String, Object> root = new HashMap<>();
root.put("agent_home", configuration.agentHome());
root.put("scenario_home", configuration.scenarioHome());
root.put("scenario_name", configuration.scenarioName());
root.put("scenario_version", configuration.scenarioVersion());
root.put("entry_service", configuration.entryService());
root.put("health_check", configuration.healthCheck());
root.put("test_framework", configuration.testFramework());
root.put("docker_image_name", configuration.dockerImageName());
root.put("docker_image_version", configuration.dockerImageVersion());
root.put("docker_container_name", configuration.dockerContainerName());
ArrayList<String> links = Lists.newArrayList();
configuration.caseConfiguration().getDependencies().forEach((k, service) -> {
links.add(service.getHost());
});
root.put("links", links);
root.put("services", convertDockerServices(configuration.caseConfiguration().getDependencies()));
Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);
try {
cfg.setClassLoaderForTemplateLoading(this.getClass().getClassLoader(), "/");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
cfg.setWrapUncheckedExceptions(true);
} catch (Exception e) {
// never to do this
}
try {
cfg.getTemplate("docker-compose.template").process(root, new FileWriter(new File(configuration.outputDir(),
"docker-compose.yml")));
} catch (TemplateException | IOException e) {
logger.error(e);
}
}
protected List<DockerService> convertDockerServices(Map<String, DependencyComponent> componentMap) {
ArrayList<DockerService> services = Lists.newArrayList();
componentMap.forEach((name, dependency) -> {
DockerService service = new DockerService();
service.setName(name);
service.setVersion(dependency.getVersion());
service.setImage(dependency.getImage());
service.setHost(dependency.getHost());
service.setExpose(nullToEmpty(dependency.getExpose()));
service.setVolumes(nullToEmpty(dependency.getVolumes()));
service.setEnvironments(nullToEmpty(dependency.getEnvironment()));
services.add(service);
});
return services;
}
private static final List<String> nullToEmpty(List<String> list) {
return list == null ? Lists.newArrayList() : list;
}
@Override
public String runningScript(IConfiguration configuration) {
return String.format("docker-compose -f %s up", configuration.outputDir() + File.separator +
"docker-compose.yml");
}
}
/*
* 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.plugin.test.helper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.StringWriter;
import java.lang.invoke.MethodHandles;
import java.util.HashMap;
import java.util.Map;
public class DockerContainerRunningGenerator extends AbstractRunningGenerator {
private static Logger logger = LogManager.getLogger(MethodHandles.lookup().lookupClass());
protected DockerContainerRunningGenerator() {
}
@Override
public void generateAdditionFiles(IConfiguration configuration) {
// DO Nothing
}
@Override
public String runningScript(IConfiguration configuration) {
Map<String, Object> root = new HashMap<>();
root.put("agent_home", configuration.agentHome());
root.put("scenario_home", configuration.scenarioHome());
root.put("scenario_name", configuration.scenarioName());
root.put("scenario_version", configuration.scenarioVersion());
root.put("entry_service", configuration.entryService());
root.put("health_check", configuration.healthCheck());
root.put("test_framework", configuration.testFramework());
root.put("docker_image_name", configuration.dockerImageName());
root.put("docker_image_version", configuration.dockerImageVersion());
root.put("docker_container_name", configuration.dockerContainerName());
StringWriter out = null;
try {
out = new StringWriter();
cfg.getTemplate("container-start-script.template").process(root, out);
} catch (Exception e) {
logger.error("Failed to generate running script.", e);
}
return out.toString();
}
}
/*
* 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.plugin.test.helper;
public class Main {
public static void main(String[] args) throws Exception {
IConfiguration configuration = new ConfigurationImpl();
configuration.scenarioGenerator().generate(configuration);
System.exit(0);
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册