├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── assets └── cyborg-flow-logo.png ├── cyborg-agent ├── Makefile ├── README.md ├── plugins │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ └── maven-wrapper.properties │ ├── apm-checkstyle │ │ ├── CHECKSTYLE_HEAD │ │ ├── checkStyle.xml │ │ └── importControl.xml │ ├── mvnw │ ├── mvnw.cmd │ ├── mysql-5.x │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── skywalking │ │ │ │ └── apm │ │ │ │ └── cyborg │ │ │ │ └── flow │ │ │ │ └── plugin │ │ │ │ └── jdbc │ │ │ │ └── mysql │ │ │ │ └── v5 │ │ │ │ ├── ConnectionCreate5xInterceptor.java │ │ │ │ └── define │ │ │ │ ├── AbstractConnectionInstrumentation.java │ │ │ │ ├── AbstractMysqlInstrumentation.java │ │ │ │ ├── CacheIpsInstrumentation.java │ │ │ │ ├── CallableInstrumentation.java │ │ │ │ ├── ConnectionImplCreateInstrumentation.java │ │ │ │ ├── Constants.java │ │ │ │ ├── Mysql50ConnectionInstrumentation.java │ │ │ │ ├── Mysql5xConnectionInstrumentation.java │ │ │ │ ├── PreparedStatementIgnoredSetterInstrumentation.java │ │ │ │ ├── PreparedStatementInstrumentation.java │ │ │ │ ├── PreparedStatementNullSetterInstrumentation.java │ │ │ │ ├── PreparedStatementSetterInstrumentation.java │ │ │ │ └── StatementInstrumentation.java │ │ │ └── resources │ │ │ └── skywalking-plugin.def │ ├── mysql-6.x │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── skywalking │ │ │ │ └── apm │ │ │ │ └── cyborg │ │ │ │ └── flow │ │ │ │ └── plugin │ │ │ │ └── jdbc │ │ │ │ └── mysql │ │ │ │ └── v6 │ │ │ │ ├── ConnectionCreateNewInterceptor.java │ │ │ │ ├── ConnectionCreateOldInterceptor.java │ │ │ │ └── define │ │ │ │ ├── AbstractMysqlInstrumentation.java │ │ │ │ ├── CacheIpsInstrumentation.java │ │ │ │ ├── CallableInstrumentation.java │ │ │ │ ├── ConnectionImplCreateInstrumentation.java │ │ │ │ ├── ConnectionInstrumentation.java │ │ │ │ ├── Constants.java │ │ │ │ ├── DriverInstrumentation.java │ │ │ │ ├── PreparedStatementIgnoredSetterInstrumentation.java │ │ │ │ ├── PreparedStatementInstrumentation.java │ │ │ │ ├── PreparedStatementNullSetterInstrumentation.java │ │ │ │ ├── PreparedStatementSetterInstrumentation.java │ │ │ │ └── StatementInstrumentation.java │ │ │ └── resources │ │ │ └── skywalking-plugin.def │ ├── mysql-8.x │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── skywalking │ │ │ │ └── apm │ │ │ │ └── cyborg │ │ │ │ └── flow │ │ │ │ └── plugin │ │ │ │ └── jdbc │ │ │ │ └── mysql │ │ │ │ └── v8 │ │ │ │ ├── ConnectionCreateInterceptor.java │ │ │ │ └── define │ │ │ │ ├── AbstractMysqlInstrumentation.java │ │ │ │ ├── CacheIpsInstrumentation.java │ │ │ │ ├── CallableInstrumentation.java │ │ │ │ ├── ConnectionImplCreateInstrumentation.java │ │ │ │ ├── ConnectionInstrumentation.java │ │ │ │ ├── Constants.java │ │ │ │ ├── PreparedStatementIgnoredSetterInstrumentation.java │ │ │ │ ├── PreparedStatementInstrumentation.java │ │ │ │ ├── PreparedStatementNullSetterInstrumentation.java │ │ │ │ ├── PreparedStatementSetterInstrumentation.java │ │ │ │ └── StatementInstrumentation.java │ │ │ └── resources │ │ │ └── skywalking-plugin.def │ ├── mysql-common │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── skywalking │ │ │ └── apm │ │ │ └── cyborg │ │ │ └── flow │ │ │ └── plugin │ │ │ └── jdbc │ │ │ └── mysql │ │ │ ├── ConnectionCache.java │ │ │ ├── Constants.java │ │ │ ├── CreateCallableStatementInterceptor.java │ │ │ ├── CreatePreparedStatementInterceptor.java │ │ │ ├── CreateStatementInterceptor.java │ │ │ ├── CyborgSqlInjector.java │ │ │ ├── DriverConnectInterceptor.java │ │ │ ├── PreparedStatementExecuteMethodsInterceptor.java │ │ │ ├── SetCatalogInterceptor.java │ │ │ └── StatementExecuteMethodsInterceptor.java │ └── pom.xml ├── release.sh └── replace-plugins.sh ├── cyborg-dashboard ├── Makefile ├── core.oal ├── release.sh ├── replace-oap.sh └── ui-template.yml ├── cyborg-database-shadow ├── README.md ├── README_ZH.md └── conf │ ├── config-shadow.yaml │ └── server.yaml └── cyborg-flow-gateway ├── README.md ├── README_ZH.md └── conf ├── apisix.yaml └── config.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # eclipse ignore 5 | .settings/ 6 | .project 7 | .classpath 8 | .factorypath 9 | 10 | # idea ignore 11 | .idea/ 12 | *.ipr 13 | *.iml 14 | *.iws 15 | 16 | # Log file 17 | *.log 18 | 19 | # BlueJ files 20 | *.ctxt 21 | 22 | # Mobile Tools for Java (J2ME) 23 | .mtj.tmp/ 24 | 25 | # Package Files # 26 | *.jar 27 | *.war 28 | *.nar 29 | *.ear 30 | *.zip 31 | *.tar.gz 32 | *.rar 33 | 34 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 35 | hs_err_pid* 36 | 37 | # java maven 38 | target/ 39 | 40 | # cyborg-agent 41 | /cyborg-agent/cyborg-agent/ -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | CyborgFlow 2 | Copyright 2021-2021 SphereEx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CyborgFlow 2 | Sky Walking logo 3 | 4 | CyborgFlow provides an out-of-the-box (OOTB) solution to perform load test on your online system, powered by Apache APISIX, Apache SkyWalking and Apache ShardingSphere. 5 | 6 | ## Quick Start 7 | 8 | ### Download Release Package 9 | 10 | Please download the package from the [release page](https://github.com/SphereEx/CyborgFlow/releases): 11 | 12 | ### Setup Cyborg Database Shadow 13 | 14 | 1. Unpack the **cyborg-database-shadow.tar.gz**. 15 | 2. Follow [document](cyborg-database-shadow/README.md#quick-start) to quick start the server. 16 | 17 | ### Setup Cyborg Dashboard 18 | 19 | 1. Unpack the **cyborg-dashboard.tar.gz**. 20 | 2. Follow [Backend Document](https://skywalking.apache.org/docs/main/latest/en/setup/backend/backend-setup/) to start the dashboard backend. 21 | 3. Follow [UI Document](https://skywalking.apache.org/docs/main/latest/en/setup/backend/ui-setup/) to start the dashboard UI, and the you could access via `http://localhost:8080`. Please note that currently you won't find any data, as the application hasn't been setup yet. 22 | 23 | ### Setup Cyborg Agent 24 | 25 | 1. Unpack the **cyborg-agent.tar.gz**. 26 | 2. Follow [setup document](https://skywalking.apache.org/docs/skywalking-java/latest/en/setup/service-agent/java-agent/readme/) config the agent to your application, and make the agent link to the Cyborg Dashboard backend. 27 | 3. Change the address of the linked database in your application to the Cyborg database shadow server address. 28 | 4. Start your application. 29 | 30 | ### Setup Cyborg Flow Gateway 31 | 32 | 1. Please follow [quick start document](cyborg-flow-gateway/README.md) to install `APISIX` and link to the Cyborg Dashboard backend and your application. 33 | 2. Trigger request to access your application via `APISIX`. 34 | 35 | ### View the Dashboard 36 | 37 | 1. Access the Cyborg Dashboard UI. 38 | 2. Click the `Cyborg Flow` tab to switch the dashboard. Then you could get the traffic information. 39 | 40 | # License 41 | Apache 2.0 42 | -------------------------------------------------------------------------------- /assets/cyborg-flow-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SphereEx/cyborg-flow/895be3e0876fea55edf82b9ceaf9994cfd7ba709/assets/cyborg-flow-logo.png -------------------------------------------------------------------------------- /cyborg-agent/Makefile: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # If the first argument is "run"... 17 | 18 | SHELL := /bin/bash -o pipefail 19 | 20 | CYBORG_AGENT_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 21 | CYBORG_AGENT_TAR := cyborg-agent.tar.gz 22 | CYBORG_UPSTREAM_REPO ?= https://github.com/apache/skywalking-java.git 23 | CYBORG_UPSTREAM_HEAD ?= a7a4faabb158ea8322170e3c7cae0210a8c4e7b4 24 | 25 | .PHONY: build 26 | build: 27 | cd plugins && ./mvnw --batch-mode clean package -Dmaven.test.skip=true 28 | 29 | .PHONY: replace 30 | replace: build 31 | bash ./replace-plugins.sh $(path) 32 | 33 | .PHONY: release 34 | release: 35 | bash ./release.sh $(CYBORG_UPSTREAM_REPO) $(CYBORG_UPSTREAM_HEAD) $(CYBORG_AGENT_ROOT)/$(CYBORG_AGENT_TAR) -------------------------------------------------------------------------------- /cyborg-agent/README.md: -------------------------------------------------------------------------------- 1 | # cyborg-agent 2 | 3 | ## Quick start 4 | 5 | 1. Please head to the [releases page](https://skywalking.apache.org/downloads/) to download a release of Apache SkyWalking Java Agent. 6 | 7 | 2. Build `cyborg-agent` and replace plugins. The `SW_AGENT_HOME` should be the `skywalking-java` base directory. 8 | ```shell 9 | make replace path=$(SW_AGENT_HOME) 10 | ``` 11 | 12 | 3. Start application with `skywalking-agent`, for more information please read the [official documentation](https://skywalking.apache.org/docs/#JavaAgent). 13 | 14 | ## Use Example 15 | 16 | We use [Apache SkyWalking Cross Process Correlation Context](https://skywalking.apache.org/docs/main/latest/en/protocols/skywalking-cross-process-correlation-headers-protocol-v1/) 17 | to decide should we need to use the shadow database. The correlation key and value is: `cyborg-flow=true`. 18 | In Java, you could be using the [Tracing API](https://skywalking.apache.org/docs/skywalking-java/latest/en/setup/service-agent/java-agent/application-toolkit-trace/) to put the context. -------------------------------------------------------------------------------- /cyborg-agent/plugins/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.5"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar 3 | 4 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/apm-checkstyle/CHECKSTYLE_HEAD: -------------------------------------------------------------------------------- 1 | ^<\?xml version="1\.0" encoding="UTF-8"\?>$ 2 | ^ 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/apm-checkstyle/importControl.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | cyborg-flow-plugin 23 | org.apache.skywalking 24 | 8.8.0 25 | 26 | 4.0.0 27 | 28 | cyborg-flow-mysql-plugin-5.x 29 | cyborg-flow-mysql-plugin-5.x 30 | jar 31 | 32 | 33 | UTF-8 34 | 5.1.44 35 | 36 | 37 | 38 | 39 | mysql 40 | mysql-connector-java 41 | ${mysql-connector-java.version} 42 | provided 43 | 44 | 45 | org.apache.skywalking 46 | apm-jdbc-commons 47 | ${project.version} 48 | provided 49 | 50 | 51 | org.apache.skywalking 52 | cyborg-flow-mysql-common 53 | ${project.version} 54 | provided 55 | 56 | 57 | 58 | 59 | 60 | 61 | maven-deploy-plugin 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/ConnectionCreate5xInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; 24 | import org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser.URLParser; 25 | import org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.ConnectionCache; 26 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 27 | 28 | import java.lang.reflect.Method; 29 | 30 | /** 31 | * ConnectionImpl#getInstance in mysql-5.x has 5 parameters such as getInstance(String hostToConnectTo, int 32 | * portToConnectTo, Properties info, String databaseToConnectTo, String url) 33 | */ 34 | public class ConnectionCreate5xInterceptor implements StaticMethodsAroundInterceptor { 35 | 36 | @Override 37 | public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 38 | MethodInterceptResult result) { 39 | } 40 | 41 | @Override 42 | public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 43 | Object ret) { 44 | if (ret instanceof EnhancedInstance) { 45 | ConnectionInfo connectionInfo = ConnectionCache.get(allArguments[0].toString(), allArguments[1].toString(), allArguments[3].toString()); 46 | if (connectionInfo == null) { 47 | connectionInfo = URLParser.parser(allArguments[4].toString()); 48 | } 49 | ((EnhancedInstance) ret).setSkyWalkingDynamicField(connectionInfo); 50 | } 51 | return ret; 52 | } 53 | 54 | @Override 55 | public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 56 | Throwable t) { 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/AbstractConnectionInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | import org.apache.skywalking.apm.plugin.jdbc.define.Constants; 27 | 28 | import static net.bytebuddy.matcher.ElementMatchers.named; 29 | import static net.bytebuddy.matcher.ElementMatchers.takesArguments; 30 | 31 | /** 32 | * {@link AbstractConnectionInstrumentation} intercepts the following methods that the class which extend 33 | * com.mysql.jdbc.ConnectionImpl. 34 | *

35 | * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor 36 | * 2. Enhance prepareCall by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor 37 | * 3. Enhance createStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor 38 | * 4. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor 39 | */ 40 | public abstract class AbstractConnectionInstrumentation extends AbstractMysqlInstrumentation { 41 | 42 | @Override 43 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 44 | return new ConstructorInterceptPoint[0]; 45 | } 46 | 47 | @Override 48 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 49 | return new InstanceMethodsInterceptPoint[] { 50 | new InstanceMethodsInterceptPoint() { 51 | @Override 52 | public ElementMatcher getMethodsMatcher() { 53 | return named(Constants.PREPARE_STATEMENT_METHOD_NAME); 54 | } 55 | 56 | @Override 57 | public String getMethodsInterceptor() { 58 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.CREATE_PREPARED_STATEMENT_INTERCEPTOR; 59 | } 60 | 61 | @Override 62 | public boolean isOverrideArgs() { 63 | return true; 64 | } 65 | }, 66 | new InstanceMethodsInterceptPoint() { 67 | @Override 68 | public ElementMatcher getMethodsMatcher() { 69 | return named(Constants.PREPARE_CALL_METHOD_NAME); 70 | } 71 | 72 | @Override 73 | public String getMethodsInterceptor() { 74 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.CREATE_CALLABLE_STATEMENT_INTERCEPTOR; 75 | } 76 | 77 | @Override 78 | public boolean isOverrideArgs() { 79 | return true; 80 | } 81 | }, 82 | new InstanceMethodsInterceptPoint() { 83 | @Override 84 | public ElementMatcher getMethodsMatcher() { 85 | return named(Constants.CREATE_STATEMENT_METHOD_NAME).and(takesArguments(2)); 86 | } 87 | 88 | @Override 89 | public String getMethodsInterceptor() { 90 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.CREATE_STATEMENT_INTERCEPTOR; 91 | } 92 | 93 | @Override 94 | public boolean isOverrideArgs() { 95 | return true; 96 | } 97 | }, 98 | new InstanceMethodsInterceptPoint() { 99 | @Override 100 | public ElementMatcher getMethodsMatcher() { 101 | return named(Constants.COMMIT_METHOD_NAME).or(named(Constants.ROLLBACK_METHOD_NAME)) 102 | .or(named(Constants.CLOSE_METHOD_NAME)) 103 | .or(named(Constants.RELEASE_SAVE_POINT_METHOD_NAME)); 104 | } 105 | 106 | @Override 107 | public String getMethodsInterceptor() { 108 | return Constants.SERVICE_METHOD_INTERCEPT_CLASS; 109 | } 110 | 111 | @Override 112 | public boolean isOverrideArgs() { 113 | return false; 114 | } 115 | }, 116 | new InstanceMethodsInterceptPoint() { 117 | @Override 118 | public ElementMatcher getMethodsMatcher() { 119 | return named("setCatalog"); 120 | } 121 | 122 | @Override 123 | public String getMethodsInterceptor() { 124 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.SET_CATALOG_INTERCEPTOR; 125 | } 126 | 127 | @Override 128 | public boolean isOverrideArgs() { 129 | return false; 130 | } 131 | } 132 | }; 133 | 134 | } 135 | 136 | @Override 137 | protected abstract ClassMatch enhanceClass(); 138 | } 139 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/AbstractMysqlInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine; 25 | 26 | public abstract class AbstractMysqlInstrumentation extends ClassEnhancePluginDefine { 27 | 28 | @Override 29 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 30 | return null; 31 | } 32 | 33 | @Override 34 | public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { 35 | return null; 36 | } 37 | 38 | @Override 39 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 40 | return null; 41 | } 42 | 43 | @Override 44 | protected String[] witnessClasses() { 45 | return new String[] {Constants.WITNESS_MYSQL_5X_CLASS}; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/CacheIpsInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; 29 | import static org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.DRIVER_CONNECT_INTERCEPTOR; 30 | 31 | public class CacheIpsInstrumentation extends AbstractMysqlInstrumentation { 32 | 33 | private static final String ENHANCE_CLASS_NON_REG_REP = "com.mysql.jdbc.NonRegisteringReplicationDriver"; 34 | private static final String ENHANCE_CLASS = "com.mysql.jdbc.Driver"; 35 | private static final String ENHANCE_CLASS_NON_REG = "com.mysql.jdbc.NonRegisteringDriver"; 36 | 37 | @Override 38 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 39 | return new ConstructorInterceptPoint[0]; 40 | } 41 | 42 | @Override 43 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 44 | return new InstanceMethodsInterceptPoint[] { 45 | new InstanceMethodsInterceptPoint() { 46 | @Override 47 | public ElementMatcher getMethodsMatcher() { 48 | return named("connect"); 49 | } 50 | 51 | @Override 52 | public String getMethodsInterceptor() { 53 | return DRIVER_CONNECT_INTERCEPTOR; 54 | } 55 | 56 | @Override 57 | public boolean isOverrideArgs() { 58 | return false; 59 | } 60 | } 61 | }; 62 | } 63 | 64 | @Override 65 | protected ClassMatch enhanceClass() { 66 | return byMultiClassMatch(ENHANCE_CLASS, ENHANCE_CLASS_NON_REG, ENHANCE_CLASS_NON_REG_REP); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/CallableInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 29 | 30 | /** 31 | * {@link CallableInstrumentation} define that the mysql-5.x plugin intercepts the following methods in the 32 | * com.mysql.jdbc.CallableStatement class: 33 | * 1. execute 2. executeQuery 3. executeUpdate 34 | */ 35 | public class CallableInstrumentation extends AbstractMysqlInstrumentation { 36 | private static final String ENHANCE_CLASS = "com.mysql.jdbc.CallableStatement"; 37 | private static final String SERVICE_METHOD_INTERCEPTOR = org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR; 38 | 39 | @Override 40 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 41 | return new ConstructorInterceptPoint[0]; 42 | } 43 | 44 | @Override 45 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 46 | return new InstanceMethodsInterceptPoint[] { 47 | new InstanceMethodsInterceptPoint() { 48 | @Override 49 | public ElementMatcher getMethodsMatcher() { 50 | return named("execute").or(named("executeQuery")).or(named("executeUpdate")); 51 | } 52 | 53 | @Override 54 | public String getMethodsInterceptor() { 55 | return SERVICE_METHOD_INTERCEPTOR; 56 | } 57 | 58 | @Override 59 | public boolean isOverrideArgs() { 60 | return false; 61 | } 62 | } 63 | }; 64 | } 65 | 66 | @Override 67 | protected ClassMatch enhanceClass() { 68 | return byName(ENHANCE_CLASS); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/ConnectionImplCreateInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 25 | 26 | import static net.bytebuddy.matcher.ElementMatchers.named; 27 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 28 | 29 | public class ConnectionImplCreateInstrumentation extends AbstractMysqlInstrumentation { 30 | 31 | private static final String JDBC_ENHANCE_CLASS = "com.mysql.jdbc.ConnectionImpl"; 32 | 33 | private static final String CONNECT_METHOD = "getInstance"; 34 | 35 | @Override 36 | public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { 37 | return new StaticMethodsInterceptPoint[] { 38 | new StaticMethodsInterceptPoint() { 39 | @Override 40 | public ElementMatcher getMethodsMatcher() { 41 | return named(CONNECT_METHOD); 42 | } 43 | 44 | @Override 45 | public String getMethodsInterceptor() { 46 | return "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.ConnectionCreate5xInterceptor"; 47 | } 48 | 49 | @Override 50 | public boolean isOverrideArgs() { 51 | return false; 52 | } 53 | } 54 | }; 55 | } 56 | 57 | @Override 58 | protected ClassMatch enhanceClass() { 59 | return byName(JDBC_ENHANCE_CLASS); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | public class Constants { 22 | public static final String WITNESS_MYSQL_5X_CLASS = "com.mysql.jdbc.ConnectionImpl"; 23 | } 24 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/Mysql50ConnectionInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 22 | 23 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 24 | 25 | /** 26 | * {@link Mysql50ConnectionInstrumentation} interceptor the com.mysql.jdbc.Connection class in the 5.0.x version of 27 | * mysql driver jar. 28 | */ 29 | public class Mysql50ConnectionInstrumentation extends AbstractConnectionInstrumentation { 30 | @Override 31 | protected ClassMatch enhanceClass() { 32 | return byName("com.mysql.jdbc.Connection"); 33 | } 34 | 35 | @Override 36 | protected String[] witnessClasses() { 37 | return new String[] {"com.mysql.jdbc.CursorRowProvider"}; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/Mysql5xConnectionInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 22 | 23 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 24 | 25 | /** 26 | * {@link Mysql5xConnectionInstrumentation } interceptor {@link com.mysql.jdbc.ConnectionImpl} and 27 | * com.mysql.jdbc.ConnectionImpl in mysql jdbc driver 5.1 and 5.1+ 28 | */ 29 | public class Mysql5xConnectionInstrumentation extends AbstractConnectionInstrumentation { 30 | public static final String ENHANCE_CLASS = "com.mysql.jdbc.ConnectionImpl"; 31 | 32 | @Override 33 | protected ClassMatch enhanceClass() { 34 | return byName(ENHANCE_CLASS); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 22 | import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; 23 | 24 | public class PreparedStatementIgnoredSetterInstrumentation extends PreparedStatementInstrumentation { 25 | @Override 26 | public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 27 | return new InstanceMethodsInterceptPoint[] { 28 | new PSSetterDefinitionOfJDBCInstrumentation(true) 29 | }; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | import org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants; 27 | 28 | import static net.bytebuddy.matcher.ElementMatchers.named; 29 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 30 | 31 | /** 32 | * {@link PreparedStatementInstrumentation} define that the mysql-5.x plugin intercepts the following methods in the 33 | * com.mysql.jdbc.PreparedStatement class: 34 | * 1. execute 2. executeQuery 3. executeUpdate 4. executeLargeUpdate 35 | */ 36 | public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentation { 37 | 38 | private static final String SERVICE_METHOD_INTERCEPTOR = Constants.PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR; 39 | public static final String MYSQL_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; 40 | 41 | @Override 42 | public final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 43 | return new ConstructorInterceptPoint[0]; 44 | } 45 | 46 | @Override 47 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 48 | return new InstanceMethodsInterceptPoint[] { 49 | new InstanceMethodsInterceptPoint() { 50 | @Override 51 | public ElementMatcher getMethodsMatcher() { 52 | return named("execute").or(named("executeQuery")) 53 | .or(named("executeUpdate")) 54 | .or(named("executeLargeUpdate")); 55 | } 56 | 57 | @Override 58 | public String getMethodsInterceptor() { 59 | return SERVICE_METHOD_INTERCEPTOR; 60 | } 61 | 62 | @Override 63 | public boolean isOverrideArgs() { 64 | return false; 65 | } 66 | } 67 | }; 68 | } 69 | 70 | @Override 71 | protected ClassMatch enhanceClass() { 72 | return byName(MYSQL_PREPARED_STATEMENT_CLASS_NAME); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 22 | import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; 23 | 24 | public class PreparedStatementNullSetterInstrumentation extends PreparedStatementInstrumentation { 25 | 26 | @Override 27 | public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 28 | return new InstanceMethodsInterceptPoint[] { 29 | new JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint() 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 22 | import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; 23 | 24 | public class PreparedStatementSetterInstrumentation extends PreparedStatementInstrumentation { 25 | 26 | @Override 27 | public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 28 | return new InstanceMethodsInterceptPoint[] { 29 | new PSSetterDefinitionOfJDBCInstrumentation(false) 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v5/define/StatementInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 29 | 30 | /** 31 | * {@link StatementInstrumentation} intercepts the following methods in the com.mysql.jdbc.StatementImpl and 32 | * com.mysql.cj.jdbc.StatementImpl class. 1. execute 2. executeQuery 3. executeUpdate 4. executeLargeUpdate 5. addBatch 33 | * 6. executeBatchInternal 7. executeUpdateInternal 8. executeQuery 9. executeBatch 34 | */ 35 | public class StatementInstrumentation extends AbstractMysqlInstrumentation { 36 | private static final String SERVICE_METHOD_INTERCEPTOR = org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.STATEMENT_EXECUTE_METHODS_INTERCEPTOR; 37 | public static final String MYSQL_STATEMENT_CLASS_NAME = "com.mysql.jdbc.StatementImpl"; 38 | 39 | @Override 40 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 41 | return new ConstructorInterceptPoint[0]; 42 | } 43 | 44 | @Override 45 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 46 | return new InstanceMethodsInterceptPoint[] { 47 | new InstanceMethodsInterceptPoint() { 48 | @Override 49 | public ElementMatcher getMethodsMatcher() { 50 | return named("execute").or(named("executeQuery")) 51 | .or(named("executeUpdate")) 52 | .or(named("executeLargeUpdate")) 53 | .or(named("executeBatchInternal")) 54 | .or(named("executeUpdateInternal")) 55 | .or(named("executeQuery")) 56 | .or(named("executeBatch")); 57 | } 58 | 59 | @Override 60 | public String getMethodsInterceptor() { 61 | return SERVICE_METHOD_INTERCEPTOR; 62 | } 63 | 64 | @Override 65 | public boolean isOverrideArgs() { 66 | return true; 67 | } 68 | } 69 | }; 70 | } 71 | 72 | @Override 73 | protected ClassMatch enhanceClass() { 74 | return byName(MYSQL_STATEMENT_CLASS_NAME); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-5.x/src/main/resources/skywalking-plugin.def: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | cyborg-agent-mysql-5.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define.Mysql5xConnectionInstrumentation 18 | cyborg-agent-mysql-5.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define.Mysql50ConnectionInstrumentation 19 | cyborg-agent-mysql-5.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define.CallableInstrumentation 20 | cyborg-agent-mysql-5.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define.PreparedStatementInstrumentation 21 | cyborg-agent-mysql-5.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define.StatementInstrumentation 22 | cyborg-agent-mysql-5.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define.CacheIpsInstrumentation 23 | cyborg-agent-mysql-5.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define.ConnectionImplCreateInstrumentation 24 | cyborg-agent-mysql-5.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define.PreparedStatementIgnoredSetterInstrumentation 25 | cyborg-agent-mysql-5.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define.PreparedStatementSetterInstrumentation 26 | cyborg-agent-mysql-5.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v5.define.PreparedStatementNullSetterInstrumentation 27 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | cyborg-flow-plugin 23 | org.apache.skywalking 24 | 8.8.0 25 | 26 | 4.0.0 27 | 28 | cyborg-flow-mysql-plugin-6.x 29 | cyborg-flow-mysql-plugin-6.x 30 | jar 31 | 32 | 33 | UTF-8 34 | 6.0.6 35 | 36 | 37 | 38 | 39 | mysql 40 | mysql-connector-java 41 | ${mysql-connector-java.version} 42 | provided 43 | 44 | 45 | org.apache.skywalking 46 | apm-jdbc-commons 47 | ${project.version} 48 | provided 49 | 50 | 51 | org.apache.skywalking 52 | cyborg-flow-mysql-common 53 | ${project.version} 54 | provided 55 | 56 | 57 | 58 | 59 | 60 | 61 | maven-deploy-plugin 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/ConnectionCreateNewInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6; 20 | 21 | import com.mysql.cj.core.conf.url.HostInfo; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; 25 | import org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser.URLParser; 26 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 27 | 28 | import java.lang.reflect.Method; 29 | 30 | /** 31 | * for mysql connector java 6.0.4+ 32 | */ 33 | public class ConnectionCreateNewInterceptor implements StaticMethodsAroundInterceptor { 34 | 35 | @Override 36 | public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 37 | MethodInterceptResult result) { 38 | 39 | } 40 | 41 | @Override 42 | public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 43 | Object ret) { 44 | if (ret instanceof EnhancedInstance) { 45 | final HostInfo hostInfo = (HostInfo) allArguments[0]; 46 | ConnectionInfo connectionInfo = URLParser.parser(hostInfo.getDatabaseUrl()); 47 | ((EnhancedInstance) ret).setSkyWalkingDynamicField(connectionInfo); 48 | } 49 | return ret; 50 | } 51 | 52 | @Override 53 | public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 54 | Throwable t) { 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/ConnectionCreateOldInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; 24 | import org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.ConnectionCache; 25 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 26 | 27 | import java.lang.reflect.Method; 28 | 29 | /** 30 | * for mysql connector java 6.0.2,6.0.3 31 | */ 32 | public class ConnectionCreateOldInterceptor implements StaticMethodsAroundInterceptor { 33 | 34 | @Override 35 | public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 36 | MethodInterceptResult result) { 37 | 38 | } 39 | 40 | @Override 41 | public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 42 | Object ret) { 43 | if (ret instanceof EnhancedInstance) { 44 | String database = ""; 45 | try { 46 | Method getDbMethod = parameterTypes[0].getDeclaredMethod("getDatabase"); 47 | database = (String) getDbMethod.invoke(allArguments[0]); 48 | } catch (Throwable t) { } 49 | ConnectionInfo connectionInfo = ConnectionCache.get(allArguments[1].toString(), allArguments[2].toString(), database); 50 | ((EnhancedInstance) ret).setSkyWalkingDynamicField(connectionInfo); 51 | } 52 | return ret; 53 | } 54 | 55 | @Override 56 | public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 57 | Throwable t) { 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/AbstractMysqlInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine; 25 | 26 | public abstract class AbstractMysqlInstrumentation extends ClassEnhancePluginDefine { 27 | 28 | @Override 29 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 30 | return null; 31 | } 32 | 33 | @Override 34 | public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { 35 | return null; 36 | } 37 | 38 | @Override 39 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 40 | return null; 41 | } 42 | 43 | @Override 44 | protected String[] witnessClasses() { 45 | return new String[] {Constants.WITNESS_MYSQL_6X_CLASS}; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/CacheIpsInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; 29 | import static org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.DRIVER_CONNECT_INTERCEPTOR; 30 | 31 | public class CacheIpsInstrumentation extends AbstractMysqlInstrumentation { 32 | 33 | private static final String ENHANCE_CLASS_NON_REG = "com.mysql.cj.jdbc.NonRegisteringDriver"; 34 | 35 | @Override 36 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 37 | return new ConstructorInterceptPoint[0]; 38 | } 39 | 40 | @Override 41 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 42 | return new InstanceMethodsInterceptPoint[] { 43 | new InstanceMethodsInterceptPoint() { 44 | @Override 45 | public ElementMatcher getMethodsMatcher() { 46 | return named("connect"); 47 | } 48 | 49 | @Override 50 | public String getMethodsInterceptor() { 51 | return DRIVER_CONNECT_INTERCEPTOR; 52 | } 53 | 54 | @Override 55 | public boolean isOverrideArgs() { 56 | return false; 57 | } 58 | } 59 | }; 60 | } 61 | 62 | @Override 63 | protected ClassMatch enhanceClass() { 64 | return byMultiClassMatch(ENHANCE_CLASS_NON_REG); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/CallableInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 29 | 30 | /** 31 | * {@link CallableInstrumentation} define that the mysql-6.x plugin intercepts the following methods in the 32 | * com.mysql.jdbc.cj.CallableStatement class: 33 | * 1. execute 2. executeQuery 3. executeUpdate 34 | */ 35 | public class CallableInstrumentation extends AbstractMysqlInstrumentation { 36 | private static final String ENHANCE_CLASS = "com.mysql.jdbc.cj.CallableStatement"; 37 | private static final String SERVICE_METHOD_INTERCEPTOR = org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR; 38 | 39 | @Override 40 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 41 | return new ConstructorInterceptPoint[0]; 42 | } 43 | 44 | @Override 45 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 46 | return new InstanceMethodsInterceptPoint[] { 47 | new InstanceMethodsInterceptPoint() { 48 | @Override 49 | public ElementMatcher getMethodsMatcher() { 50 | return named("execute").or(named("executeQuery")).or(named("executeUpdate")); 51 | } 52 | 53 | @Override 54 | public String getMethodsInterceptor() { 55 | return SERVICE_METHOD_INTERCEPTOR; 56 | } 57 | 58 | @Override 59 | public boolean isOverrideArgs() { 60 | return false; 61 | } 62 | } 63 | }; 64 | } 65 | 66 | @Override 67 | protected ClassMatch enhanceClass() { 68 | return byName(ENHANCE_CLASS); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/ConnectionImplCreateInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 25 | 26 | import static net.bytebuddy.matcher.ElementMatchers.named; 27 | import static net.bytebuddy.matcher.ElementMatchers.takesArguments; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 29 | 30 | /** 31 | * interceptor the method {@link com.mysql.cj.jdbc.ConnectionImpl#getInstance} for mysql client version 6.x 32 | */ 33 | public class ConnectionImplCreateInstrumentation extends AbstractMysqlInstrumentation { 34 | 35 | private static final String JDBC_ENHANCE_CLASS = "com.mysql.cj.jdbc.ConnectionImpl"; 36 | 37 | private static final String CONNECT_METHOD = "getInstance"; 38 | 39 | private static final String GET_INSTANCE_NEW_INTERCEPTOR = "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.ConnectionCreateNewInterceptor"; 40 | 41 | private static final String GET_INSTANCE_OLD_INTERCEPTOR = "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.ConnectionCreateOldInterceptor"; 42 | 43 | @Override 44 | public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { 45 | return new StaticMethodsInterceptPoint[] { 46 | new StaticMethodsInterceptPoint() { 47 | @Override 48 | public ElementMatcher getMethodsMatcher() { 49 | return named(CONNECT_METHOD).and(takesArguments(1)); 50 | } 51 | 52 | @Override 53 | public String getMethodsInterceptor() { 54 | return GET_INSTANCE_NEW_INTERCEPTOR; 55 | } 56 | 57 | @Override 58 | public boolean isOverrideArgs() { 59 | return false; 60 | } 61 | }, 62 | new StaticMethodsInterceptPoint() { 63 | @Override 64 | public ElementMatcher getMethodsMatcher() { 65 | return named(CONNECT_METHOD).and(takesArguments(4)); 66 | } 67 | 68 | @Override 69 | public String getMethodsInterceptor() { 70 | return GET_INSTANCE_OLD_INTERCEPTOR; 71 | } 72 | 73 | @Override 74 | public boolean isOverrideArgs() { 75 | return false; 76 | } 77 | } 78 | }; 79 | } 80 | 81 | @Override 82 | protected ClassMatch enhanceClass() { 83 | return byName(JDBC_ENHANCE_CLASS); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/ConnectionInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static net.bytebuddy.matcher.ElementMatchers.takesArguments; 29 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 30 | 31 | public class ConnectionInstrumentation extends AbstractMysqlInstrumentation { 32 | 33 | public static final String ENHANCE_CLASS = "com.mysql.cj.jdbc.ConnectionImpl"; 34 | 35 | @Override 36 | protected ClassMatch enhanceClass() { 37 | return byName(ENHANCE_CLASS); 38 | } 39 | 40 | @Override 41 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 42 | return new ConstructorInterceptPoint[0]; 43 | } 44 | 45 | @Override 46 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 47 | return new InstanceMethodsInterceptPoint[] { 48 | new InstanceMethodsInterceptPoint() { 49 | @Override 50 | public ElementMatcher getMethodsMatcher() { 51 | return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME); 52 | } 53 | 54 | @Override 55 | public String getMethodsInterceptor() { 56 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.CREATE_PREPARED_STATEMENT_INTERCEPTOR; 57 | } 58 | 59 | @Override 60 | public boolean isOverrideArgs() { 61 | return true; 62 | } 63 | }, 64 | new InstanceMethodsInterceptPoint() { 65 | @Override 66 | public ElementMatcher getMethodsMatcher() { 67 | return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME); 68 | } 69 | 70 | @Override 71 | public String getMethodsInterceptor() { 72 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.CREATE_CALLABLE_STATEMENT_INTERCEPTOR; 73 | } 74 | 75 | @Override 76 | public boolean isOverrideArgs() { 77 | return true; 78 | } 79 | }, 80 | new InstanceMethodsInterceptPoint() { 81 | @Override 82 | public ElementMatcher getMethodsMatcher() { 83 | return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME).and(takesArguments(2)); 84 | } 85 | 86 | @Override 87 | public String getMethodsInterceptor() { 88 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.CREATE_STATEMENT_INTERCEPTOR; 89 | } 90 | 91 | @Override 92 | public boolean isOverrideArgs() { 93 | return true; 94 | } 95 | }, 96 | new InstanceMethodsInterceptPoint() { 97 | @Override 98 | public ElementMatcher getMethodsMatcher() { 99 | return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME).or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME)) 100 | .or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME)) 101 | .or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME)); 102 | } 103 | 104 | @Override 105 | public String getMethodsInterceptor() { 106 | return org.apache.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; 107 | } 108 | 109 | @Override 110 | public boolean isOverrideArgs() { 111 | return false; 112 | } 113 | }, 114 | new InstanceMethodsInterceptPoint() { 115 | @Override 116 | public ElementMatcher getMethodsMatcher() { 117 | return named("setCatalog"); 118 | } 119 | 120 | @Override 121 | public String getMethodsInterceptor() { 122 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.SET_CATALOG_INTERCEPTOR; 123 | } 124 | 125 | @Override 126 | public boolean isOverrideArgs() { 127 | return false; 128 | } 129 | } 130 | }; 131 | 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | public class Constants { 22 | public static final String WITNESS_MYSQL_6X_CLASS = "com.mysql.cj.api.MysqlConnection"; 23 | } 24 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/DriverInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 22 | import org.apache.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; 23 | 24 | import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; 25 | 26 | /** 27 | * {@link DriverInstrumentation} presents that skywalking intercepts {@link com.mysql.jdbc.Driver}. 28 | */ 29 | public class DriverInstrumentation extends AbstractDriverInstrumentation { 30 | @Override 31 | protected ClassMatch enhanceClass() { 32 | return byMultiClassMatch("com.mysql.jdbc.Driver", "com.mysql.cj.jdbc.Driver", "com.mysql.jdbc.NonRegisteringDriver"); 33 | } 34 | 35 | @Override 36 | protected String[] witnessClasses() { 37 | return new String[] {Constants.WITNESS_MYSQL_6X_CLASS}; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 22 | import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; 23 | 24 | public class PreparedStatementIgnoredSetterInstrumentation extends PreparedStatementInstrumentation { 25 | 26 | @Override 27 | public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 28 | return new InstanceMethodsInterceptPoint[] { 29 | new PSSetterDefinitionOfJDBCInstrumentation(true) 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 29 | 30 | /** 31 | * {@link PreparedStatementInstrumentation} define that the mysql-6.x plugin intercepts the following methods in the 32 | * com.mysql.cj.jdbc.PreparedStatement class: 33 | * 1. execute 2. executeQuery 3. executeUpdate 4. executeLargeUpdate 34 | */ 35 | public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentation { 36 | 37 | private static final String SERVICE_METHOD_INTERCEPTOR = org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR; 38 | public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; 39 | 40 | @Override 41 | public final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 42 | return new ConstructorInterceptPoint[0]; 43 | } 44 | 45 | @Override 46 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 47 | return new InstanceMethodsInterceptPoint[] { 48 | new InstanceMethodsInterceptPoint() { 49 | @Override 50 | public ElementMatcher getMethodsMatcher() { 51 | return named("execute").or(named("executeQuery")) 52 | .or(named("executeUpdate")) 53 | .or(named("executeLargeUpdate")); 54 | } 55 | 56 | @Override 57 | public String getMethodsInterceptor() { 58 | return SERVICE_METHOD_INTERCEPTOR; 59 | } 60 | 61 | @Override 62 | public boolean isOverrideArgs() { 63 | return false; 64 | } 65 | } 66 | }; 67 | } 68 | 69 | @Override 70 | protected ClassMatch enhanceClass() { 71 | return byName(MYSQL6_PREPARED_STATEMENT_CLASS_NAME); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 22 | import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; 23 | 24 | public class PreparedStatementNullSetterInstrumentation extends PreparedStatementInstrumentation { 25 | 26 | @Override 27 | public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 28 | return new InstanceMethodsInterceptPoint[] { 29 | new JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint() 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 22 | import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; 23 | 24 | public class PreparedStatementSetterInstrumentation extends PreparedStatementInstrumentation { 25 | 26 | @Override 27 | public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 28 | return new InstanceMethodsInterceptPoint[] { 29 | new PSSetterDefinitionOfJDBCInstrumentation(false) 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v6/define/StatementInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 29 | 30 | /** 31 | * {@link StatementInstrumentation} intercepts the following methods in the com.mysql.jdbc.StatementImpl and 32 | * com.mysql.cj.jdbc.StatementImpl class. 1. execute 2. executeQuery 3. executeUpdate 4. executeLargeUpdate 5. addBatch 33 | * 6. executeBatchInternal 7. executeUpdateInternal 8. executeQuery 9. executeBatch 34 | */ 35 | public class StatementInstrumentation extends AbstractMysqlInstrumentation { 36 | private static final String SERVICE_METHOD_INTERCEPTOR = org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.STATEMENT_EXECUTE_METHODS_INTERCEPTOR; 37 | public static final String MYSQL6_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.StatementImpl"; 38 | 39 | @Override 40 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 41 | return new ConstructorInterceptPoint[0]; 42 | } 43 | 44 | @Override 45 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 46 | return new InstanceMethodsInterceptPoint[] { 47 | new InstanceMethodsInterceptPoint() { 48 | @Override 49 | public ElementMatcher getMethodsMatcher() { 50 | return named("execute").or(named("executeQuery")) 51 | .or(named("executeUpdate")) 52 | .or(named("executeLargeUpdate")) 53 | .or(named("executeBatchInternal")) 54 | .or(named("executeUpdateInternal")) 55 | .or(named("executeQuery")) 56 | .or(named("executeBatch")); 57 | } 58 | 59 | @Override 60 | public String getMethodsInterceptor() { 61 | return SERVICE_METHOD_INTERCEPTOR; 62 | } 63 | 64 | @Override 65 | public boolean isOverrideArgs() { 66 | return true; 67 | } 68 | } 69 | }; 70 | } 71 | 72 | @Override 73 | protected ClassMatch enhanceClass() { 74 | return byName(MYSQL6_STATEMENT_CLASS_NAME); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-6.x/src/main/resources/skywalking-plugin.def: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | cyborg-agent-mysql-6.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define.DriverInstrumentation 18 | cyborg-agent-mysql-6.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define.ConnectionInstrumentation 19 | cyborg-agent-mysql-6.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define.CallableInstrumentation 20 | cyborg-agent-mysql-6.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define.PreparedStatementInstrumentation 21 | cyborg-agent-mysql-6.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define.StatementInstrumentation 22 | cyborg-agent-mysql-6.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define.CacheIpsInstrumentation 23 | cyborg-agent-mysql-6.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define.ConnectionImplCreateInstrumentation 24 | cyborg-agent-mysql-6.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define.PreparedStatementSetterInstrumentation 25 | cyborg-agent-mysql-6.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define.PreparedStatementIgnoredSetterInstrumentation 26 | cyborg-agent-mysql-6.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v6.define.PreparedStatementNullSetterInstrumentation 27 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | cyborg-flow-plugin 23 | org.apache.skywalking 24 | 8.8.0 25 | 26 | 4.0.0 27 | 28 | cyborg-flow-mysql-plugin-8.x 29 | cyborg-flow-mysql-plugin-8.x 30 | jar 31 | 32 | 33 | 8.0.13 34 | 35 | 36 | 37 | 38 | mysql 39 | mysql-connector-java 40 | ${mysql-connector-java.version} 41 | provided 42 | 43 | 44 | org.apache.skywalking 45 | apm-jdbc-commons 46 | ${project.version} 47 | provided 48 | 49 | 50 | org.apache.skywalking 51 | cyborg-flow-mysql-common 52 | ${project.version} 53 | provided 54 | 55 | 56 | 57 | 58 | 59 | 60 | maven-deploy-plugin 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/ConnectionCreateInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8; 20 | 21 | import com.mysql.cj.conf.HostInfo; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; 25 | import org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.ConnectionCache; 26 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 27 | 28 | import java.lang.reflect.Method; 29 | 30 | public class ConnectionCreateInterceptor implements StaticMethodsAroundInterceptor { 31 | 32 | @Override 33 | public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 34 | MethodInterceptResult result) { 35 | 36 | } 37 | 38 | @Override 39 | public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 40 | Object ret) { 41 | if (ret instanceof EnhancedInstance) { 42 | final HostInfo hostInfo = (HostInfo) allArguments[0]; 43 | ConnectionInfo connectionInfo = ConnectionCache.get(hostInfo.getHostPortPair(), hostInfo.getDatabase()); 44 | ((EnhancedInstance) ret).setSkyWalkingDynamicField(connectionInfo); 45 | } 46 | return ret; 47 | } 48 | 49 | @Override 50 | public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, 51 | Throwable t) { 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/AbstractMysqlInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine; 25 | 26 | public abstract class AbstractMysqlInstrumentation extends ClassEnhancePluginDefine { 27 | 28 | @Override 29 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 30 | return null; 31 | } 32 | 33 | @Override 34 | public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { 35 | return null; 36 | } 37 | 38 | @Override 39 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 40 | return null; 41 | } 42 | 43 | @Override 44 | protected String[] witnessClasses() { 45 | return new String[] {Constants.WITNESS_MYSQL_8X_CLASS}; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/CacheIpsInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; 29 | import static org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.DRIVER_CONNECT_INTERCEPTOR; 30 | 31 | public class CacheIpsInstrumentation extends AbstractMysqlInstrumentation { 32 | 33 | private static final String ENHANCE_CLASS_NON_REG = "com.mysql.cj.jdbc.NonRegisteringDriver"; 34 | 35 | @Override 36 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 37 | return new ConstructorInterceptPoint[0]; 38 | } 39 | 40 | @Override 41 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 42 | return new InstanceMethodsInterceptPoint[] { 43 | new InstanceMethodsInterceptPoint() { 44 | @Override 45 | public ElementMatcher getMethodsMatcher() { 46 | return named("connect"); 47 | } 48 | 49 | @Override 50 | public String getMethodsInterceptor() { 51 | return DRIVER_CONNECT_INTERCEPTOR; 52 | } 53 | 54 | @Override 55 | public boolean isOverrideArgs() { 56 | return false; 57 | } 58 | } 59 | }; 60 | } 61 | 62 | @Override 63 | protected ClassMatch enhanceClass() { 64 | return byMultiClassMatch(ENHANCE_CLASS_NON_REG); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/CallableInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 29 | 30 | public class CallableInstrumentation extends AbstractMysqlInstrumentation { 31 | private static final String ENHANCE_CLASS = "com.mysql.cj.jdbc.CallableStatement"; 32 | private static final String SERVICE_METHOD_INTERCEPTOR = org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR; 33 | 34 | @Override 35 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 36 | return new ConstructorInterceptPoint[0]; 37 | } 38 | 39 | @Override 40 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 41 | return new InstanceMethodsInterceptPoint[] { 42 | new InstanceMethodsInterceptPoint() { 43 | @Override 44 | public ElementMatcher getMethodsMatcher() { 45 | return named("execute").or(named("executeQuery")).or(named("executeUpdate")); 46 | } 47 | 48 | @Override 49 | public String getMethodsInterceptor() { 50 | return SERVICE_METHOD_INTERCEPTOR; 51 | } 52 | 53 | @Override 54 | public boolean isOverrideArgs() { 55 | return false; 56 | } 57 | } 58 | }; 59 | } 60 | 61 | @Override 62 | protected ClassMatch enhanceClass() { 63 | return byName(ENHANCE_CLASS); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/ConnectionImplCreateInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 25 | 26 | import java.util.Properties; 27 | 28 | import static net.bytebuddy.matcher.ElementMatchers.named; 29 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 30 | 31 | /** 32 | * interceptor the method {@link com.mysql.cj.jdbc.ConnectionImpl#getInstance(com.mysql.cj.conf.HostInfo)} instead of 33 | * {@link com.mysql.cj.jdbc.Driver#connect(String, Properties)} 34 | */ 35 | public class ConnectionImplCreateInstrumentation extends AbstractMysqlInstrumentation { 36 | 37 | private static final String JDBC_ENHANCE_CLASS = "com.mysql.cj.jdbc.ConnectionImpl"; 38 | 39 | private static final String CONNECT_METHOD = "getInstance"; 40 | 41 | @Override 42 | public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { 43 | return new StaticMethodsInterceptPoint[] { 44 | new StaticMethodsInterceptPoint() { 45 | @Override 46 | public ElementMatcher getMethodsMatcher() { 47 | return named(CONNECT_METHOD); 48 | } 49 | 50 | @Override 51 | public String getMethodsInterceptor() { 52 | return "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.ConnectionCreateInterceptor"; 53 | } 54 | 55 | @Override 56 | public boolean isOverrideArgs() { 57 | return false; 58 | } 59 | } 60 | }; 61 | } 62 | 63 | @Override 64 | protected ClassMatch enhanceClass() { 65 | return byName(JDBC_ENHANCE_CLASS); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/ConnectionInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static net.bytebuddy.matcher.ElementMatchers.takesArguments; 29 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 30 | 31 | public class ConnectionInstrumentation extends AbstractMysqlInstrumentation { 32 | 33 | @Override 34 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 35 | return new ConstructorInterceptPoint[0]; 36 | } 37 | 38 | @Override 39 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 40 | return new InstanceMethodsInterceptPoint[] { 41 | new InstanceMethodsInterceptPoint() { 42 | @Override 43 | public ElementMatcher getMethodsMatcher() { 44 | return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME); 45 | } 46 | 47 | @Override 48 | public String getMethodsInterceptor() { 49 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.CREATE_PREPARED_STATEMENT_INTERCEPTOR; 50 | } 51 | 52 | @Override 53 | public boolean isOverrideArgs() { 54 | return true; 55 | } 56 | }, 57 | new InstanceMethodsInterceptPoint() { 58 | @Override 59 | public ElementMatcher getMethodsMatcher() { 60 | return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME); 61 | } 62 | 63 | @Override 64 | public String getMethodsInterceptor() { 65 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.CREATE_CALLABLE_STATEMENT_INTERCEPTOR; 66 | } 67 | 68 | @Override 69 | public boolean isOverrideArgs() { 70 | return true; 71 | } 72 | }, 73 | new InstanceMethodsInterceptPoint() { 74 | @Override 75 | public ElementMatcher getMethodsMatcher() { 76 | return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME).and(takesArguments(2)); 77 | } 78 | 79 | @Override 80 | public String getMethodsInterceptor() { 81 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.CREATE_STATEMENT_INTERCEPTOR; 82 | } 83 | 84 | @Override 85 | public boolean isOverrideArgs() { 86 | return true; 87 | } 88 | }, 89 | new InstanceMethodsInterceptPoint() { 90 | @Override 91 | public ElementMatcher getMethodsMatcher() { 92 | return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME).or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME)) 93 | .or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME)) 94 | .or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME)); 95 | } 96 | 97 | @Override 98 | public String getMethodsInterceptor() { 99 | return org.apache.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; 100 | } 101 | 102 | @Override 103 | public boolean isOverrideArgs() { 104 | return false; 105 | } 106 | }, 107 | new InstanceMethodsInterceptPoint() { 108 | @Override 109 | public ElementMatcher getMethodsMatcher() { 110 | return named("setCatalog"); 111 | } 112 | 113 | @Override 114 | public String getMethodsInterceptor() { 115 | return org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.SET_CATALOG_INTERCEPTOR; 116 | } 117 | 118 | @Override 119 | public boolean isOverrideArgs() { 120 | return false; 121 | } 122 | } 123 | }; 124 | 125 | } 126 | 127 | @Override 128 | protected ClassMatch enhanceClass() { 129 | return byName("com.mysql.cj.jdbc.ConnectionImpl"); 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | public class Constants { 22 | public static final String WITNESS_MYSQL_8X_CLASS = "com.mysql.cj.interceptors.QueryInterceptor"; 23 | } 24 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 22 | import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; 23 | 24 | public class PreparedStatementIgnoredSetterInstrumentation extends PreparedStatementInstrumentation { 25 | 26 | @Override 27 | public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 28 | return new InstanceMethodsInterceptPoint[] { 29 | new PSSetterDefinitionOfJDBCInstrumentation(true) 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | import org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants; 27 | 28 | import static net.bytebuddy.matcher.ElementMatchers.named; 29 | import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; 30 | 31 | public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentation { 32 | 33 | private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.ClientPreparedStatement"; 34 | private static final String PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement"; 35 | 36 | private static final String SERVICE_METHOD_INTERCEPTOR = Constants.PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR; 37 | 38 | @Override 39 | public final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 40 | return new ConstructorInterceptPoint[0]; 41 | } 42 | 43 | @Override 44 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 45 | return new InstanceMethodsInterceptPoint[] { 46 | new InstanceMethodsInterceptPoint() { 47 | @Override 48 | public ElementMatcher getMethodsMatcher() { 49 | return named("execute").or(named("executeQuery")) 50 | .or(named("executeUpdate")) 51 | .or(named("executeLargeUpdate")); 52 | } 53 | 54 | @Override 55 | public String getMethodsInterceptor() { 56 | return SERVICE_METHOD_INTERCEPTOR; 57 | } 58 | 59 | @Override 60 | public boolean isOverrideArgs() { 61 | return false; 62 | } 63 | } 64 | }; 65 | } 66 | 67 | @Override 68 | protected ClassMatch enhanceClass() { 69 | return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 22 | import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; 23 | 24 | public class PreparedStatementNullSetterInstrumentation extends PreparedStatementInstrumentation { 25 | 26 | @Override 27 | public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 28 | return new InstanceMethodsInterceptPoint[] { 29 | new JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint() 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 22 | import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; 23 | 24 | public class PreparedStatementSetterInstrumentation extends PreparedStatementInstrumentation { 25 | 26 | @Override 27 | public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 28 | return new InstanceMethodsInterceptPoint[] { 29 | new PSSetterDefinitionOfJDBCInstrumentation(false) 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/v8/define/StatementInstrumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define; 20 | 21 | import net.bytebuddy.description.method.MethodDescription; 22 | import net.bytebuddy.matcher.ElementMatcher; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; 24 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 25 | import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; 26 | 27 | import static net.bytebuddy.matcher.ElementMatchers.named; 28 | import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; 29 | 30 | public class StatementInstrumentation extends AbstractMysqlInstrumentation { 31 | private static final String SERVICE_METHOD_INTERCEPTOR = org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.STATEMENT_EXECUTE_METHODS_INTERCEPTOR; 32 | public static final String MYSQL8_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.StatementImpl"; 33 | 34 | @Override 35 | public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { 36 | return new ConstructorInterceptPoint[0]; 37 | } 38 | 39 | @Override 40 | public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { 41 | return new InstanceMethodsInterceptPoint[] { 42 | new InstanceMethodsInterceptPoint() { 43 | @Override 44 | public ElementMatcher getMethodsMatcher() { 45 | return named("execute").or(named("executeQuery")) 46 | .or(named("executeUpdate")) 47 | .or(named("executeLargeUpdate")) 48 | .or(named("executeBatchInternal")) 49 | .or(named("executeUpdateInternal")) 50 | .or(named("executeQuery")) 51 | .or(named("executeBatch")); 52 | } 53 | 54 | @Override 55 | public String getMethodsInterceptor() { 56 | return SERVICE_METHOD_INTERCEPTOR; 57 | } 58 | 59 | @Override 60 | public boolean isOverrideArgs() { 61 | return true; 62 | } 63 | } 64 | }; 65 | } 66 | 67 | @Override 68 | protected ClassMatch enhanceClass() { 69 | return byName(MYSQL8_STATEMENT_CLASS_NAME); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-8.x/src/main/resources/skywalking-plugin.def: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | cyborg-agent-mysql-8.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define.ConnectionImplCreateInstrumentation 18 | cyborg-agent-mysql-8.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define.ConnectionInstrumentation 19 | cyborg-agent-mysql-8.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define.CallableInstrumentation 20 | cyborg-agent-mysql-8.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define.PreparedStatementInstrumentation 21 | cyborg-agent-mysql-8.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define.StatementInstrumentation 22 | cyborg-agent-mysql-8.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define.PreparedStatementSetterInstrumentation 23 | cyborg-agent-mysql-8.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define.PreparedStatementNullSetterInstrumentation 24 | cyborg-agent-mysql-8.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define.PreparedStatementIgnoredSetterInstrumentation 25 | cyborg-agent-mysql-8.x=org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.v8.define.CacheIpsInstrumentation -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 23 | 24 | cyborg-flow-plugin 25 | org.apache.skywalking 26 | 8.8.0 27 | 28 | 4.0.0 29 | 30 | cyborg-flow-mysql-common 31 | cyborg-flow-mysql-common 32 | jar 33 | 34 | 35 | UTF-8 36 | 8.0.13 37 | 38 | 39 | 40 | 41 | 42 | mysql 43 | mysql-connector-java 44 | ${mysql-connector-java.version} 45 | test 46 | 47 | 48 | org.apache.skywalking 49 | apm-jdbc-commons 50 | ${project.version} 51 | provided 52 | 53 | 54 | 55 | 56 | 57 | 58 | maven-deploy-plugin 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/ConnectionCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql; 20 | 21 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 22 | import org.apache.skywalking.apm.util.StringUtil; 23 | 24 | import java.util.concurrent.ConcurrentHashMap; 25 | 26 | public class ConnectionCache { 27 | private static final ConcurrentHashMap CONNECTIONS_MAP = new ConcurrentHashMap(); 28 | 29 | private static final String CONNECTION_SPLIT_STR = ","; 30 | 31 | public static ConnectionInfo get(String host, String port, String databaseName) { 32 | final String hostPortPair = String.format("%s:%s/%s", host, port, databaseName); 33 | return CONNECTIONS_MAP.get(hostPortPair); 34 | } 35 | 36 | public static ConnectionInfo get(String hostPortPair, String databaseName) { 37 | return CONNECTIONS_MAP.get(hostPortPair + "/" + databaseName); 38 | } 39 | 40 | public static void save(ConnectionInfo connectionInfo) { 41 | for (String conn : connectionInfo.getDatabasePeer().split(CONNECTION_SPLIT_STR)) { 42 | if (!StringUtil.isEmpty(conn)) { 43 | CONNECTIONS_MAP.putIfAbsent(conn + "/" + connectionInfo.getDatabaseName(), connectionInfo); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql; 20 | 21 | import org.apache.skywalking.apm.agent.core.context.tag.StringTag; 22 | 23 | public class Constants { 24 | public static final String CREATE_CALLABLE_STATEMENT_INTERCEPTOR = "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.CreateCallableStatementInterceptor"; 25 | public static final String CREATE_PREPARED_STATEMENT_INTERCEPTOR = "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.CreatePreparedStatementInterceptor"; 26 | public static final String CREATE_STATEMENT_INTERCEPTOR = "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.CreateStatementInterceptor"; 27 | public static final String PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.PreparedStatementExecuteMethodsInterceptor"; 28 | public static final String SET_CATALOG_INTERCEPTOR = "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.SetCatalogInterceptor"; 29 | public static final String STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; 30 | public static final String DRIVER_CONNECT_INTERCEPTOR = "org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.DriverConnectInterceptor"; 31 | 32 | public static final StringTag SQL_PARAMETERS = new StringTag("db.sql.parameters"); 33 | } 34 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 24 | import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; 25 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 26 | 27 | import java.lang.reflect.Method; 28 | 29 | public class CreateCallableStatementInterceptor implements InstanceMethodsAroundInterceptor { 30 | @Override 31 | public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, 32 | MethodInterceptResult result) throws Throwable { 33 | // inject sql 34 | allArguments[0] = CyborgSqlInjector.inject((String) allArguments[0]); 35 | } 36 | 37 | @Override 38 | public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, 39 | Object ret) throws Throwable { 40 | if (ret instanceof EnhancedInstance) { 41 | ((EnhancedInstance) ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo) objInst.getSkyWalkingDynamicField(), (String) allArguments[0], "CallableStatement")); 42 | } 43 | return ret; 44 | } 45 | 46 | @Override 47 | public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, 48 | Class[] argumentsTypes, Throwable t) { 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 24 | import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; 25 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 26 | 27 | import java.lang.reflect.Method; 28 | 29 | public class CreatePreparedStatementInterceptor implements InstanceMethodsAroundInterceptor { 30 | @Override 31 | public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, 32 | MethodInterceptResult result) throws Throwable { 33 | // inject sql 34 | allArguments[0] = CyborgSqlInjector.inject((String) allArguments[0]); 35 | } 36 | 37 | @Override 38 | public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, 39 | Object ret) throws Throwable { 40 | if (ret instanceof EnhancedInstance) { 41 | ((EnhancedInstance) ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo) objInst.getSkyWalkingDynamicField(), (String) allArguments[0], "PreparedStatement")); 42 | } 43 | return ret; 44 | } 45 | 46 | @Override 47 | public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, 48 | Class[] argumentsTypes, Throwable t) { 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/CreateStatementInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 24 | import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; 25 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 26 | 27 | import java.lang.reflect.Method; 28 | 29 | public class CreateStatementInterceptor implements InstanceMethodsAroundInterceptor { 30 | @Override 31 | public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, 32 | MethodInterceptResult result) throws Throwable { 33 | } 34 | 35 | @Override 36 | public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, 37 | Object ret) throws Throwable { 38 | if (ret instanceof EnhancedInstance) { 39 | ((EnhancedInstance) ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo) objInst.getSkyWalkingDynamicField(), "", "Statement")); 40 | } 41 | return ret; 42 | } 43 | 44 | @Override 45 | public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, 46 | Class[] argumentsTypes, Throwable t) { 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/CyborgSqlInjector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql; 20 | 21 | import org.apache.skywalking.apm.agent.core.context.ContextManager; 22 | import org.apache.skywalking.apm.agent.core.context.CorrelationContext; 23 | 24 | import java.util.Objects; 25 | 26 | public class CyborgSqlInjector { 27 | 28 | public static final String CORRELATION_CONTEXT_KEY = "cyborg-flow"; 29 | public static final String CORRELATION_CONTEXT_VALUE = "true"; 30 | 31 | public static final String APPEND_TAG_IN_SQL = "/* cyborg-flow:true */"; 32 | 33 | /** 34 | * Inject the tag to sql when context include `cyborg-flow` 35 | */ 36 | public static String inject(String sql) { 37 | final CorrelationContext context = ContextManager.getCorrelationContext(); 38 | if (context == null) { 39 | return sql; 40 | } 41 | 42 | final Boolean needInject = context.get(CORRELATION_CONTEXT_KEY) 43 | .map(s -> Objects.equals(s, CORRELATION_CONTEXT_VALUE)).orElse(false); 44 | if (!needInject) { 45 | return sql; 46 | } 47 | 48 | return sql + APPEND_TAG_IN_SQL; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/DriverConnectInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 24 | import org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser.URLParser; 25 | 26 | import java.lang.reflect.Method; 27 | 28 | public class DriverConnectInterceptor implements InstanceMethodsAroundInterceptor { 29 | 30 | @Override 31 | public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, 32 | MethodInterceptResult result) throws Throwable { 33 | ConnectionCache.save(URLParser.parser(allArguments[0].toString())); 34 | } 35 | 36 | @Override 37 | public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, 38 | Object ret) throws Throwable { 39 | return ret; 40 | } 41 | 42 | @Override 43 | public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, 44 | Class[] argumentsTypes, Throwable t) { 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql; 20 | 21 | import org.apache.skywalking.apm.agent.core.context.ContextManager; 22 | import org.apache.skywalking.apm.agent.core.context.tag.Tags; 23 | import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; 24 | import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; 25 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 26 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; 27 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 28 | import org.apache.skywalking.apm.plugin.jdbc.JDBCPluginConfig; 29 | import org.apache.skywalking.apm.plugin.jdbc.PreparedStatementParameterBuilder; 30 | import org.apache.skywalking.apm.plugin.jdbc.SqlBodyUtil; 31 | import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; 32 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 33 | 34 | import java.lang.reflect.Method; 35 | 36 | import static org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql.Constants.SQL_PARAMETERS; 37 | 38 | public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { 39 | 40 | @Override 41 | public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, 42 | Class[] argumentsTypes, MethodInterceptResult result) { 43 | StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); 44 | /** 45 | * For avoid NPE. In this particular case, Execute sql inside the {@link com.mysql.jdbc.ConnectionImpl} constructor, 46 | * before the interceptor sets the connectionInfo. 47 | * When invoking prepareCall, cacheObject is null. Because it will determine procedures's parameter types by executing sql in mysql 48 | * before the interceptor sets the statementEnhanceInfos. 49 | * @see JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object) 50 | */ 51 | if (cacheObject != null && cacheObject.getConnectionInfo() != null) { 52 | ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); 53 | AbstractSpan span = ContextManager.createExitSpan( 54 | buildOperationName(connectInfo, method.getName(), cacheObject 55 | .getStatementName()), connectInfo.getDatabasePeer()); 56 | Tags.DB_TYPE.set(span, "sql"); 57 | Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); 58 | Tags.DB_STATEMENT.set(span, SqlBodyUtil.limitSqlBodySize(cacheObject.getSql())); 59 | span.setComponent(connectInfo.getComponent()); 60 | 61 | if (JDBCPluginConfig.Plugin.JDBC.TRACE_SQL_PARAMETERS) { 62 | final Object[] parameters = cacheObject.getParameters(); 63 | if (parameters != null && parameters.length > 0) { 64 | int maxIndex = cacheObject.getMaxIndex(); 65 | String parameterString = getParameterString(parameters, maxIndex); 66 | SQL_PARAMETERS.set(span, parameterString); 67 | } 68 | } 69 | 70 | SpanLayer.asDB(span); 71 | } 72 | } 73 | 74 | @Override 75 | public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, 76 | Class[] argumentsTypes, Object ret) { 77 | StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); 78 | if (cacheObject != null && cacheObject.getConnectionInfo() != null) { 79 | ContextManager.stopSpan(); 80 | } 81 | return ret; 82 | } 83 | 84 | @Override 85 | public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, 86 | Class[] argumentsTypes, Throwable t) { 87 | StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); 88 | if (cacheObject != null && cacheObject.getConnectionInfo() != null) { 89 | ContextManager.activeSpan().log(t); 90 | } 91 | } 92 | 93 | private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { 94 | return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; 95 | } 96 | 97 | private String getParameterString(Object[] parameters, int maxIndex) { 98 | return new PreparedStatementParameterBuilder() 99 | .setParameters(parameters) 100 | .setMaxIndex(maxIndex) 101 | .build(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/SetCatalogInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql; 20 | 21 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 22 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; 23 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 24 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 25 | 26 | import java.lang.reflect.Method; 27 | 28 | public class SetCatalogInterceptor implements InstanceMethodsAroundInterceptor { 29 | @Override 30 | public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, 31 | MethodInterceptResult result) throws Throwable { 32 | Object dynamicField = objInst.getSkyWalkingDynamicField(); 33 | if (dynamicField instanceof ConnectionInfo) { 34 | ((ConnectionInfo) dynamicField).setDatabaseName(String.valueOf(allArguments[0])); 35 | } 36 | } 37 | 38 | @Override 39 | public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, 40 | Object ret) throws Throwable { 41 | return ret; 42 | } 43 | 44 | @Override 45 | public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, 46 | Class[] argumentsTypes, Throwable t) { 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/mysql-common/src/main/java/org/apache/skywalking/apm/cyborg/flow/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.skywalking.apm.cyborg.flow.plugin.jdbc.mysql; 20 | 21 | import org.apache.skywalking.apm.agent.core.context.ContextManager; 22 | import org.apache.skywalking.apm.agent.core.context.tag.Tags; 23 | import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; 24 | import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; 25 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; 26 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; 27 | import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; 28 | import org.apache.skywalking.apm.plugin.jdbc.SqlBodyUtil; 29 | import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; 30 | import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; 31 | 32 | import java.lang.reflect.Method; 33 | 34 | public class StatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { 35 | @Override 36 | public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, 37 | Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { 38 | StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); 39 | ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); 40 | // inject sql 41 | allArguments[0] = CyborgSqlInjector.inject((String) allArguments[0]); 42 | /** 43 | * To protected the code occur NullPointException. because mysql execute system sql when constructor method in 44 | * {@link com.mysql.jdbc.ConnectionImpl} class executed. but the interceptor set the connection Info after 45 | * the constructor method executed. 46 | * 47 | * @see JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object) 48 | */ 49 | if (connectInfo != null) { 50 | 51 | AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject 52 | .getStatementName()), connectInfo.getDatabasePeer()); 53 | Tags.DB_TYPE.set(span, "sql"); 54 | Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); 55 | 56 | /** 57 | * The first argument of all intercept method in `com.mysql.jdbc.StatementImpl` class is SQL, except the 58 | * `executeBatch` method that the jdbc plugin need to trace, because of this method argument size is zero. 59 | */ 60 | String sql = ""; 61 | if (allArguments.length > 0) { 62 | sql = (String) allArguments[0]; 63 | sql = SqlBodyUtil.limitSqlBodySize(sql); 64 | } 65 | Tags.DB_STATEMENT.set(span, sql); 66 | span.setComponent(connectInfo.getComponent()); 67 | 68 | SpanLayer.asDB(span); 69 | } 70 | } 71 | 72 | @Override 73 | public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, 74 | Class[] argumentsTypes, Object ret) throws Throwable { 75 | StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); 76 | if (cacheObject.getConnectionInfo() != null) { 77 | ContextManager.stopSpan(); 78 | } 79 | return ret; 80 | } 81 | 82 | @Override 83 | public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, 84 | Class[] argumentsTypes, Throwable t) { 85 | StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); 86 | if (cacheObject.getConnectionInfo() != null) { 87 | ContextManager.activeSpan().log(t); 88 | } 89 | } 90 | 91 | private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { 92 | return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /cyborg-agent/plugins/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | apm-sdk-plugin 23 | org.apache.skywalking 24 | 8.8.0 25 | 26 | 4.0.0 27 | 28 | cyborg-flow-plugin 29 | cyborg-flow-plugin 30 | pom 31 | 32 | 33 | UTF-8 34 | ${project.build.directory}/../../../cyborg-agent 35 | ${agent.package.dest.dir}/plugins 36 | 37 | 38 | 39 | mysql-5.x 40 | mysql-6.x 41 | mysql-8.x 42 | mysql-common 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /cyborg-agent/release.sh: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | CYBORG_AGENT="$(cd "$(dirname $0)"; pwd)" 18 | REPO=$1 19 | REPO_HEAD=$2 20 | DIST_FILE_PATH=$3 21 | 22 | cd $CYBORG_AGENT 23 | 24 | # build upstream 25 | git clone $REPO skywalking-java-agent 26 | cd skywalking-java-agent && git reset --hard $REPO_HEAD 27 | git submodule init && git submodule update 28 | SKIP_TEST=true make build 29 | 30 | # replace 31 | AGENT_HOME=$(cd skywalking-agent; pwd) 32 | cd $CYBORG_AGENT && make replace path=$AGENT_HOME 33 | 34 | # build tar 35 | cd $(dirname $AGENT_HOME) 36 | mv $(basename $AGENT_HOME) cyborg-agent 37 | tar vczf $DIST_FILE_PATH cyborg-agent 38 | 39 | # cleanup upstream 40 | rm -rf $CYBORG_AGENT/skywalking-java-agent -------------------------------------------------------------------------------- /cyborg-agent/replace-plugins.sh: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | if [ "$1" == "" ]; then 18 | echo "Please specify the root directory of skywalking-agent" 19 | exit 1 20 | fi 21 | 22 | CYBORG_AGENT_DIR="$(cd "$(dirname $0)"; pwd)" 23 | AGENT_DIR="$(cd "$1"; pwd)" 24 | AGENT_BACKUP_DIR="$AGENT_DIR/plugins-backup" 25 | 26 | function replace_plugin() { 27 | need_replace=$1 28 | new_plugins=$2 29 | 30 | # move old plugins to backup 31 | PLUGIN_BASE="$AGENT_DIR/$(dirname $need_replace)" 32 | find $PLUGIN_BASE -name "$(basename $need_replace)*" -print0 | 33 | while IFS= read -r -d '' file; do 34 | mv $file $AGENT_BACKUP_DIR 35 | echo "Move agent $(basename $file) to backup" 36 | done 37 | 38 | # copy new agents 39 | find $CYBORG_AGENT_DIR/$(dirname $new_plugins) -name "$(basename $new_plugins)*" -print0 | 40 | while IFS= read -r -d '' file; do 41 | cp $file $PLUGIN_BASE 42 | echo "Add new agent $(basename $file)" 43 | done 44 | } 45 | 46 | function append_auto_tag() { 47 | AGENT_CONF=$1 48 | if [ ! -f $AGENT_CONF ]; then 49 | echo "cannot append \"correlation.auto_tag_keys\", because agent.config file is not found" 50 | return 1 51 | fi 52 | 53 | contains_key=false 54 | while IFS='=' read -r key value 55 | do 56 | if [[ "$key" == "correlation.auto_tag_keys" ]]; then 57 | contains_key=true 58 | fi 59 | done < "$AGENT_CONF" 60 | if [[ "$contains_key" == false ]]; then 61 | echo "correlation.auto_tag_keys=cyborg-flow" >> $AGENT_CONF 62 | echo "append \"cyborg-flow\" to the correlation.auto_tag_keys." 63 | return 64 | fi 65 | 66 | auto_tag_value=$(sed -n 's/^correlation.auto_tag_keys*=*//p' $AGENT_CONF) 67 | auto_key_prefix="" 68 | auto_key_exists_value="" 69 | auto_key_suffix="" 70 | if [[ "$auto_tag_value" == *"\${"* ]]; then 71 | auto_key_prefix=$(echo $auto_tag_value | sed -r 's/^(\$\{.*\:).*\}$/\1/') 72 | auto_key_exists_value=$(echo $auto_tag_value | sed -r 's/^.*\:(.*)\}$/\1/') 73 | auto_key_suffix="}" 74 | else 75 | auto_key_exists_value=$auto_tag_value 76 | fi 77 | 78 | if [[ "$auto_key_exists_value" == *"cyborg-flow"* ]]; then 79 | echo "already contains the \"cyborg-flow\" auto tag key, won't be add again" 80 | return 81 | fi 82 | 83 | if [ "$auto_key_exists_value" != "" ]; then 84 | auto_key_exists_value="${auto_key_exists_value}," 85 | fi 86 | replace="${auto_key_prefix}${auto_key_exists_value}cyborg-flow${auto_key_suffix}" 87 | sed -i "s/^correlation.auto_tag_keys.*$/correlation.auto_tag_keys=$replace/g" $AGENT_CONF 88 | echo "append \"cyborg-flow\" to the correlation.auto_tag_keys." 89 | } 90 | 91 | echo "ready for replace agent path: $AGENT_DIR" 92 | echo "backup agent path: $AGENT_BACKUP_DIR" 93 | mkdir -p $AGENT_BACKUP_DIR 94 | 95 | # replace plugins 96 | replace_plugin plugins/apm-mysql- cyborg-agent/plugins/cyborg-flow-mysql- 97 | 98 | # append correlation.auto_tag_keys 99 | append_auto_tag $AGENT_DIR/config/agent.config -------------------------------------------------------------------------------- /cyborg-dashboard/Makefile: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # If the first argument is "run"... 17 | 18 | SHELL := /bin/bash -o pipefail 19 | 20 | CYBORG_DASHBOARD_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 21 | CYBORG_DASHBOARD_TAR := cyborg-dashboard.tar.gz 22 | CYBORG_UPSTREAM_REPO ?= https://github.com/apache/skywalking.git 23 | CYBORG_UPSTREAM_HEAD ?= 4284a57501eae6df49cb2703f31cc6f30d43367e 24 | REMOVE_UPSTREAM_TEMPLATE ?= true 25 | 26 | .PHONY: replace 27 | replace: 28 | bash ./replace-oap.sh $(path) $(REMOVE_UPSTREAM_TEMPLATE) 29 | 30 | .PHONY: release 31 | release: 32 | bash ./release.sh $(CYBORG_UPSTREAM_REPO) $(CYBORG_UPSTREAM_HEAD) $(CYBORG_DASHBOARD_ROOT)/$(CYBORG_DASHBOARD_TAR) 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /cyborg-dashboard/core.oal: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // normal server 20 | cyborg_flow_normal_service_resp_time = from(Service.latency).filter(tags not contain "cyborg-flow:true").longAvg(); 21 | cyborg_flow_normal_service_cpm = from(Service.*).filter(tags not contain "cyborg-flow:true").cpm(); 22 | cyborg_flow_normal_service_sla = from(Service.*).filter(tags not contain "cyborg-flow:true").percent(status == true); 23 | cyborg_flow_normal_service_percentile = from(Service.latency).filter(tags not contain "cyborg-flow:true").percentile(10); 24 | cyborg_flow_normal_service_heatmap = from(Service.latency).filter(tags not contain "cyborg-flow:true").histogram(100, 20); 25 | 26 | // cyborg flow server 27 | cyborg_flow_generate_service_resp_time = from(Service.latency).filter(tags contain "cyborg-flow:true").longAvg(); 28 | cyborg_flow_generate_service_cpm = from(Service.*).filter(tags contain "cyborg-flow:true").cpm(); 29 | cyborg_flow_generate_service_sla = from(Service.*).filter(tags contain "cyborg-flow:true").percent(status == true); 30 | cyborg_flow_generate_service_percentile = from(Service.latency).filter(tags contain "cyborg-flow:true").percentile(10); 31 | cyborg_flow_generate_service_heatmap = from(Service.latency).filter(tags contain "cyborg-flow:true").histogram(100, 20); -------------------------------------------------------------------------------- /cyborg-dashboard/release.sh: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | CYBORG_DASHBOARD="$(cd "$(dirname $0)"; pwd)" 18 | REPO=$1 19 | REPO_HEAD=$2 20 | DIST_FILE_PATH=$3 21 | 22 | cd $CYBORG_DASHBOARD 23 | 24 | # build upstream 25 | git clone $REPO skywalking-apm 26 | cd skywalking-apm && git reset --hard $REPO_HEAD 27 | make init && SKIP_TEST=true make build.all 28 | cd dist && tar -zxvf apache-skywalking-apm-bin.tar.gz 29 | 30 | # replace 31 | OAP_HOME=$(cd apache-skywalking-apm-bin; pwd) 32 | REMOVE_UPSTREAM_TEMPLATE=true make -C $CYBORG_DASHBOARD replace path=$OAP_HOME 33 | 34 | # build tar 35 | cd $(dirname $OAP_HOME) 36 | mv $(basename $OAP_HOME) cyborg-dashboard 37 | tar vczf $DIST_FILE_PATH cyborg-dashboard 38 | 39 | # cleanup upstream 40 | rm -rf $CYBORG_DASHBOARD/skywalking-apm -------------------------------------------------------------------------------- /cyborg-dashboard/replace-oap.sh: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | if [ "$1" == "" ]; then 18 | echo "Please specify the root directory of SkyWalking APM" 19 | exit 1 20 | fi 21 | 22 | CYBORG_DASHBOARD="$(cd "$(dirname $0)"; pwd)" 23 | APM_DIR="$(cd "$1"; pwd)" 24 | REMOVE_UPSTREAM_CONTENT=$2 25 | 26 | if [ ! -d "$APM_DIR/config/ui-initialized-templates" ] || [ ! -d "$APM_DIR/config/oal" ]; then 27 | echo "Please make sure the SkyWalking APM directory is correct: $APM_DIR" 28 | return 1 29 | fi 30 | 31 | if [[ "$REMOVE_UPSTREAM_CONTENT" == "true" ]]; then 32 | rm -rf $APM_DIR/config/ui-initialized-templates/* 33 | fi 34 | 35 | cp $CYBORG_DASHBOARD/ui-template.yml $APM_DIR/config/ui-initialized-templates/cyborg-flow.yml 36 | echo "Copy UI template" 37 | 38 | if [ -f "$APM_DIR/config/oal/core.oal" ] && [[ "$REMOVE_UPSTREAM_CONTENT" != "true" ]]; then 39 | echo "Detect official core.oal, make it to core.oal_backup" 40 | mv "$APM_DIR/config/oal/core.oal" "$APM_DIR/config/oal/core.oal_backup" 41 | fi 42 | 43 | cp $CYBORG_DASHBOARD/core.oal $APM_DIR/config/oal/core.oal 44 | echo "Copy OAL" 45 | -------------------------------------------------------------------------------- /cyborg-dashboard/ui-template.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # UI templates initialized file includes the default template when the SkyWalking OAP starts up at the first time. 17 | # 18 | # Also, SkyWalking would detect the existing templates in the database, once they are missing, all templates in this file 19 | # could be added automatically. 20 | 21 | templates: 22 | - name: Cyborg Flow 23 | type: "DASHBOARD" 24 | configuration: |- 25 | [ 26 | { 27 | "name": "Cyborg Flow", 28 | "type": "service", 29 | "children": [{ 30 | "name": "service", 31 | "children": [{ 32 | "width": 3, 33 | "title": "Normal CPM", 34 | "height": 350, 35 | "entityType": "Service", 36 | "independentSelector": false, 37 | "metricType": "REGULAR_VALUE", 38 | "metricName": "cyborg_flow_normal_service_cpm", 39 | "queryMetricType": "readMetricsValues", 40 | "chartType": "ChartLine" 41 | }, { 42 | "width": 3, 43 | "title": "Normal SLA", 44 | "height": 350, 45 | "entityType": "Service", 46 | "independentSelector": false, 47 | "metricType": "REGULAR_VALUE", 48 | "metricName": "cyborg_flow_normal_service_sla", 49 | "queryMetricType": "readMetricsValues", 50 | "chartType": "ChartLine", 51 | "aggregation": "/", 52 | "aggregationNum": "100" 53 | }, { 54 | "width": 3, 55 | "title": "Cyborg CPM", 56 | "height": 350, 57 | "entityType": "Service", 58 | "independentSelector": false, 59 | "metricType": "REGULAR_VALUE", 60 | "metricName": "cyborg_flow_generate_service_cpm", 61 | "queryMetricType": "readMetricsValues", 62 | "chartType": "ChartLine" 63 | }, { 64 | "width": 3, 65 | "title": "Cyborg SLA", 66 | "height": 350, 67 | "entityType": "Service", 68 | "independentSelector": false, 69 | "metricType": "REGULAR_VALUE", 70 | "metricName": "cyborg_flow_generate_service_sla", 71 | "queryMetricType": "readMetricsValues", 72 | "chartType": "ChartLine", 73 | "aggregation": "/", 74 | "aggregationNum": "100" 75 | }, { 76 | "width": 3, 77 | "title": "Normal Response Latency", 78 | "height": 350, 79 | "entityType": "Service", 80 | "independentSelector": false, 81 | "metricType": "LABELED_VALUE", 82 | "metricName": "cyborg_flow_normal_service_percentile", 83 | "queryMetricType": "readLabeledMetricsValues", 84 | "chartType": "ChartLine", 85 | "metricLabels": "P50, P75, P90, P95, P99", 86 | "labelsIndex": "0,1,2,3,4" 87 | }, { 88 | "width": 3, 89 | "title": "Normal Heatmap", 90 | "height": 350, 91 | "entityType": "Service", 92 | "independentSelector": false, 93 | "metricType": "HEATMAP", 94 | "metricName": "cyborg_flow_normal_service_heatmap", 95 | "queryMetricType": "readHeatMap", 96 | "chartType": "ChartHeatmap" 97 | }, { 98 | "width": 3, 99 | "title": "Cyborg Response Latency", 100 | "height": 350, 101 | "entityType": "Service", 102 | "independentSelector": false, 103 | "metricType": "LABELED_VALUE", 104 | "metricName": "cyborg_flow_generate_service_percentile", 105 | "queryMetricType": "readLabeledMetricsValues", 106 | "chartType": "ChartLine", 107 | "metricLabels": "P50, P75, P90, P95, P99", 108 | "labelsIndex": "0,1,2,3,4" 109 | }, { 110 | "width": 3, 111 | "title": "Cyborg Heatmap", 112 | "height": 350, 113 | "entityType": "Service", 114 | "independentSelector": false, 115 | "metricType": "HEATMAP", 116 | "metricName": "cyborg_flow_generate_service_heatmap", 117 | "queryMetricType": "readHeatMap", 118 | "chartType": "ChartHeatmap" 119 | }] 120 | }] 121 | } 122 | ] 123 | # Activated as the DASHBOARD type, makes this templates added into the UI page automatically. 124 | # False means providing a basic template, user needs to add it manually. 125 | activated: true 126 | # True means wouldn't show up on the dashboard. Only keeps the definition in the storage. 127 | disabled: false -------------------------------------------------------------------------------- /cyborg-database-shadow/README.md: -------------------------------------------------------------------------------- 1 | # cyborg-database-shadow 2 | 3 | ## Quick Start 4 | 5 | #### Download&Install 6 | 7 | Please head to the [releases page](https://www.apache.org/dyn/closer.cgi/shardingsphere/5.0.0/apache-shardingsphere-5.0.0-shardingsphere-proxy-bin.tar.gz) to download 5.0.0 release of Apache ShardingSphere. 8 | 9 | #### Configuration 10 | 11 | The `conf` directory contains the template configuration files by default `config-shadow.yaml` and `server.yaml`. 12 | 13 | If the template configuration files by default meet your business needs, replace the corresponding configuration file. 14 | 15 | Please refer to [ShardingSphere-Proxy Configuration Manual](https://shardingsphere.apache.org/document/5.0.0/en/user-manual/shardingsphere-proxy/configuration/), if you want to learn more. 16 | 17 | #### Dependencies 18 | 19 | If the backend database is PostgreSQL, there's no need for additional dependencies. 20 | 21 | If the backend database is MySQL, please download [mysql-connector-java-5.1.47.jar](https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar) or [mysql-connector-java-8.0.11.jar](https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.11/mysql-connector-java-8.0.11.jar) and put it into `%SHARDINGSPHERE_PROXY_HOME%/lib` directory. 22 | 23 | #### Start Server 24 | 25 | ```shell 26 | sh %SHARDINGSPHERE_PROXY_HOME%/bin/start.sh 27 | ``` 28 | > Default port is 3307. 29 | 30 | Please refer to [ShardingSphere-Proxy Start Server](https://shardingsphere.apache.org/document/5.0.0/en/quick-start/shardingsphere-proxy-quick-start/#3-start-server), if you want learn more. 31 | 32 | ## Use Example 33 | 34 | Take the INSERT statement as an example. 35 | 36 | ```sql 37 | INSERT INTO table (column,…) VALUES (value,…); 38 | ``` 39 | will be executed to the production DB. 40 | 41 | ```sql 42 | INSERT INTO table (column,…) VALUES (value,…)/*cyborg-flow:true*/; 43 | ``` 44 | will be executed to the shadow DB. 45 | 46 | Please refer to [ShardingSphere-shadow](https://shardingsphere.apache.org/document/5.0.0/en/reference/shadow/), if you want to learn more. 47 | 48 | ## Use Norms 49 | 50 | SQL support,please refer to [ShardingSphere-shadow use-norms](https://shardingsphere.apache.org/document/5.0.0/en/features/shadow/use-norms/) 51 | -------------------------------------------------------------------------------- /cyborg-database-shadow/README_ZH.md: -------------------------------------------------------------------------------- 1 | # cyborg-database-shadow 2 | 3 | ## 快速开始 4 | 5 | #### 下载&安装 6 | 7 | 请前往 [发布页面](https://www.apache.org/dyn/closer.cgi/shardingsphere/5.0.0/apache-shardingsphere-5.0.0-shardingsphere-proxy-bin.tar.gz) 下载 Apache ShardingSphere 5.0.0 版本。 8 | 9 | #### 配置 10 | 11 | `conf` 目录包含默认模板配置文件 `config-shadow.yaml` 和 `server.yaml`。 12 | 13 | 如果默认模板配置文件满足您的业务需求,请更换相应的配置文件。 14 | 15 | 如果需要了解更多的信息,请参阅 [ShardingSphere-Proxy Configuration Manual](https://shardingsphere.apache.org/document/5.0.0/cn/user-manual/shardingsphere-proxy/configuration/) 16 | 17 | #### 依赖 18 | 19 | If the backend database is PostgreSQL, there's no need for additional dependencies. 20 | 21 | If the backend database is MySQL, please download [mysql-connector-java-5.1.47.jar](https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar) or [mysql-connector-java-8.0.11.jar](https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.11/mysql-connector-java-8.0.11.jar) and put it into `%SHARDINGSPHERE_PROXY_HOME%/lib` directory. 22 | 23 | #### 启动服务 24 | 25 | ```shell 26 | sh %SHARDINGSPHERE_PROXY_HOME%/bin/start.sh 27 | ``` 28 | > 默认启动端口为: `3307` 29 | 30 | 如果需要了解更多的信息,请参阅 [ShardingSphere-Proxy Start Server](https://shardingsphere.apache.org/document/5.0.0/cn/quick-start/shardingsphere-proxy-quick-start/#3-start-server) 31 | 32 | ## 使用样例 33 | 34 | 以 `INSERT` 语句为例, 35 | 36 | ```sql 37 | INSERT INTO table (column,…) VALUES (value,…); 38 | ``` 39 | 会在生产库执行. 40 | 41 | ```sql 42 | INSERT INTO table (column,…) VALUES (value,…)/*cyborg-flow:true*/; 43 | ``` 44 | 会在影子库执行. 45 | 46 | 如果需要了解更多的信息,请参阅 [ShardingSphere-shadow](https://shardingsphere.apache.org/document/5.0.0/cn/reference/shadow/) 47 | 48 | ## 使用规范 49 | 50 | SQL 支持情况,请参阅 [ShardingSphere-shadow 使用规范](https://shardingsphere.apache.org/document/5.0.0/cn/features/shadow/use-norms/) 51 | -------------------------------------------------------------------------------- /cyborg-database-shadow/conf/config-shadow.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | ###################################################################################################### 19 | # 20 | # Here you can configure the rules for the proxy. 21 | # This example is configuration of shadow rule. 22 | # 23 | ###################################################################################################### 24 | # 25 | #schemaName: shadow_db 26 | # 27 | #dataSources: 28 | # ds: 29 | # url: jdbc:postgresql://10.12.3.114:5432/demo_ds_0?serverTimezone=UTC&useSSL=false 30 | # username: postgres 31 | # password: postgres 32 | # connectionTimeoutMilliseconds: 30000 33 | # idleTimeoutMilliseconds: 60000 34 | # maxLifetimeMilliseconds: 1800000 35 | # maxPoolSize: 50 36 | # minPoolSize: 1 37 | # shadow_ds: 38 | # url: jdbc:postgresql://10.12.3.114:5432/demo_ds_1?serverTimezone=UTC&useSSL=false 39 | # username: postgres 40 | # password: postgres 41 | # connectionTimeoutMilliseconds: 30000 42 | # idleTimeoutMilliseconds: 60000 43 | # maxLifetimeMilliseconds: 1800000 44 | # maxPoolSize: 50 45 | # minPoolSize: 1 46 | # 47 | #rules: 48 | #- !SHADOW 49 | # column: shadow 50 | # sourceDataSourceNames: 51 | # - ds 52 | # shadowDataSourceNames: 53 | # - shadow_ds 54 | # 55 | # 56 | ###################################################################################################### 57 | # 58 | # If you want to connect to MySQL, you should manually copy MySQL driver to lib directory. 59 | # 60 | ###################################################################################################### 61 | 62 | schemaName: cyborg-database-shadow 63 | 64 | dataSources: 65 | # Production DB configuration, modified according to actual needs. 66 | ds: 67 | url: jdbc:mysql://127.0.0.1:3306/ds?serverTimezone=UTC&useSSL=false 68 | username: root 69 | password: 70 | connectionTimeoutMilliseconds: 30000 71 | idleTimeoutMilliseconds: 60000 72 | maxLifetimeMilliseconds: 1800000 73 | maxPoolSize: 50 74 | minPoolSize: 1 75 | # Shadow DB configuration, modified according to actual needs. 76 | ds_shadow: 77 | url: jdbc:mysql://127.0.0.1:3306/ds_shadow?serverTimezone=UTC&useSSL=false 78 | username: root 79 | password: 80 | connectionTimeoutMilliseconds: 30000 81 | idleTimeoutMilliseconds: 60000 82 | maxLifetimeMilliseconds: 1800000 83 | maxPoolSize: 50 84 | minPoolSize: 1 85 | 86 | rules: 87 | - !SHADOW 88 | enable: true 89 | dataSources: 90 | shadowDataSource: 91 | sourceDataSourceName: ds 92 | shadowDataSourceName: ds_shadow 93 | defaultShadowAlgorithmName: simple-note-algorithm 94 | shadowAlgorithms: 95 | simple-note-algorithm: 96 | type: SIMPLE_NOTE 97 | props: 98 | cyborg-flow: true 99 | -------------------------------------------------------------------------------- /cyborg-database-shadow/conf/server.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | ###################################################################################################### 19 | # 20 | # If you want to configure governance, authorization and proxy properties, please refer to this file. 21 | # 22 | ###################################################################################################### 23 | 24 | #scaling: 25 | # blockQueueSize: 10000 26 | # workerThread: 40 27 | # clusterAutoSwitchAlgorithm: 28 | # type: IDLE 29 | # props: 30 | # incremental-task-idle-minute-threshold: 30 31 | # dataConsistencyCheckAlgorithm: 32 | # type: DEFAULT 33 | # 34 | #mode: 35 | # type: Cluster 36 | # repository: 37 | # type: ZooKeeper 38 | # props: 39 | # namespace: governance_ds 40 | # server-lists: localhost:2181 41 | # retryIntervalMilliseconds: 500 42 | # timeToLiveSeconds: 60 43 | # maxRetries: 3 44 | # operationTimeoutMilliseconds: 500 45 | # overwrite: false 46 | # 47 | rules: 48 | - !AUTHORITY 49 | users: 50 | - root@%:root 51 | - sharding@:sharding 52 | provider: 53 | type: NATIVE 54 | 55 | props: 56 | max-connections-size-per-query: 1 57 | executor-size: 16 # Infinite by default. 58 | proxy-frontend-flush-threshold: 128 # The default value is 128. 59 | proxy-opentracing-enabled: false 60 | proxy-hint-enabled: false 61 | sql-show: false 62 | check-table-metadata-enabled: false 63 | lock-wait-timeout-milliseconds: 50000 # The maximum time to wait for a lock 64 | show-process-list-enabled: false 65 | # Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy. 66 | # The default value is -1, which means set the minimum value for different JDBC drivers. 67 | proxy-backend-query-fetch-size: -1 68 | check-duplicate-table-enabled: false 69 | sql-comment-parse-enabled: true 70 | proxy-frontend-executor-size: 200 # Proxy frontend executor size. The default value is 0, which means let Netty decide. 71 | # Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution 72 | # if client connections are more than proxy-frontend-netty-executor-size, especially executing slow SQL. 73 | proxy-backend-executor-suitable: OLAP 74 | -------------------------------------------------------------------------------- /cyborg-flow-gateway/README.md: -------------------------------------------------------------------------------- 1 | # cyborg-database-gateway 2 | 3 | ## Quick Start (base on CentOS 7) 4 | 5 | #### Install the RPM repositories for OpenResty and Apache APISIX 6 | 7 | ```shell 8 | sudo yum install -y https://repos.apiseven.com/packages/centos/apache-apisix-repo-1.0-1.noarch.rpm 9 | ``` 10 | 11 | #### Install Apache APISIX and all dependencies via RPM package 12 | 13 | ```shell 14 | sudo yum install -y https://repos.apiseven.com/packages/centos/7/x86_64/apisix-2.10.1-0.el7.x86_64.rpm 15 | ``` 16 | 17 | #### Configuration 18 | 19 | The `conf` directory contains the Apache APISIX configuration file `config.yaml` and the routing rules for Stand-alone mode `apisix.yaml`. 20 | 21 | ##### Custom Configuration 22 | 23 | - overwrite the `/usr/local/apisix/conf/config.yaml` file with this project file `cyborg-flow-gateway/conf/config.yaml`. 24 | - copy the project file `cyborg-flow-gateway/conf/apisix.yaml` to the `/usr/local/apisix/conf/`. 25 | 26 | ##### Custom Configuration Description 27 | 28 | 1. `config_center: yaml` in `cyborg-flow-gateway/conf/config.yaml` means that Apache APISIX is in Stand-alone mode and reads routing rules from `apisix.yaml`. For more information, see [Stand-alone mode](https://github.com/apache/apisix/blob/master/docs/en/latest/stand-alone.md). 29 | 30 | ```yaml 31 | plugins: 32 | - proxy-rewrite 33 | - skywalking 34 | plugin_attr: 35 | skywalking: 36 | service_name: APISIX 37 | service_instance_name: "APISIX Instance Name" 38 | endpoint_addr: http://${skywalking_endpoint}:12800 # please replace with the address of your SkyWalking Endpoint 39 | ``` 40 | 41 | `plugins` option is uesd to configure the list of enabled plugins. `plugin_attr` option is used to configure the properties of the plugin. For more information about the SkyWalking plugin, see [skywalking](https://github.com/apache/apisix/blob/master/docs/en/latest/plugins/skywalking.md). 42 | 43 | 44 | 2. in `cyborg-flow-gateway/conf/apisix.yaml` 45 | 46 | ```yaml 47 | plugins: 48 | proxy-rewrite: 49 | headers: 50 | sw8-correlation: Y3lib3JnLWZsb3c=:dHJ1ZQ== 51 | ``` 52 | means that use `proxy-rewrite` plugin in Apache APISIX to inject `sw8-correlation: Y3lib3JnLWZsb3c=:dHJ1ZQ==` into the headers of the request. `Y3lib3JnLWZsb3c=` is the Base 64 encoding format for `cyborg-flow`, and `dHJ1ZQ==` is the Base 64 encoding for `true`. 53 | For more information, see [proxy-rewrite](https://github.com/apache/apisix/blob/master/docs/en/latest/plugins/proxy-rewrite.md). 54 | 55 | `skywalking` means that the SkyWalking plugin is enabled on this route, `sample_ratio` is the sample rate of the SkyWalking plugin. 56 | 57 | #### Start Server 58 | 59 | ```shell 60 | apisix start 61 | ``` 62 | 63 | > Default port is 9080. 64 | 65 | ## Test 66 | 67 | 1. Send a request to Apache APISIX to trigger the route rule and test if it works: 68 | 69 | ```shell 70 | $ curl 127.0.0.1:9080/get 71 | { 72 | "args": {}, 73 | "headers": { 74 | "Accept": "*/*", 75 | "Host": "127.0.0.1", 76 | "Sw8-Correlation": "Y3lib3JnLWZsb3c=:dHJ1ZQ==", 77 | "User-Agent": "curl/7.29.0", 78 | "X-Amzn-Trace-Id": "Root=1-61822115-4c57f6ee321faa2d49cc5a61", 79 | "X-Forwarded-Host": "127.0.0.1" 80 | }, 81 | "origin": "127.0.0.1, 180.118.190.54", 82 | "url": "http://127.0.0.1/get" 83 | } 84 | ``` 85 | 86 | From the response of `httpbin.org` shows that APISIX successfully injected `"Sw8-Correlation": "Y3lib3JnLWZsb3c=:dHJ1ZQ=="` into the headers of the request. 87 | 88 | 2. Use the command line tool `swctl` in SkyWalking to check the registration status of Apache APISIX with SkyWalking: 89 | 90 | ```shell 91 | $ ./bin/swctl service ls 92 | [{"id":"QVBJU0lY.1","name":"APISIX","group":""}] 93 | ``` 94 | 95 | Apache APISIX is successfully registered on SkyWalking. 96 | -------------------------------------------------------------------------------- /cyborg-flow-gateway/README_ZH.md: -------------------------------------------------------------------------------- 1 | # cyborg-flow-gateway 2 | 3 | ## 快速开始(基于 CentOS 7) 4 | 5 | #### 安装 OpenResty 和 Apache APISIX 的 RPM 仓库 6 | 7 | ```shell 8 | sudo yum install -y https://repos.apiseven.com/packages/centos/apache-apisix-repo-1.0-1.noarch.rpm 9 | ``` 10 | 11 | #### 通过 RPM 包安装 Apache APISIX 及所有依赖 12 | 13 | ```shell 14 | sudo yum install -y https://repos.apiseven.com/packages/centos/7/x86_64/apisix-2.10.1-0.el7.x86_64.rpm 15 | ``` 16 | 17 | #### 配置 18 | 19 | `conf` 目录包含 Apache APISIX 的配置文件 `config.yaml` 和 Stand-alone 模式的路由规则 `apisix.yaml`。 20 | 21 | ##### 自定义配置 22 | 23 | - 用本项目文件 `cyborg-flow-gateway/conf/config.yaml` 文件覆盖 `/usr/local/apisix/conf/config.yaml`; 24 | - 用本项目文件 `cyborg-flow-gateway/conf/apisix.yaml` 复制到 `/usr/local/apisix/conf/` 路径下; 25 | 26 | ##### 自定义配置说明 27 | 28 | 1. `cyborg-flow-gateway/conf/config.yaml` 中的 `config_center: yaml` 表示 Apache APISIX 启用 Stand-alone 模式,从 `apisix.yaml` 读取路由规则。如果需要了解更多的信息,请参阅 [Stand-alone 模式](https://github.com/apache/apisix/blob/master/docs/zh/latest/stand-alone.md) 。 29 | 30 | ```yaml 31 | plugins: 32 | - proxy-rewrite 33 | - skywalking 34 | plugin_attr: 35 | skywalking: 36 | service_name: APISIX 37 | service_instance_name: "APISIX Instance Name" 38 | endpoint_addr: http://${skywalking_endpoint}:12800 # 请替换为您的 SkyWalking Endpoint 的地址 39 | ``` 40 | 41 | `plugins` 选项用于配置启用的插件列表。`plugin_attr` 选项用于配置插件的属性。如果需要了解更多 SkyWalking 插件的属性,请参阅 [skywalking](https://github.com/apache/apisix/blob/master/docs/zh/latest/plugins/skywalking.md) 。 42 | 43 | 44 | 2. `cyborg-flow-gateway/conf/apisix.yaml` 中 45 | 46 | ```yaml 47 | plugins: 48 | proxy-rewrite: 49 | headers: 50 | sw8-correlation: Y3lib3JnLWZsb3c=:dHJ1ZQ== 51 | skywalking: 52 | sample_ratio: 1 53 | ``` 54 | 表示在 Apache APISIX 中添加 `proxy-rewrite` 插件,利用该插件向请求的 headers 中注入 `sw8-correlation: Y3lib3JnLWZsb3c=:dHJ1ZQ==`。`Y3lib3JnLWZsb3c=` 是 `cyborg-flow` 的 Base 64 编码格式,`dHJ1ZQ==` 是 `true` 的 Base 64 编码。 55 | 如果需要了解更多的信息,请参阅 [proxy-rewrite](https://github.com/apache/apisix/blob/master/docs/zh/latest/plugins/proxy-rewrite.md) 。 56 | 57 | `skywalking` 表示在该 route 上开启 SkyWalking 插件,`sample_ratio` 表示 SkyWalking 插件的采样率。 58 | 59 | #### 启动服务 60 | 61 | ```shell 62 | apisix start 63 | ``` 64 | 65 | > 默认启动端口为: `9080` 66 | 67 | ## 测试 68 | 69 | 1. 发送请求到 Apache APISIX,触发路由规则,测试是否正常: 70 | 71 | ```shell 72 | $ curl 127.0.0.1:9080/get 73 | { 74 | "args": {}, 75 | "headers": { 76 | "Accept": "*/*", 77 | "Host": "127.0.0.1", 78 | "Sw8-Correlation": "Y3lib3JnLWZsb3c=:dHJ1ZQ==", 79 | "User-Agent": "curl/7.29.0", 80 | "X-Amzn-Trace-Id": "Root=1-61822115-4c57f6ee321faa2d49cc5a61", 81 | "X-Forwarded-Host": "127.0.0.1" 82 | }, 83 | "origin": "127.0.0.1, 180.118.190.54", 84 | "url": "http://127.0.0.1/get" 85 | } 86 | ``` 87 | 88 | 从 `httpbin.org` 返回的响应可以看到,Apache APISIX 成功向请求的 headers 中注入了 `"Sw8-Correlation": "Y3lib3JnLWZsb3c=:dHJ1ZQ=="`。 89 | 90 | 91 | 2. 在 SkyWalking 中用命令行工具 `swctl` 查看 Apache APISIX 在 SkyWalking 注册状态: 92 | 93 | ```shell 94 | $ ./bin/swctl service ls 95 | [{"id":"QVBJU0lY.1","name":"APISIX","group":""}] 96 | ``` 97 | 98 | 可以看到 Apache APISIX 在 SkyWalking 注册成功。 99 | -------------------------------------------------------------------------------- /cyborg-flow-gateway/conf/apisix.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # example 18 | routes: 19 | - 20 | uri: /get 21 | plugins: 22 | proxy-rewrite: 23 | headers: 24 | sw8-correlation: Y3lib3JnLWZsb3c=:dHJ1ZQ== 25 | skywalking: 26 | sample_ratio: 1 27 | upstream: 28 | nodes: 29 | "httpbin.org:80": 1 30 | type: roundrobin 31 | #END 32 | -------------------------------------------------------------------------------- /cyborg-flow-gateway/conf/config.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # If you want to set the specified configuration value, you can set the new 18 | # in this file. For example if you want to specify the etcd address: 19 | # 20 | # etcd: 21 | # host: 22 | # - http://127.0.0.1:2379 23 | # 24 | # To configure via environment variables, you can use `${{VAR}}` syntax. For instance: 25 | # 26 | # etcd: 27 | # host: 28 | # - http://${{ETCD_HOST}}:2379 29 | # 30 | # And then run `export ETCD_HOST=$your_host` before `make init`. 31 | # 32 | # If the configured environment variable can't be found, an error will be thrown. 33 | apisix: 34 | config_center: yaml 35 | enable_admin: false 36 | 37 | plugins: 38 | - proxy-rewrite 39 | - skywalking 40 | 41 | plugin_attr: 42 | skywalking: 43 | service_name: APISIX 44 | service_instance_name: "APISIX Instance Name" 45 | endpoint_addr: http://${skywalking_endpoint}:12800 46 | --------------------------------------------------------------------------------