Skip to content

Commit 7f3b79b

Browse files
authored
bugfix: fix prometheus fail to return seata metrics data when using Nacos (apache#6786)
1 parent b2f9c3a commit 7f3b79b

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

changes/en-us/2.x.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Add changes here for all PR submitted to the 2.x branch.
3030
- [[#6778](https://github.com/apache/incubator-seata/pull/6778)] fix namingserver node term
3131
- [[#6765](https://github.com/apache/incubator-seata/pull/6765)] fix MySQL driver loading by replacing custom classloader with system classloader for better compatibility and simplified process
3232
- [[#6781](https://github.com/apache/incubator-seata/pull/6781)] the issue where the TC occasionally fails to go offline from the NamingServer
33+
- [[#6785](https://github.com/apache/incubator-seata/pull/6785)] fix prometheus fail to return seata metrics data when using Nacos
3334
- [[#6797](https://github.com/apache/incubator-seata/pull/6797)] fall back to any of available cluster address when query cluster address is empty
3435
- [[#6800](https://github.com/apache/incubator-seata/pull/6800)] make exception message generic for all database drivers
3536
- [[#6759](https://github.com/apache/incubator-seata/pull/6759)] fix the error of active refresh failure of cross-database table metadata

changes/zh-cn/2.x.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [[#6778](https://github.com/apache/incubator-seata/pull/6778)] 修复namingserver的节点term为0问题
3232
- [[#6765](https://github.com/apache/incubator-seata/pull/6765)] 改进MySQL驱动加载机制,将自定义类加载器替换为系统类加载器,更兼容简化流程
3333
- [[#6781](https://github.com/apache/incubator-seata/pull/6781)] 修复tc下线时,由于定时任务没有先关闭,导致下线后还会被注册上,需要靠namingserver的健康检查来下线的bug
34+
- [[#6785](https://github.com/apache/incubator-seata/pull/6785)] 修复 prometheus 在与 Nacos 集成时无法返回 seata metrics 数据的问题
3435
- [[#6797](https://github.com/apache/incubator-seata/pull/6797)] 当查询的集群地址为空时,获取可用的任意集群地址
3536
- [[#6800](https://github.com/apache/incubator-seata/pull/6800)] 使异常消息对所有数据库驱动程序通用
3637
- [[#6812](https://github.com/apache/incubator-seata/pull/6812)] 修复切换事务分组和节点下线时namingserver没有实时感知和推送的bug

common/src/main/java/org/apache/seata/common/DefaultValues.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public interface DefaultValues {
259259
/**
260260
* the const DEFAULT_METRICS_ENABLED
261261
*/
262-
boolean DEFAULT_METRICS_ENABLED = false;
262+
boolean DEFAULT_METRICS_ENABLED = true;
263263

264264
/**
265265
* the const DEFAULT_METRICS_REGISTRY_TYPE

metrics/seata-metrics-exporter-prometheus/src/main/java/org/apache/seata/metrics/exporter/prometheus/PrometheusExporter.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
package org.apache.seata.metrics.exporter.prometheus;
1818

1919
import java.io.IOException;
20+
import java.net.InetSocketAddress;
2021
import java.util.ArrayList;
2122
import java.util.List;
2223
import java.util.Map.Entry;
2324

2425
import io.prometheus.client.Collector;
2526
import io.prometheus.client.Collector.MetricFamilySamples.Sample;
27+
import io.prometheus.client.CollectorRegistry;
2628
import io.prometheus.client.exporter.HTTPServer;
2729
import org.apache.seata.common.loader.LoadLevel;
2830
import org.apache.seata.config.ConfigurationFactory;
@@ -48,8 +50,9 @@ public class PrometheusExporter extends Collector implements Collector.Describab
4850
public PrometheusExporter() throws IOException {
4951
int port = ConfigurationFactory.getInstance().getInt(
5052
ConfigurationKeys.METRICS_PREFIX + METRICS_EXPORTER_PROMETHEUS_PORT, DEFAULT_PROMETHEUS_PORT);
51-
this.server = new HTTPServer(port, true);
52-
this.register();
53+
CollectorRegistry collectorRegistry = new CollectorRegistry(true);
54+
this.register(collectorRegistry);
55+
this.server = new HTTPServer(new InetSocketAddress(port),collectorRegistry, true);
5356
}
5457

5558
@Override

script/config-center/config.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ server.raft.sync=true
164164

165165

166166
#Metrics configuration, only for the server
167-
metrics.enabled=false
167+
metrics.enabled=true
168168
metrics.registryType=compact
169169
metrics.exporterList=prometheus
170170
metrics.exporterPrometheusPort=9898

0 commit comments

Comments
 (0)