Dubbo应用可观测性升级指南与踩坑记录

2024-04-23 15:12

本文主要是介绍Dubbo应用可观测性升级指南与踩坑记录,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

应用从dubbo-3.1.*升级到dubbo-*:3.2.*最新稳定版本,提升应用的可观测性和度量数据准确性

1. dubbo版本发布说明(可不关注)

dubbo版本发布

https://github.com/apache/dubbo/releases

  • 【升级兼容性】3.1 升级到 3.2

dubbo-3.2.0

2. 应用修改点

应用一般只需要升级dubbo-spring-boot-starter版本到3.2.10,相关组件版本检查是否一致

要求

  • dubbo-spring-boot-starter版本3.2.10dubbo系列版本一样 (xxx-spring-boot-starter引入,项目里可不单独引用)
  • 【依赖可选】netty系列版本4.1.101.Final
  • 【依赖可选】fastjson2 版本2.0.46 (全部统一使用hessian2参数序列化方式)
  • 【依赖可选】protobuf-java版本3.24.2
  • 【依赖可选】t-digest版本3.3
  • 检查jar包dubbo-spring-boot-observability-starterspring-boot-starter-actuator是否存在。

版本检查
通过Maven依赖树命令分析mvn dependency:tree > dependency-tree.txt
IDEA,通过Maven依赖分析功能,关键词搜索

Maven依赖分析

2.1 jar包升级

pom.xml依赖声明

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.16</version><relativePath/>
</parent><properties><dubbo.version>3.2.10</dubbo.version><netty.version>4.1.101.Final</netty.version><micrometer.version>1.12.0</micrometer.version><prometheus-client.version>0.16.0</prometheus-client.version><prometheus-pushgateway.version>0.16.0</prometheus-pushgateway.version>
</properties><dependencyManagement><dependencies><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId><version>${dubbo.version}</version></dependency></dependencies>
</dependencyManagement>

pom.xml依赖

<dependencies><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId></dependency>
</dependencies>
  • 【版本检查】fastjson2版本升级到2.0.46

fastjson不太稳定,问题较多,风险较大。

参数序列化方式,建议保持不变。

全部统一使用hessian2参数序列化方式

2.2 属性配置

application.properties

management.server.port=18180
#management.server.base-path=
management.server.servlet.context-path=
management.endpoints.web.base-path=/
management.endpoints.web.exposure.include=prometheus
management.endpoints.web.exposure.exclude=metrics
management.endpoints.web.path-mapping.prometheus=metrics
management.metrics.export.prometheus.descriptions=false
management.metrics.tags.application=${spring.application.name}# 消费者从提供者同步地址信息等元数据
dubbo.application.metadata-service-protocol=dubbo
dubbo.application.qos-port=22222
dubbo.metrics.protocol=prometheus
dubbo.metrics.enable-jvm=true
dubbo.metrics.enable-threadpool=true
dubbo.metrics.enable-registry=false
dubbo.metrics.enable-metadata=false
dubbo.metrics.export-metrics-service=false
dubbo.metrics.use-global-registry=true
dubbo.metrics.enable-rpc=true
dubbo.metrics.aggregation.enabled=true
dubbo.metrics.aggregation.enable-qps=true
dubbo.metrics.aggregation.enable-rt-pxx=true
dubbo.metrics.aggregation.enable-rt=true
dubbo.metrics.aggregation.enable-request=true
dubbo.metrics.histogram.enabled=true

【配置可选】Apollo统一的基础配置(集成外部配置数据源-配置中心)

建议使用Nacos

apollo-client依赖检查

apollo.bootstrap.enabled=true
apollo.bootstrap.namespaces=*,common-middleware-dubbo-metrics

2.3 类检查机制设置【升级必须设置】

若不设置,泛化调用可能会失败。

4-21 - 检测到不安全的序列化数据

出参入参对象可能有些未实现Serializable序列化接口,引起调用异常。

解法详见【官方文档】类检查机制

【解法】AutoConfiguration-自动配置

ApplicationConfig applicationConfig = new ApplicationConfig();
// 类检查机制
applicationConfig.setSerializeCheckStatus("DISABLE");
applicationConfig.setCheckSerializable(false);

【解法】属性文件

# 类检查机制
dubbo.application.serialize-check-status=DISABLE
dubbo.application.check-serializable=false

2.5 live存活探针日志-建议屏蔽

Kubernetes通过存活探针(liveness probe)检查容器是否还在运行,每隔2s探测一次,打印不少日志,建议屏蔽。

logback-k8s.xmllogback-spring.xml配置文件

<!-- k8s liveness probe qos日志很多,不打印 -->
<logger name="org.apache.dubbo.qos.command" level="warn" additivity="false"/>
logging.level.org.apache.dubbo.qos.command=warn

3. 踩过的坑

应用升级Dubbo3问题记录

3.1 检查系统最终组件版本

  • dubbo-boot-starter-*系列版本3.2.10 (xxx-spring-boot-starter引入,项目里可不单独引用)
  • fastjson2版本2.0.46 (全部统一使用hessian2参数序列化方式)
  • netty版本4.1.101.Final
  • protobuf-java版本3.24.2
  • t-digest版本3.3
  • 检查jar包dubbo-spring-boot-observability-starterspring-boot-starter-actuator是否存在。
  • micrometer系列组件版本是否一样
  • prometheussimpleclient系列组件版本是否一样

3.2 MetadataService报NPE异常

原因是提供者DubboAccessLogFilter抛出NPE异常,引起消费者获取应用地址等元数据信息失败。

dubbo过滤器加载机制调整

在Filter中调用RpcContext.getServiceContext().isConsumerSide()方法报空指针错误 · Issue #11716 · apache/dubbo

2024-01-23 11:51:14,075 [Dubbo-framework-metadata-retry-thread-1] ERROR org.apache.dubbo.registry.client.metadata.MetadataUtils -  [DUBBO] Failed to get app metadata for revision 6dd35818cdc09f4b682f8ac3fe312847 for type local from instance 192.168.108.31:8504, dubbo version: 3.2.10, current host: 192.168.104.218, error code: 1-39. This may be caused by , go to https://dubbo.apache.org/faq/1/39 to find instructions. 
org.apache.dubbo.rpc.RpcException: Failed to invoke remote method: getMetadataInfo, provider: dubbo://192.168.108.31:8502/org.apache.dubbo.metadata.MetadataService?connections=1&corethreads=2&dubbo=2.0.2&group=member&port=8502&prefer.serialization=hessian2&protocol=dubbo&release=3.2.10&retries=0&side=consumer&threadpool=cached&threads=100&timeout=3000&version=1.0.0, cause: org.apache.dubbo.remoting.RemotingException: java.lang.NullPointerException
java.lang.NullPointerExceptionat com.xxx.member.config.DubboAccessLogFilter.invoke$original$xDfvMLE5(DubboAccessLogFilter.java:44)

【解法】对于@Activate自动激活的过滤器,不能再显示配置Filter

@Activate(group = CommonConstants.PROVIDER, order = 1)
public class DubboAccessLogFilter implements Filter {@Overridepublic Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {// ...RpcContextAttachment rpcContext = RpcContext.getServerAttachment();// ...}
}

3.3 netty版本冲突

netty版本要和dubbo依赖的版本一样或兼容

<properties><netty.version>4.1.101.Final</netty.version><micrometer.version>1.12.0</micrometer.version><prometheus-client.version>0.16.0</prometheus-client.version><prometheus-pushgateway.version>0.16.0</prometheus-pushgateway.version>
</properties>
java.lang.NoSuchMethodError: io.netty.handler.codec.http2.Http2FrameCodecBuilder: method <init>()V not foundat org.apache.dubbo.rpc.protocol.tri.TripleHttp2FrameCodecBuilder.<init>(TripleHttp2FrameCodecBuilder.java:32)at org.apache.dubbo.rpc.protocol.tri.TripleHttp2FrameCodecBuilder.fromConnection(TripleHttp2FrameCodecBuilder.java:37)

3.4 p95指标计算冲突

t-digest要高于3.3elasticsearch里引入了低版本。

<dependencyManagement><dependencies><dependency><groupId>org.elasticsearch</groupId><artifactId>elasticsearch</artifactId><version>5.3.3</version><exclusions><exclusion><groupId>com.tdunning</groupId><artifactId>t-digest</artifactId></exclusion></exclusions></dependency></dependencies>
</dependencyManagement>

3.5 参数对象未实现Serializable序列化接口

4-21 - 检测到不安全的序列化数据

3.1 升级至 3.2

序列化协议升级

请求从消费者应用调用具体服务方法时,可能参数值为空,报如下异常。

Serialized class com.xxx.perform.request.XxxRequest is not in allow list. Current mode is `STRICT`, will disallow to deserialize it by default. Please add it into security/serialize.allowlist or follow FAQ to configure it., dubbo version: 3.2.5, current host: 192.168.108.111, error code: 4-21. This may be caused by , go to https://dubbo.apache.org/faq/4/21 to find instructions

解法详见【官方文档】类检查机制

【解法】AutoConfiguration-自动配置

ApplicationConfig applicationConfig = new ApplicationConfig();
// 类检查机制
applicationConfig.setSerializeCheckStatus("DISABLE");
applicationConfig.setCheckSerializable(false);// 提供者配置层
ProviderConfig providerConfig = new ProviderConfig();
// 参数解析序列化方式
providerConfig.setPreferSerialization("hessian2");
providerConfig.setSerialization("hessian2");

【解法】属性文件

# 类检查机制
dubbo.application.serialize-check-status=DISABLE
dubbo.application.check-serializable=false
# 参数解析序列化方式
# 提供者配置层
dubbo.provider.prefer-serialization=hessian2
dubbo.provider.serialization=hessian2

3.6 使用 sharding-jdbc 造成 SQLFeatureNotSupportedException: isValid

暂时关闭actuator对db的监控

  • https://www.cnblogs.com/laeni/p/16089788.html
  • https://blog.csdn.net/kurohatan/article/details/119951747
management.health.db.enabled=false

3.7 屏蔽dubbo访问警告日志

[DUBBO] Will write to the default location, " + "please enable this feature by setting 'accesslog.fixed.path=true' and restart the process. " + "We highly recommend to not enable this feature in production for security concerns, " + "please be fully aware of the potential risks before doing so!, dubbo version: 3.2.10, current host: 192.168.107.130, error code: 0-28. This may be caused by Change of accesslog file path not allowed. , go to https://dubbo.apache.org/faq/0/28 to find instructions.

dubbo协议配置,不设置accesslog访问日志配置项。

# 删除这些
- protocolConfig.setAccesslog(false);
- protocolConfig.setAccesslog("false");

3.8 Spring应用上下文刷新两次

这些信息在应用启动日志里出现两次,ContextRefreshedEvent事件会被触发两次,Spring以父子容器模式运行。

Initializing Spring embedded WebApplicationContext
Root WebApplicationContext: initialization completedTomcat initialized with port(s): 8080 (http)
Tomcat initialized with port(s): 18180 (http)

应用里有基于监听ContextRefreshedEvent事件的逻辑,可能会存在两次运行的风险。

防止重复触发

ContextRefreshedEvent使用注意事项

  • 方案一:增加一个是否初始化的标识,进行初始化前判断标识。
  • 方案二:改为监听ApplicationReadyEvent事件,只会触发一次。
/*** 并发开关*/
private final AtomicBoolean concurrentSwitch = new AtomicBoolean(false);if (concurrentSwitch.compareAndSet(false, true)) {// do something
}

先前,18180 端口是以 Jetty 服务器进程启动,不是 Tomcat。
父子容器,应该是 8080 和 18180 都使用 Tomcat 容器启动 引入。
应用以 父容器 为主线。可以查看对象地址

receive event org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@34766f4b, started on Wed Jan 10 10:07:53 CST 2024, parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2dd80673]receive event org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2dd80673, started on Wed Jan 10 10:07:41 CST 2024]

3.9 应用未暴露18180端口

dubbo应用可能未依赖spring-boot-starter-web,未启动Servlet容器,进而未暴露18180端口。

因为18180端口暴露依赖于Servlet容器启动。

【可能解法】增加spring-boot-starter-web依赖可以解决

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

3.10 RPC调用消费者端反序列化响应对象时数据丢失一条

[FEATURE] 开启JSONWriter.Feature.ReferenceDetection序列化有java.util.List类型成员引用的对象能得到“$ref”序列化结果 · Issue #

RPC调用响应结构中的List某一条数据丢失问题,响应结构中存在外层字段引用List中的元素($ref),是fastjson2的问题,升级到fastjson2-2.0.46解决。

3.11 fastjson2 JSON反序列化异常

com.alibaba.fastjson2.JSONException: skip not support type INT32 68 · Issue #1257 · alibaba/fastjson

本问题是fastjson2的问题,升级到fastjson2-2.0.46解决。

Caused by: org.apache.dubbo.remoting.RemotingException: java.io.IOException: org.apache.dubbo.common.serialize.SerializationException: com.alibaba.fastjson2.JSONException: skip not support type INT32 68Caused by: org.apache.dubbo.remoting.RemotingException: java.io.IOException: org.apache.dubbo.common.serialize.SerializationException: com.alibaba.fastjson2.JSONException: skip not support type INT32 69

4. 应用部署后检查

应用观测指标

  • 收集观测指标

应用日志中搜索18180关键词

> message:"18180" Tomcat started on port(s): 18180 (http) with context path ''Tomcat initialized with port(s): 18180 (http)

应用本地启动并访问

http://localhost:18180/metrics

若指标URL访问不了,请检查下面这些配置项

management.server.port=18180
#management.server.base-path=
management.server.servlet.context-path=
management.endpoints.web.base-path=
management.endpoints.web.exposure.include=prometheus
management.endpoints.web.exposure.exclude=metrics
management.endpoints.web.path-mapping.prometheus=metrics

可观测工作台

  • Dubbo可观测仪表盘

应用名里搜索

Dubbo可观测

triple协议

1.应用启动日志里搜索tri协议或8506端口

ZookeeperRegistry -  [DUBBO] Register: tri://*.*.*.*:8506/com.xxx.consumer.api.Xxx

2.DubboKeeper工作台

内存满了,数据可能未及时更新

页面里查找8506

5. 升级进度

Dubbo-3.2升级进度表-飞书表格(配置各个环境的升级统计图)

这篇关于Dubbo应用可观测性升级指南与踩坑记录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/929142

相关文章

51单片机学习记录———定时器

文章目录 前言一、定时器介绍二、STC89C52定时器资源三、定时器框图四、定时器模式五、定时器相关寄存器六、定时器练习 前言 一个学习嵌入式的小白~ 有问题评论区或私信指出~ 提示:以下是本篇文章正文内容,下面案例可供参考 一、定时器介绍 定时器介绍:51单片机的定时器属于单片机的内部资源,其电路的连接和运转均在单片机内部完成。 定时器作用: 1.用于计数系统,可

Javascript高级程序设计(第四版)--学习记录之变量、内存

原始值与引用值 原始值:简单的数据即基础数据类型,按值访问。 引用值:由多个值构成的对象即复杂数据类型,按引用访问。 动态属性 对于引用值而言,可以随时添加、修改和删除其属性和方法。 let person = new Object();person.name = 'Jason';person.age = 42;console.log(person.name,person.age);//'J

vcpkg安装opencv中的特殊问题记录(无法找到opencv_corexd.dll)

我是按照网上的vcpkg安装opencv方法进行的(比如这篇:从0开始在visual studio上安装opencv(超详细,针对小白)),但是中间出现了一些别人没有遇到的问题,虽然原因没有找到,但是本人给出一些暂时的解决办法: 问题1: 我在安装库命令行使用的是 .\vcpkg.exe install opencv 我的电脑是x64,vcpkg在这条命令后默认下载的也是opencv2:x6

亮相WOT全球技术创新大会,揭秘火山引擎边缘容器技术在泛CDN场景的应用与实践

2024年6月21日-22日,51CTO“WOT全球技术创新大会2024”在北京举办。火山引擎边缘计算架构师李志明受邀参与,以“边缘容器技术在泛CDN场景的应用和实践”为主题,与多位行业资深专家,共同探讨泛CDN行业技术架构以及云原生与边缘计算的发展和展望。 火山引擎边缘计算架构师李志明表示:为更好地解决传统泛CDN类业务运行中的问题,火山引擎边缘容器团队参考行业做法,结合实践经验,打造火山

记录AS混淆代码模板

开启混淆得先在build.gradle文件中把 minifyEnabled false改成true,以及shrinkResources true//去除无用的resource文件 这些是写在proguard-rules.pro文件内的 指定代码的压缩级别 -optimizationpasses 5 包明不混合大小写 -dontusemixedcaseclassnames 不去忽略非公共

自制的浏览器主页,可以是最简单的桌面应用,可以把它当成备忘录桌面应用

自制的浏览器主页,可以是最简单的桌面应用,可以把它当成备忘录桌面应用。如果你看不懂,请留言。 完整代码: <!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><ti

Python应用开发——30天学习Streamlit Python包进行APP的构建(9)

st.area_chart 显示区域图。 这是围绕 st.altair_chart 的语法糖。主要区别在于该命令使用数据自身的列和指数来计算图表的 Altair 规格。因此,在许多 "只需绘制此图 "的情况下,该命令更易于使用,但可定制性较差。 如果 st.area_chart 无法正确猜测数据规格,请尝试使用 st.altair_chart 指定所需的图表。 Function signa

数控系统资料记录

数控技术:数控系统刀补功能的软件实现及其仿真--数控仿真程序开发实战 https://github.com/mai4567/CNC 下载编译报错:error: src/dxflib.a: 没有那个文件或目录: 解决:下载dxflibhttps://www.ribbonsoft.com/en/dxflib-downloads,下载完后编译,编译后得到libdxflib.a,替换掉项目makefi

pixel_link记录

export PYTHONPATH=/path2to/pixel_link/pylib/src:$PYTHONPATH   https://blog.csdn.net/northeastsqure/article/details/83655200   https://blog.csdn.net/u011440558/article/details/78606662   报错: All

气象站的种类和应用范围可以根据不同的分类标准进行详细的划分和描述

气象站的种类和应用范围可以根据不同的分类标准进行详细的划分和描述。以下是从不同角度对气象站的种类和应用范围的介绍: 一、气象站的种类 根据用途和安装环境分类: 农业气象站:专为农业生产服务,监测土壤温度、湿度等参数,为农业生产提供科学依据。交通气象站:用于公路、铁路、机场等交通场所的气象监测,提供实时气象数据以支持交通运营和调度。林业气象站:监测林区风速、湿度、温度等气象要素,为林区保护和