Skip to content

Commit

Permalink
tag 2021.01.05 add tail based sample to current otel guides. committe…
Browse files Browse the repository at this point in the history
…r:陈晨。

add tail based sample and update read me file contents.
  • Loading branch information
chenmudu committed Jan 4, 2021
1 parent a020be4 commit ff8fa3e
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 15 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ App-Jvm-Metrics Info By Prometheus And Prometheus Gateway:

![avatar](image/app-jvm-metrics.png)

关于业务日志, 借助对应的日志框架实现自定义即可。
例如LogBack,自定义其Layout以及Appender, 借助第三方例如Kafka,将数据exporter至当前Otel-Col即可。
- 关于业务日志, 借助对应的日志框架实现自定义即可,后将数据对接至Otel-Collector即可。

中心化管控:Biz Logging, Trace, Metrics 较为方便。还未尝试Otel让 个人 最惊喜的Tail-Base-Smaple规则。
- 中心化管控:Biz Logging, Trace, Metrics 较为方便。~~还未尝试Otel让 个人 最惊喜的Tail-Base-Smaple规则。~~

- 关于Otel-Col的Tailed Base采样已尝鲜,值得注意的是,该功能的局限性:

1. 基于尾部采样仅仅适合在单个 Collector 内可成功运行,多个Collector之间组成的集群官方及个人均未测试。

1. 基于尾部采样的规则,目前仅仅适用于Trace,其实个人觉得更重要的是业务的Logging数据。

#### 前言

Expand Down Expand Up @@ -87,6 +92,7 @@ OTEL_RESOURCE_ATTRIBUTES=service.name=your service name
#### 测试服务列表

* [Open-Telemetry-Java 示例工程(基于 Spring MVC 示例WebMvc)](otel-simple-webmvc)
* [Open-Telemetry-Java 示例工程(基于 Spring MVC 示例Tail Based采样)](otel-simple-tailbase)
* [Open-Telemetry-Java 示例工程(基于 Rest Clients 示例RestClient)](otel-simple-restclient)
* [Open-Telemetry-Java 示例工程(基于 Spring Webflux 示例WebFlux)](otel-simple-webflux)
* [Open-Telemetry-Java 示例工程(基于 Spring Rdb 示例Rdb)](otel-simple-rdb)
Expand All @@ -106,6 +112,8 @@ OTEL_RESOURCE_ATTRIBUTES=service.name=your service name

- Otel Collector Docker Version: 0.16.0-Dev

- Otel Collector Contrib Docker Version: 0.17.0-Dev

- Maven Version: 3.3.9

- IDEA Version: 2018.1.5 x64
Expand Down
11 changes: 11 additions & 0 deletions config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Open-Telemetry Config 目录

> Open-Telemetry Config 目录仅仅是个人的一些配置参考。
##### 列表

- otel-col-config.yaml: Otel-Collector-Dev 内部的配置相关,仅供参考。

- otel-col-contrib-config.yaml: Otel-Collector-Contrib-Dev 内部的配置相关,仅供参考。

- others.properties: 个人用的其他配置,仅供参考。
62 changes: 62 additions & 0 deletions config/otel-col-contrib-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
extensions:
health_check:
pprof:
endpoint: 0.0.0.0:1777
zpages:
endpoint: 0.0.0.0:55679

receivers:
otlp:
protocols:
grpc:
http:



processors:
batch:
send_batch_size: 10000
send_batch_max_size: 10240
timeout: 5s

tail_sampling:
decision_wait: 50s
num_traces: 200
expected_new_traces_per_sec: 10
policies:
[
{
name: test-policy-1,
type: numeric_attribute, ## 因为 min_value, max_value是闭区间。[201, 999]
numeric_attribute: {key: http.status_code, min_value: 201, max_value: 999}
}
]

exporters:
logging:
logLevel: DEBUG
sampling_initial: 5
sampling_thereafter: 200
jaeger:
endpoint: 192.168.2.6:14250
insecure: true
prometheusremotewrite:
endpoint: "http://192.168.2.6:9998"
namespace: "otel-collector-metrics-space"
insecure: true

service:

pipelines:

traces:
receivers: [otlp]
processors: [tail_sampling]
exporters: [logging, jaeger]

metrics:
receivers: [otlp]
processors: [batch]
exporters: [logging, prometheusremotewrite]

extensions: [health_check, pprof, zpages]
37 changes: 27 additions & 10 deletions config/others.properties
Original file line number Diff line number Diff line change
@@ -1,41 +1,58 @@
docker 命令:仅供参考。
## docker 命令:仅供参考。 只是很不喜欢官方docker compose 的端口映射

jaeger:
##jaeger:
## 中文文档有个端口忘记开启,切记切记。

docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
-p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 14268:14268 -p 9411:9411 -p 14250:14250 jaegertracing/all-in-one:1.16
docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HTTP_PORT=9411
-p 5775:5775/udp -p 6831:6831/udp \
-p 6832:6832/udp -p 5778:5778 \
-p 16686:16686 -p 14268:14268 \
-p 9411:9411 -p 14250:14250 \
jaegertracing/all-in-one:1.16


prometheus:
##prometheus:

docker search prometheus

docker pull prom/prometheus

docker run --name prometheus -d -p 9999:9090 quay.io/prometheus/prometheus
docker run --name prometheus -d -p 9999:9090 \
quay.io/prometheus/prometheus

docker cp prometheus.yml 204ff9046a33:/etc/prometheus/prometheus.yml

prometheus gateway:
## prometheus gateway:

docker pull prom/pushgateway

docker run -d --name=pg -p 9091:9091 prom/pushgateway


grafana:
## grafana:

docker pull grafana/grafana

docker run -d -p 3000:3000 --name=grafana grafana/grafana


otel-docker:
## otel-docker:

hub.docker search otel ---> docker pull 。

docker run -d -p 1777:1777 -p 4317:4317 -p 8888:8888 -p 13133:13133 -p 55678:55678 -p 55679:55679 -p 55680:55680 -p 55681:55681 --name otelcol-dev otel/opentelemetry-collector-dev
docker run -d -p 1777:1777 -p 4317:4317 \
-p 8888:8888 -p 13133:13133 -p 55678:55678 \
-p 55679:55679 -p 55680:55680 -p 55681:55681 \
--name otelcol-dev otel/opentelemetry-collector-dev

docker cp config.yaml 85dee316e533:/etc/otel/config.yaml


## otel-col-contrib to docker.
docker run -p 1777:1777 -p 4317:4317 \
-p 8888:8888 -p 13133:13133 \
-p 55679:55679 -p 55680:55680 \
-p 55681:55681 \
-v /c/Users/chenc/dockerOtelTest/config.yaml:/etc/otel/config.yaml \
--name otelcol-contrib-dev otel/opentelemetry-collector-contrib-dev

17 changes: 17 additions & 0 deletions otel-simple-tailbase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Open-Telemetry-Simple-TailBased 案例工程

> Open-Telemetry-Simple-TailBased 实际测试了 Otel-Col 对 Trace Data 的采样规则。
##### 测试模块快速开始

1. 确保[Guides 案例工程下的步骤](../README.md)执行完毕。

2. 启动此模块[otel-simple-tailbase](https://github.com/chenmudu/open-telemetry-java-guides/tree/master/otel-simple-tailbase/src/main/java/org/chenmudu/otel/tailbase)TailBasedRunMain.

3. 访问http://localhost:10009/tailbased。

4. Copy Console 中的 TraceId访问 http://localhost:16686/ 即可观测结果。

##### 注意

1. 当你使用想观测
30 changes: 30 additions & 0 deletions otel-simple-tailbase/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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>open-telemetry-java-guides</artifactId>
<groupId>org.chenmudu.otel</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>otel-simple-tailbase</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-extension-annotations</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* MIT License
* <p>
* Copyright (c) 2020 chenmudu (陈晨)
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
package org.chenmudu.otel.tailbase;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
*
* @author [email protected] 2021/1/5 00:15
*/
@SpringBootApplication
public class TailBasedRunMain {
public static void main(String[] args) {
SpringApplication.run(TailBasedRunMain.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* MIT License
* <p>
* Copyright (c) 2020 chenmudu (陈晨)
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
package org.chenmudu.otel.tailbase.controller;

import io.opentelemetry.extension.annotations.WithSpan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
*
* @author [email protected] 2021/1/5 00:16
*/
@Slf4j
@RestController
public class OtelTestTailBaseController {

private volatile Integer counter = 0;

@GetMapping("/tailbased")
public String tailbased() {
log.info("OtelTestTailBaseController hello started!");
this.calledHi();
return "OtelTestTailBaseController hello !";
}

@WithSpan(value = "testCalledHi")
private String calledHi() {
log.info("OtelTestTailBaseController calledHi started!");
// 当你配置了tail_base采样规则时即可生效。
if(counter++ % 2 == 1) {
int i = 1 /0 ;
}
return "calledHi";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
server.port=10009

spring.application.name=otel-simple-tail-based
15 changes: 15 additions & 0 deletions otel-simple-tailbase/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<configuration>
<jmxConfigurator/>
<property name="charset" value="UTF-8" />
<property name="pattern"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-5level] - [%X{traceId},%X{spanId}]- %logger{30}.%method:%line %msg%n" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${pattern}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
6 changes: 5 additions & 1 deletion otel-simple-webmvc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@

3. 访问http://localhost:10001/hello。

4. Copy Console 中的 TraceId访问 http://localhost:16686/ 即可观测结果。
4. Copy Console 中的 TraceId访问 http://localhost:16686/ 即可观测结果。

##### 注意

1. 当你使用想观测
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.opentelemetry.extension.annotations.WithSpan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
Expand All @@ -28,6 +29,8 @@
@RestController
public class OtelTestSpringMvcController {

private Integer counter = 0;

@GetMapping("/hello")
public String hello() {
log.info("OtelTestSpringMvcController hello started!");
Expand All @@ -38,6 +41,9 @@ public String hello() {
@WithSpan(value = "testCalledHi")
private String calledHi() {
log.info("OtelTestSpringMvcController calledHi started!");
if(counter++ % 2 == 1) {
int i = 1 /0 ;
}
return "calledHi";
}
}
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@

<modules>
<module>otel-simple-async</module>
<module>otel-simple-kafka</module>
<module>otel-simple-rabbit</module>
<module>otel-simple-rdb</module>
<module>otel-simple-restclient</module>
<module>otel-simple-spring-data</module>
<module>otel-simple-tailbase</module>
<module>otel-simple-webflux</module>
<module>otel-simple-webmvc</module>
<module>otel-simple-kafka</module>
<module>otel-simple-tailbase</module>
</modules>

<dependencyManagement>
Expand Down

0 comments on commit ff8fa3e

Please sign in to comment.