Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1.2 zhile #454

Open
wants to merge 18 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

28 changes: 15 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ name: build

on:
push:
branches: [ 3.x ]
branches: [ master ]
pull_request:
branches: [ 3.x ]
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn clean install -DskipTests -B -V
&& sh ./check_format.sh
&& mvn clean test
- name: Codecov
uses: codecov/codecov-action@v1
- uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn clean install -DskipTests -B -V
&& sh ./check_format.sh
&& mvn clean test
- name: Codecov
uses: codecov/codecov-action@v1
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ nb-configuration.xml
coverage-report
logs
*.log
pom.xml.versionsBackup

pom.xml.versionsBackup
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## SOFATracer

[![Build Status](https://github.com/sofastack/sofa-tracer/workflows/build/badge.svg?branch=3.x)](https://github.com/sofastack/sofa-tracer/workflows/build/badge.svg?branch=3.x)
[![Coverage Status](https://coveralls.io/repos/github/alipay/sofa-tracer/badge.svg?branch=master)](https://coveralls.io/github/alipay/sofa-tracer?branch=master)
[![Build Status](https://github.com/sofastack/sofa-tracer/workflows/build/badge.svg?branch=master)](https://github.com/sofastack/sofa-tracer/workflows/build/badge.svg?branch=master)
[![Coverage Status](https://codecov.io/gh/sofastack/sofa-tracer/branch/master/graph/badge.svg)](https://codecov.io/gh/sofastack/sofa-tracer/branch/master)
![license](https://img.shields.io/badge/license-Apache--2.0-green.svg)
[![Maven](https://img.shields.io/github/release/alipay/sofa-tracer.svg)](https://github.com/alipay/sofa-tracer/releases)

Expand Down Expand Up @@ -43,7 +43,7 @@ SOFATracer 可以将链路跟踪数据远程上报到开源产品 [Zipkin](https

## 三、快速开始

请查看文档中的[快速开始](http://www.sofastack.tech/sofa-tracer/docs/QuickStart)来了解如何快速上手使用 SOFATracer。
请查看文档中的[快速开始](https://www.sofastack.tech/projects/sofa-tracer/component-access/)来了解如何快速上手使用 SOFATracer。

## 四、如何贡献

Expand Down
31 changes: 0 additions & 31 deletions appveyor.yml

This file was deleted.

2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "pom.xml"
43 changes: 22 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>tracer-all-parent</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<packaging>pom</packaging>
<name>tracer-all-parent</name>
<description>Alipay SOFATracer Log Implemented by OpenTracing</description>
Expand Down Expand Up @@ -51,8 +51,6 @@
<main.user.dir>${user.dir}</main.user.dir>
<maven.staging.plugin>1.6.7</maven.staging.plugin>
<maven.gpg.pluign>1.5</maven.gpg.pluign>
<coveralls.maven.plugin>3.1.0</coveralls.maven.plugin>
<cobertura.maven.plugin>2.6</cobertura.maven.plugin>
</properties>

<licenses>
Expand Down Expand Up @@ -275,7 +273,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -404,26 +402,29 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${coveralls.maven.plugin}</version>
<configuration>
<sourceEncoding>${project.encoding}</sourceEncoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.maven.plugin}</version>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<encoding>${project.encoding}</encoding>
<aggregate>true</aggregate>
<formats>
<format>xml</format>
<format>html</format>
</formats>
<skip>false</skip>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
2 changes: 1 addition & 1 deletion sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.1.0</version>
<version>3.1.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.RowId;
import java.sql.SQLXML;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
package com.alipay.sofa.tracer.plugins.datasource;

import com.alipay.common.tracer.core.utils.StringUtils;
import com.alipay.sofa.tracer.plugins.datasource.tracer.*;
import com.alipay.sofa.tracer.plugins.datasource.tracer.ConnectionTraceInterceptor;
import com.alipay.sofa.tracer.plugins.datasource.tracer.DataSourceClientTracer;
import com.alipay.sofa.tracer.plugins.datasource.tracer.DataSourceTracerKeys;
import com.alipay.sofa.tracer.plugins.datasource.tracer.Endpoint;
import com.alipay.sofa.tracer.plugins.datasource.tracer.KeyValueAnnotation;
import com.alipay.sofa.tracer.plugins.datasource.tracer.StatementTracerInterceptor;
import com.alipay.sofa.tracer.plugins.datasource.utils.DataSourceUtils;

import javax.sql.DataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.alipay.sofa.tracer.plugins.datasource.tracer;

import com.alipay.sofa.tracer.plugins.datasource.Interceptor;

import java.util.List;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.alipay.common.tracer.core.span.CommonSpanTags;
import com.alipay.common.tracer.core.span.SofaTracerSpan;
import com.alipay.common.tracer.core.utils.TracerUtils;

import java.util.Map;

/**
Expand All @@ -45,7 +46,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
tagsWithStr.get(DataSourceTracerKeys.DATABASE_NAME));
statKey.addKey(DataSourceTracerKeys.SQL, tagsWithStr.get(DataSourceTracerKeys.SQL));
//result
String result = SofaTracerConstant.RESULT_CODE_SUCCESS.equals(tagsWithStr
String result = SofaTracerConstant.RESULT_SUCCESS.equals(tagsWithStr
.get(CommonSpanTags.RESULT_CODE)) ? SofaTracerConstant.STAT_FLAG_SUCCESS
: SofaTracerConstant.STAT_FLAG_FAILS;
statKey.setResult(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
tagsWithStr.get(DataSourceTracerKeys.DATABASE_NAME),
tagsWithStr.get(DataSourceTracerKeys.SQL) }));
//result
String resultCode = SofaTracerConstant.RESULT_CODE_SUCCESS.equals(tagsWithStr
String resultCode = SofaTracerConstant.RESULT_SUCCESS.equals(tagsWithStr
.get(CommonSpanTags.RESULT_CODE)) ? SofaTracerConstant.STAT_FLAG_SUCCESS
: SofaTracerConstant.STAT_FLAG_FAILS;
statKey.setResult(resultCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
*/
package com.alipay.sofa.tracer.plugins.datasource.utils;

import com.alipay.common.tracer.core.appender.self.SelfLog;
import com.alipay.common.tracer.core.utils.AssertUtils;
import com.alipay.common.tracer.core.utils.StringUtils;
import com.alipay.sofa.common.code.LogCode2Description;
import com.alipay.sofa.tracer.plugins.datasource.tracer.Endpoint;

import java.lang.reflect.Method;
Expand All @@ -26,6 +28,8 @@
import java.util.Collections;
import java.util.List;

import static com.alipay.common.tracer.core.constants.SofaTracerConstant.SPACE_ID;

/**
* @author shusong.yss
* @author qilong.zql
Expand All @@ -52,6 +56,8 @@ public class DataSourceUtils {

public static final String ORACLE_PREFIX_THIN = "jdbc:oracle:thin:";

public static final String POSTGRE_PREFIX_THIN = "jdbc:postgresql://";

public static final int ORACLE_DEFAULT_PORT = 1521;

public static boolean isDruidDataSource(Object dataSource) {
Expand Down Expand Up @@ -172,11 +178,23 @@ public static boolean isTargetDataSource(String className, Object dataSource) {

public static List<Endpoint> getEndpointsFromConnectionURL(final String connectionURL) {
String currentUri = StringUtils.EMPTY_STRING;
List<Endpoint> endpoints = null;
if (StringUtils.isNotBlank(connectionURL) && connectionURL.startsWith(ORACLE_PREFIX_THIN)) {
currentUri = connectionURL.substring(ORACLE_PREFIX_THIN.length());
// parse endpoints by tns name.
endpoints = parseEndpointByTnsName(currentUri);
List<Endpoint> endpoints = Collections.emptyList();
try {
//首先jdbc:oracle:thin: 特殊解析
if (StringUtils.isNotBlank(connectionURL)
&& connectionURL.startsWith(ORACLE_PREFIX_THIN)) {

currentUri = connectionURL.substring(ORACLE_PREFIX_THIN.length());
// parse endpoints by tns name.
endpoints = parseEndpointByTnsName(currentUri);
} else if (StringUtils.isNotBlank(connectionURL)
&& connectionURL.startsWith(POSTGRE_PREFIX_THIN)
&& connectionURL.contains(",")) {
//pg数据库 读写分离的配资
currentUri = connectionURL.substring(POSTGRE_PREFIX_THIN.length());
endpoints = parseEndpointByPgMulti(currentUri);
}
//普通解析 兜底
if (endpoints == null || endpoints.size() == 0 || null == endpoints.get(0)
|| StringUtils.isBlank(endpoints.get(0).getHost())) {
// easy tns or others db url be resolve. it's a single endpoint.
Expand All @@ -186,9 +204,30 @@ public static List<Endpoint> getEndpointsFromConnectionURL(final String connecti
}
endpoints = Collections.singletonList(singleEndpoint);
}
return endpoints;
} catch (Exception e) {
//链接配置样式多,捕获异常,不影响启动
SelfLog.error(LogCode2Description.convert(SPACE_ID, "01-00015"), e);
}
return Collections.emptyList();
return endpoints;
}

private static List<Endpoint> parseEndpointByPgMulti(String currentUri) {
List<Endpoint> endpoints = new ArrayList<>();
String[] urls = currentUri.split(",");
for (String url : urls) {
int hostEnd = url.indexOf(":");
String host = url.substring(0, hostEnd);
int portEnd = url.indexOf('/');
if (portEnd == -1) {
portEnd = url.length();
}
Integer port = Integer.parseInt(url.substring(hostEnd + 1, portEnd));
Endpoint endpoint = new Endpoint();
endpoint.setHost(host);
endpoint.setPort(port);
endpoints.add(endpoint);
}
return endpoints;
}

private static List<Endpoint> parseEndpointByTnsName(final String url) {
Expand Down
Loading