From b3976295f534d1511cac462a46d41a25292a5cd7 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Fri, 21 Jun 2024 15:17:57 +0800 Subject: [PATCH] [improve] update collector info, support env config or auto fetch (#2100) Signed-off-by: tomsun28 Co-authored-by: Logic --- .all-contributorsrc | 18 ++++++++++ README.md | 4 ++- README_CN.md | 4 ++- .../dispatch/entrance/CollectServer.java | 34 ++++--------------- collector/src/main/resources/application.yml | 4 +-- .../common/entity/dto/CollectorInfo.java | 1 - .../hertzbeat/common/util/IpDomainUtil.java | 6 +--- home/docs/introduce.md | 2 +- .../current/introduce.md | 2 +- .../version-v1.4.x/introduce.md | 2 +- .../version-v1.5.x/introduce.md | 2 +- home/src/pages/team/index.jsx | 8 +++++ .../version-v1.4.x/introduce.md | 2 +- .../version-v1.5.x/introduce.md | 2 +- .../process/CollectorOnlineProcessor.java | 8 +++++ 15 files changed, 56 insertions(+), 43 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6afe40153b2..04f841d982a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1916,6 +1916,24 @@ "contributions": [ "code" ] + }, + { + "login": "killme2008", + "name": "dennis zhuang", + "avatar_url": "https://avatars.githubusercontent.com/u/14142?v=4", + "profile": "http://fnil.net/", + "contributions": [ + "code" + ] + }, + { + "login": "kerwin612", + "name": "Kerwin Bryant", + "avatar_url": "https://avatars.githubusercontent.com/u/3371163?v=4", + "profile": "https://github.com/kerwin612", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, diff --git a/README.md b/README.md index 51a1d0fab85..c4c60246262 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ [![Twitter](https://img.shields.io/twitter/follow/hertzbeat1024?logo=twitter)](https://twitter.com/hertzbeat1024) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8139/badge)](https://www.bestpractices.dev/projects/8139) [![codecov](https://codecov.io/gh/apache/HertzBeat/branch/master/graph/badge.svg)](https://app.codecov.io/gh/apache/hertzbeat) -[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/repository/docker/apache/hertzbeat/general) +[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/r/apache/hertzbeat) [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/hertzbeat)](https://artifacthub.io/packages/search?repo=hertzbeat) [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCri75zfWX0GHqJFPENEbLow?logo=youtube&label=YouTube%20Channel)](https://www.youtube.com/channel/UCri75zfWX0GHqJFPENEbLow) @@ -452,6 +452,8 @@ Thanks to these wonderful people, welcome to join us: Leon Li
Leon Li

💻 + dennis zhuang
dennis zhuang

💻 + Kerwin Bryant
Kerwin Bryant

💻 diff --git a/README_CN.md b/README_CN.md index cb2567f5a60..fdf0304c510 100644 --- a/README_CN.md +++ b/README_CN.md @@ -15,7 +15,7 @@ [![Twitter](https://img.shields.io/twitter/follow/hertzbeat1024?logo=twitter)](https://twitter.com/hertzbeat1024) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8139/badge)](https://www.bestpractices.dev/projects/8139) [![codecov](https://codecov.io/gh/apache/HertzBeat/branch/master/graph/badge.svg)](https://app.codecov.io/gh/apache/hertzbeat) -[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/repository/docker/apache/hertzbeat/general) +[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/r/apache/hertzbeat) [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/hertzbeat)](https://artifacthub.io/packages/search?repo=hertzbeat) [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCri75zfWX0GHqJFPENEbLow?logo=youtube&label=YouTube%20Channel)](https://www.youtube.com/channel/UCri75zfWX0GHqJFPENEbLow) @@ -451,6 +451,8 @@ Thanks these wonderful people, welcome to join us: Leon Li
Leon Li

💻 + dennis zhuang
dennis zhuang

💻 + Kerwin Bryant
Kerwin Bryant

💻 diff --git a/collector/src/main/java/org/apache/hertzbeat/collector/dispatch/entrance/CollectServer.java b/collector/src/main/java/org/apache/hertzbeat/collector/dispatch/entrance/CollectServer.java index 2b45cce45be..9baabd1509e 100644 --- a/collector/src/main/java/org/apache/hertzbeat/collector/dispatch/entrance/CollectServer.java +++ b/collector/src/main/java/org/apache/hertzbeat/collector/dispatch/entrance/CollectServer.java @@ -38,7 +38,6 @@ import org.apache.hertzbeat.common.entity.dto.CollectorInfo; import org.apache.hertzbeat.common.entity.message.ClusterMsg; import org.apache.hertzbeat.common.support.CommonThreadPool; -import org.apache.hertzbeat.common.util.IpDomainUtil; import org.apache.hertzbeat.common.util.JsonUtil; import org.apache.hertzbeat.remoting.RemotingClient; import org.apache.hertzbeat.remoting.event.NettyEventListener; @@ -63,12 +62,12 @@ public class CollectServer implements CommandLineRunner { private final TimerDispatch timerDispatch; + private final CollectorInfoProperties infoProperties; + private RemotingClient remotingClient; private ScheduledExecutorService scheduledExecutor; - private Info info; - public CollectServer(final CollectJobService collectJobService, final TimerDispatch timerDispatch, final DispatchProperties properties, @@ -85,15 +84,15 @@ public CollectServer(final CollectJobService collectJobService, this.collectJobService = collectJobService; this.timerDispatch = timerDispatch; this.collectJobService.setCollectServer(this); - this.init(properties, threadPool, infoProperties); + this.infoProperties = infoProperties; + this.init(properties, threadPool); } - private void init(final DispatchProperties properties, final CommonThreadPool threadPool, final CollectorInfoProperties infoProperties) { + private void init(final DispatchProperties properties, final CommonThreadPool threadPool) { NettyClientConfig nettyClientConfig = new NettyClientConfig(); DispatchProperties.EntranceProperties.NettyProperties nettyProperties = properties.getEntrance().getNetty(); nettyClientConfig.setServerHost(nettyProperties.getManagerHost()); nettyClientConfig.setServerPort(nettyProperties.getManagerPort()); - this.initInfo(infoProperties); this.remotingClient = new NettyRemotingClient(nettyClientConfig, new CollectNettyEventListener(), threadPool); this.remotingClient.registerProcessor(ClusterMsg.MessageType.HEARTBEAT, new HeartbeatProcessor()); @@ -135,9 +134,9 @@ public void onChannelActive(Channel channel) { String mode = CollectServer.this.collectJobService.getCollectorMode(); CollectorInfo collectorInfo = CollectorInfo.builder() .name(identity) - .ip(info.ip) + .ip(infoProperties.getIp()) .mode(mode) - .version(info.version) + .version(infoProperties.getVersion()) // todo more info .build(); timerDispatch.goOnline(); @@ -181,23 +180,4 @@ public void onChannelIdle(Channel channel) { log.info("handle idle event triggered. collector is going offline."); } } - - private void initInfo(final CollectorInfoProperties infoProperties) { - info = new Info(); - info.setVersion(infoProperties.getVersion()); - info.setIp(IpDomainUtil.getIpFromEnvOrDefault(infoProperties.getIp(), IpDomainUtil.getLocalhostIp())); - } - - private static class Info { - private String version; - private String ip; - - public void setVersion(String version) { - this.version = version; - } - - public void setIp(String ip) { - this.ip = ip; - } - } } diff --git a/collector/src/main/resources/application.yml b/collector/src/main/resources/application.yml index 24ebef57cee..13d52e92bfa 100644 --- a/collector/src/main/resources/application.yml +++ b/collector/src/main/resources/application.yml @@ -39,8 +39,8 @@ spring: collector: info: - version: 1.5.0 - ip: IP + version: ${COLLECTOR_VERSION:1.6.0} + ip: ${COLLECTOR_IP:} dispatch: entrance: netty: diff --git a/common/src/main/java/org/apache/hertzbeat/common/entity/dto/CollectorInfo.java b/common/src/main/java/org/apache/hertzbeat/common/entity/dto/CollectorInfo.java index a9529af4579..7c5a889e8cb 100644 --- a/common/src/main/java/org/apache/hertzbeat/common/entity/dto/CollectorInfo.java +++ b/common/src/main/java/org/apache/hertzbeat/common/entity/dto/CollectorInfo.java @@ -38,7 +38,6 @@ public class CollectorInfo { @NotNull private String name; - @NotNull private String ip; private String version; diff --git a/common/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java b/common/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java index a29badfc1a7..21d8d57dea1 100644 --- a/common/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java +++ b/common/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java @@ -106,11 +106,7 @@ public static String getLocalhostIp() { } return null; } - - public static String getIpFromEnvOrDefault(String env, String defaultIp) { - return System.getenv().getOrDefault(env, defaultIp); - } - + /** * * @param ipDomain ip domain diff --git a/home/docs/introduce.md b/home/docs/introduce.md index d559fa6ca34..98305d95ed5 100644 --- a/home/docs/introduce.md +++ b/home/docs/introduce.md @@ -11,7 +11,7 @@ slug: / [![Reddit](https://img.shields.io/badge/Reddit-Community-7289DA?logo=reddit)](https://www.reddit.com/r/hertzbeat/) [![Twitter](https://img.shields.io/twitter/follow/hertzbeat1024?logo=twitter)](https://twitter.com/hertzbeat1024) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8139/badge)](https://www.bestpractices.dev/projects/8139) -[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/repository/docker/apache/hertzbeat/general) +[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/r/apache/hertzbeat) [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/hertzbeat)](https://artifacthub.io/packages/search?repo=hertzbeat) [![QQ](https://img.shields.io/badge/QQ-630061200-orange)](https://qm.qq.com/q/FltGGGIX2m) [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCri75zfWX0GHqJFPENEbLow?logo=youtube&label=YouTube%20Channel)](https://www.youtube.com/channel/UCri75zfWX0GHqJFPENEbLow) diff --git a/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/introduce.md b/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/introduce.md index 4faa4312308..cd0274a5f98 100644 --- a/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/introduce.md +++ b/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/introduce.md @@ -11,7 +11,7 @@ slug: / [![Reddit](https://img.shields.io/badge/Reddit-Community-7289DA?logo=reddit)](https://www.reddit.com/r/hertzbeat/) [![Twitter](https://img.shields.io/twitter/follow/hertzbeat1024?logo=twitter)](https://twitter.com/hertzbeat1024) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8139/badge)](https://www.bestpractices.dev/projects/8139) -[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/repository/docker/apache/hertzbeat/general) +[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/r/apache/hertzbeat) [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/hertzbeat)](https://artifacthub.io/packages/search?repo=hertzbeat) [![QQ](https://img.shields.io/badge/QQ-630061200-orange)](https://qm.qq.com/q/FltGGGIX2m) [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCri75zfWX0GHqJFPENEbLow?logo=youtube&label=YouTube%20Channel)](https://www.youtube.com/channel/UCri75zfWX0GHqJFPENEbLow) diff --git a/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-v1.4.x/introduce.md b/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-v1.4.x/introduce.md index ac4a9dc2e5e..b9767924b38 100644 --- a/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-v1.4.x/introduce.md +++ b/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-v1.4.x/introduce.md @@ -11,7 +11,7 @@ slug: / [![Reddit](https://img.shields.io/badge/Reddit-Community-7289DA?logo=reddit)](https://www.reddit.com/r/hertzbeat/) [![Twitter](https://img.shields.io/twitter/follow/hertzbeat1024?logo=twitter)](https://twitter.com/hertzbeat1024) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8139/badge)](https://www.bestpractices.dev/projects/8139) -[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/repository/docker/apache/hertzbeat/general) +[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/r/apache/hertzbeat) [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/hertzbeat)](https://artifacthub.io/packages/search?repo=hertzbeat) [![QQ](https://img.shields.io/badge/QQ-630061200-orange)](https://qm.qq.com/q/FltGGGIX2m) [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCri75zfWX0GHqJFPENEbLow?logo=youtube&label=YouTube%20Channel)](https://www.youtube.com/channel/UCri75zfWX0GHqJFPENEbLow) diff --git a/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-v1.5.x/introduce.md b/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-v1.5.x/introduce.md index 4faa4312308..cd0274a5f98 100644 --- a/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-v1.5.x/introduce.md +++ b/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-v1.5.x/introduce.md @@ -11,7 +11,7 @@ slug: / [![Reddit](https://img.shields.io/badge/Reddit-Community-7289DA?logo=reddit)](https://www.reddit.com/r/hertzbeat/) [![Twitter](https://img.shields.io/twitter/follow/hertzbeat1024?logo=twitter)](https://twitter.com/hertzbeat1024) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8139/badge)](https://www.bestpractices.dev/projects/8139) -[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/repository/docker/apache/hertzbeat/general) +[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/r/apache/hertzbeat) [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/hertzbeat)](https://artifacthub.io/packages/search?repo=hertzbeat) [![QQ](https://img.shields.io/badge/QQ-630061200-orange)](https://qm.qq.com/q/FltGGGIX2m) [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCri75zfWX0GHqJFPENEbLow?logo=youtube&label=YouTube%20Channel)](https://www.youtube.com/channel/UCri75zfWX0GHqJFPENEbLow) diff --git a/home/src/pages/team/index.jsx b/home/src/pages/team/index.jsx index 24ae677e472..c41eaeff6f3 100644 --- a/home/src/pages/team/index.jsx +++ b/home/src/pages/team/index.jsx @@ -1079,6 +1079,14 @@ export default function () { src="https://avatars.githubusercontent.com/u/45332412?v=4?s=100" width="100px;" alt="Leon Li"/>
Leon Li
💻 + dennis zhuang
dennis zhuang

💻 + Kerwin Bryant
Kerwin + Bryant

💻 diff --git a/home/versioned_docs/version-v1.4.x/introduce.md b/home/versioned_docs/version-v1.4.x/introduce.md index a72703e6a33..63a35e80ab9 100644 --- a/home/versioned_docs/version-v1.4.x/introduce.md +++ b/home/versioned_docs/version-v1.4.x/introduce.md @@ -11,7 +11,7 @@ slug: / [![Reddit](https://img.shields.io/badge/Reddit-Community-7289DA?logo=reddit)](https://www.reddit.com/r/hertzbeat/) [![Twitter](https://img.shields.io/twitter/follow/hertzbeat1024?logo=twitter)](https://twitter.com/hertzbeat1024) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8139/badge)](https://www.bestpractices.dev/projects/8139) -[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/repository/docker/apache/hertzbeat/general) +[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/r/apache/hertzbeat) [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/hertzbeat)](https://artifacthub.io/packages/search?repo=hertzbeat) [![QQ](https://img.shields.io/badge/QQ-630061200-orange)](https://qm.qq.com/q/FltGGGIX2m) [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCri75zfWX0GHqJFPENEbLow?logo=youtube&label=YouTube%20Channel)](https://www.youtube.com/channel/UCri75zfWX0GHqJFPENEbLow) diff --git a/home/versioned_docs/version-v1.5.x/introduce.md b/home/versioned_docs/version-v1.5.x/introduce.md index d559fa6ca34..98305d95ed5 100644 --- a/home/versioned_docs/version-v1.5.x/introduce.md +++ b/home/versioned_docs/version-v1.5.x/introduce.md @@ -11,7 +11,7 @@ slug: / [![Reddit](https://img.shields.io/badge/Reddit-Community-7289DA?logo=reddit)](https://www.reddit.com/r/hertzbeat/) [![Twitter](https://img.shields.io/twitter/follow/hertzbeat1024?logo=twitter)](https://twitter.com/hertzbeat1024) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8139/badge)](https://www.bestpractices.dev/projects/8139) -[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/repository/docker/apache/hertzbeat/general) +[![Docker Pulls](https://img.shields.io/docker/pulls/apache/hertzbeat?style=%20for-the-badge&logo=docker&label=DockerHub%20Download)](https://hub.docker.com/r/apache/hertzbeat) [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/hertzbeat)](https://artifacthub.io/packages/search?repo=hertzbeat) [![QQ](https://img.shields.io/badge/QQ-630061200-orange)](https://qm.qq.com/q/FltGGGIX2m) [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCri75zfWX0GHqJFPENEbLow?logo=youtube&label=YouTube%20Channel)](https://www.youtube.com/channel/UCri75zfWX0GHqJFPENEbLow) diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/scheduler/netty/process/CollectorOnlineProcessor.java b/manager/src/main/java/org/apache/hertzbeat/manager/scheduler/netty/process/CollectorOnlineProcessor.java index 66f7d62a7c9..ab48b220380 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/scheduler/netty/process/CollectorOnlineProcessor.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/scheduler/netty/process/CollectorOnlineProcessor.java @@ -18,12 +18,14 @@ package org.apache.hertzbeat.manager.scheduler.netty.process; import io.netty.channel.ChannelHandlerContext; +import java.net.InetSocketAddress; import lombok.extern.slf4j.Slf4j; import org.apache.hertzbeat.common.entity.dto.CollectorInfo; import org.apache.hertzbeat.common.entity.message.ClusterMsg; import org.apache.hertzbeat.common.util.JsonUtil; import org.apache.hertzbeat.manager.scheduler.netty.ManageServer; import org.apache.hertzbeat.remoting.netty.NettyRemotingProcessor; +import org.springframework.util.StringUtils; /** * handle collector online message @@ -41,6 +43,12 @@ public ClusterMsg.Message handle(ChannelHandlerContext ctx, ClusterMsg.Message m String collector = message.getIdentity(); log.info("the collector {} actively requests to go online.", collector); CollectorInfo collectorInfo = JsonUtil.fromJson(message.getMsg(), CollectorInfo.class); + if (collectorInfo != null && !StringUtils.hasText(collectorInfo.getIp())) { + // fetch remote ip address + InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress(); + String clientIP = socketAddress.getAddress().getHostAddress(); + collectorInfo.setIp(clientIP); + } this.manageServer.addChannel(collector, ctx.channel()); this.manageServer.getCollectorAndJobScheduler().collectorGoOnline(collector, collectorInfo); return null;