Introducing new features.add zipkin

This commit is contained in:
lishangbu 2019-02-23 21:59:12 +08:00
parent e783864261
commit b65302ba98
11 changed files with 293 additions and 4 deletions

View File

@ -283,4 +283,62 @@ BEGIN;
INSERT INTO `sys_user_role` VALUES ('1', '1'), ('2', '2');
COMMIT;
-- ----------------------------
-- Table structure for `zipkin_spans`
-- ----------------------------
CREATE TABLE IF NOT EXISTS zipkin_spans (
`trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
`trace_id` BIGINT NOT NULL,
`id` BIGINT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`parent_id` BIGINT,
`debug` BIT(1),
`start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL',
`duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query'
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
ALTER TABLE zipkin_spans ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `id`) COMMENT 'ignore insert on duplicate';
ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`, `id`) COMMENT 'for joining with zipkin_annotations';
ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds';
ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames';
ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range';
-- ----------------------------
-- Table structure for `zipkin_annotations`
-- ----------------------------
CREATE TABLE IF NOT EXISTS zipkin_annotations (
`trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
`trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id',
`span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id',
`a_key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1',
`a_value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB',
`a_type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation',
`a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',
`endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null',
`endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address',
`endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null',
`endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null'
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds';
ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames';
ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces and autocomplete values';
ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces and autocomplete values';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`, `a_key`) COMMENT 'for dependencies job';
-- ----------------------------
-- Table structure for `zipkin_dependencies`
-- ----------------------------
CREATE TABLE IF NOT EXISTS zipkin_dependencies (
`day` DATE NOT NULL,
`parent` VARCHAR(255) NOT NULL,
`child` VARCHAR(255) NOT NULL,
`call_count` BIGINT,
`error_count` BIGINT
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`);
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -88,3 +88,13 @@ services:
container_name: pig-codegen
hostname: pig-codegen
image: pig-codegen
pig-zipkin:
build:
context: ./
dockerfile: ./pig-visual/pig-zipkin/Dockerfile
restart: always
image: pig-zipkin
container_name: pig-zipkin
ports:
- 5002:5002

View File

@ -8,9 +8,18 @@ spring:
redis:
password:
host: pig-redis
jackson:
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
# zipkin
zipkin:
enabled: true
base-url: http://pig-zipkin
sleuth:
web:
client:
enabled: true
sampler:
# 默认的采样比率为0.1,不能看到所有请求数据
# 更改采样比率为1就能看到所有的请求数据了但是这样会增加接口调用延迟
probability: 1.0
# 暴露监控端点
management:

View File

@ -0,0 +1,18 @@
spring:
# 数据源
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.jdbc.Driver
username: root
password: root
url: jdbc:mysql://pig-mysql:3306/pig?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
management:
metrics:
web:
server:
auto-time-requests: false
zipkin:
storage:
type: mysql
sleuth:
enabled: true

View File

@ -0,0 +1,15 @@
FROM anapsix/alpine-java:8_server-jre_unlimited
MAINTAINER wangiegie@gmail.com
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN mkdir -p /pig-zipkin
WORKDIR /pig-zipkin
EXPOSE 5002
ADD ./pig-visual/pig-zipkin/target/pig-zipkin.jar ./
CMD java -Djava.security.egd=file:/dev/./urandom -jar pig-zipkin.jar

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>pig-visual</artifactId>
<groupId>com.pig4cloud</groupId>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>pig-zipkin</artifactId>
<packaging>jar</packaging>
<description>pig 服务链路跟踪模块,基于zipkin</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!--排除tomcat依赖-->
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<!--配置中心客户端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!--jdbc相关-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--zipkin-->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>${zipkin.version}</version>
<!--排除log4j2 避免和logback冲突警告-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>${zipkin.version}</version>
</dependency>
<!-- 使用mysql存储-->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-mysql</artifactId>
<version>${zipkin.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-storage-mysql</artifactId>
<version>${zipkin-storage-mysql.version}</version>
</dependency>
<!-- zipkin2.x 需要此包连接操作mysql -->
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,27 @@
package com.pig4cloud.pig.zipkin;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.context.annotation.Bean;
import zipkin.storage.mysql.MySQLStorage;
import zipkin2.server.internal.EnableZipkinServer;
import javax.sql.DataSource;
/**
* 服务链路追踪
*
* @author lishangbu
* @date 2019/2/23
*/
@EnableZipkinServer
@SpringCloudApplication
public class PigZipkinApplication {
public static void main(String[] args) {
SpringApplication.run(PigZipkinApplication.class, args);
}
@Bean
public MySQLStorage mySQLStorage(DataSource datasource) {
return MySQLStorage.builder().datasource(datasource).executor(Runnable::run).build();
}
}

View File

@ -0,0 +1,16 @@
${AnsiColor.BRIGHT_YELLOW}
::::::::: ::::::::::: ::::::::
:+: :+: :+: :+: :+:
+:+ +:+ +:+ +:+
+#++:++#+ +#+ :#:
+#+ +#+ +#+ +#+#
#+# #+# #+# #+#
### ########### ########
www.pig4cloud.com
Pig Microservice Architecture

View File

@ -0,0 +1,24 @@
server:
port: 5002
spring:
application:
name: pig-zipkin
profiles:
active: dev
#配置中心
cloud:
config:
fail-fast: true
name: ${spring.application.name}
profile: ${spring.profiles.active}
discovery:
enabled: true
service-id: pig-config
# 注册中心配置
eureka:
instance:
prefer-ip-address: true
client:
service-url:
defaultZone: http://pig:pig@pig-eureka:8761/eureka/

View File

@ -31,5 +31,6 @@
<modules>
<module>pig-codegen</module>
<module>pig-monitor</module>
<module>pig-zipkin</module>
</modules>
</project>

15
pom.xml
View File

@ -29,7 +29,7 @@
<properties>
<spring-boot.version>2.0.8.RELEASE</spring-boot.version>
<spring-cloud.version>Finchley.SR2</spring-cloud.version>
<spring-platform.version>Cairo-SR5</spring-platform.version>
<spring-platform.version>Cairo-SR7</spring-platform.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
@ -41,6 +41,10 @@
<jasypt.version>2.1.0</jasypt.version>
<security.oauth.version>2.3.3.RELEASE</security.oauth.version>
<jackson.modules>2.9.6</jackson.modules>
<!--zipkin2.12.x需要此版本jooq-->
<jooq.version>3.11.9</jooq.version>
<zipkin.version>2.12.2</zipkin.version>
<zipkin-storage-mysql.version>2.8.4</zipkin-storage-mysql.version>
<docker.url>http://192.168.0.13:4243</docker.url>
<registry.url>192.168.0.13:5000</registry.url>
</properties>
@ -73,6 +77,15 @@
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
<!--服务链路追踪-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<!--断路器依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>