Skip to content

Commit

Permalink
feature: add column Version and Public Ip on Collector page
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin979 committed Jun 8, 2024
1 parent 8147bd2 commit d5366ec
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hertzbeat.collector.dispatch;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* Collector info configuration Properties
*/
@Component
@ConfigurationProperties(prefix = CollectorInfoProperties.INFO_PREFIX)
public class CollectorInfoProperties {
protected static final String INFO_PREFIX = "collector.info";

private String version;
private String publicIpEnv;

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getPublicIpEnv() {
return publicIpEnv;
}

public void setPublicIpEnv(String publicIpEnv) {
this.publicIpEnv = publicIpEnv;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.hertzbeat.collector.dispatch.CollectorInfoProperties;
import org.apache.hertzbeat.collector.dispatch.DispatchProperties;
import org.apache.hertzbeat.collector.dispatch.entrance.internal.CollectJobService;
import org.apache.hertzbeat.collector.dispatch.entrance.processor.CollectCyclicDataProcessor;
Expand Down Expand Up @@ -66,10 +67,13 @@ public class CollectServer implements CommandLineRunner {

private ScheduledExecutorService scheduledExecutor;

private Info info;

public CollectServer(final CollectJobService collectJobService,
final TimerDispatch timerDispatch,
final DispatchProperties properties,
final CommonThreadPool threadPool) {
final CommonThreadPool threadPool,
final CollectorInfoProperties infoProperties) {
if (properties == null || properties.getEntrance() == null || properties.getEntrance().getNetty() == null) {
log.error("init error, please config dispatch entrance netty props in application.yml");
throw new IllegalArgumentException("please config dispatch entrance netty props");
Expand All @@ -81,14 +85,15 @@ public CollectServer(final CollectJobService collectJobService,
this.collectJobService = collectJobService;
this.timerDispatch = timerDispatch;
this.collectJobService.setCollectServer(this);
this.init(properties, threadPool);
this.init(properties, threadPool, infoProperties);
}

private void init(final DispatchProperties properties, final CommonThreadPool threadPool) {
private void init(final DispatchProperties properties, final CommonThreadPool threadPool, final CollectorInfoProperties infoProperties) {
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());
Expand Down Expand Up @@ -132,6 +137,8 @@ public void onChannelActive(Channel channel) {
.name(identity)
.ip(IpDomainUtil.getLocalhostIp())
.mode(mode)
.publicIp(info.publicIp)
.version(info.version)
// todo more info
.build();
timerDispatch.goOnline();
Expand Down Expand Up @@ -175,4 +182,23 @@ 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.setPublicIp(IpDomainUtil.getIpFromEnvOrDefault(infoProperties.getPublicIpEnv(), IpDomainUtil.getLocalhostIp()));
}

private static class Info {
private String version;
private String publicIp;

public void setVersion(String version) {
this.version = version;
}

public void setPublicIp(String publicIp) {
this.publicIp = publicIp;
}
}
}
3 changes: 3 additions & 0 deletions collector/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ spring:
on-profile: cluster

collector:
info:
version: v1.5.1
public-ip-env: PUBLIC_IP
dispatch:
entrance:
netty:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public class CollectorInfo {

@NotNull
private String ip;


private String publicIp;

private String version;

@NotNull
private String mode = CommonConstants.MODE_PUBLIC;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public class Collector {
@NotNull
private String ip;

@Schema(title = "collector public ip", description = "collector remote public ip")
private String publicIp;

@Schema(title = "collector version", description = "collector version")
private String version;

@Schema(title = "collector status: 0-online 1-offline")
@Min(0)
private byte status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public static String getLocalhostIp() {
return null;
}

public static String getIpFromEnvOrDefault(String env, String defaultIp) {
return System.getenv().getOrDefault(env, defaultIp);
}

/**
*
* @param ipDomain ip domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public void collectorGoOnline(String identity, CollectorInfo collectorInfo) {
if (collectorInfo != null) {
collector.setIp(collectorInfo.getIp());
collector.setMode(collectorInfo.getMode());
collector.setPublicIp(collectorInfo.getPublicIp());
collector.setVersion(collectorInfo.getVersion());
}
} else {
if (collectorInfo == null) {
Expand All @@ -117,6 +119,8 @@ public void collectorGoOnline(String identity, CollectorInfo collectorInfo) {
.name(identity)
.ip(collectorInfo.getIp())
.mode(collectorInfo.getMode())
.publicIp(collectorInfo.getPublicIp())
.version(collectorInfo.getVersion())
.status(CommonConstants.COLLECTOR_STATUS_ONLINE)
.build();
}
Expand Down Expand Up @@ -267,6 +271,8 @@ public boolean onlineCollector(String identity) {
CollectorInfo collectorInfo = CollectorInfo.builder()
.name(collector.getName())
.ip(collector.getIp())
.publicIp(collector.getPublicIp())
.version(collector.getVersion())
.mode(collector.getMode())
.build();
this.collectorGoOnline(identity, collectorInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public class SchedulerInit implements CommandLineRunner {
private CollectJobScheduling collectJobScheduling;

private static final String MAIN_COLLECTOR_NODE_IP = "127.0.0.1";

private static final String DEFAULT_COLLECTOR_VERSION = "DEBUG";

@Autowired
private AppService appService;

Expand All @@ -84,6 +85,8 @@ public void run(String... args) throws Exception {
CollectorInfo collectorInfo = CollectorInfo.builder()
.name(CommonConstants.MAIN_COLLECTOR_NODE)
.ip(MAIN_COLLECTOR_NODE_IP)
.publicIp(MAIN_COLLECTOR_NODE_IP)
.version(DEFAULT_COLLECTOR_VERSION)
.build();
collectorScheduling.collectorGoOnline(CommonConstants.MAIN_COLLECTOR_NODE, collectorInfo);
// init jobs
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/app/pojo/Collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class Collector {
id!: number;
name!: string;
ip!: string;
publicIp!: string;
version!: string;
// public or private
mode!: string;
// collector status: 0-online 1-offline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
<th nzAlign="center" nzWidth="9%">{{ 'collector.pinned' | i18n }}</th>
<th nzAlign="center" nzWidth="9%">{{ 'collector.dispatched' | i18n }}</th>
<th nzAlign="center" nzWidth="12%">{{ 'collector.ip' | i18n }}</th>
<th nzAlign="center" nzWidth="12%">{{ 'collector.publicIp' | i18n }}</th>
<th nzAlign="center" nzWidth="12%">{{ 'collector.version' | i18n }}</th>
<th nzAlign="center" nzWidth="12%">{{ 'collector.start-time' | i18n }}</th>
<th nzAlign="center" nzWidth="13%">{{ 'common.edit' | i18n }}</th>
</tr>
Expand Down Expand Up @@ -130,6 +132,8 @@
</nz-tag>
</td>
<td nzAlign="center">{{ data.collector.ip }}</td>
<td nzAlign="center">{{ data.collector.publicIp }}</td>
<td nzAlign="center">{{ data.collector.version }}</td>
<td nzAlign="center">
{{ (data.collector.gmtUpdate | date : 'YYYY-MM-dd HH:mm:ss')?.trim() }}
</td>
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@
"collector.task": "Total Tasks",
"collector.start-time": "Start Time",
"collector.ip": "IP Address",
"collector.publicIp": "Public IP Address",
"collector.version": "Version",
"collector.node": "Node Name",
"collector.pinned": "Pinned Tasks",
"collector.dispatched": "Dispatched Tasks",
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/assets/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@
"collector.task": "总任务数量",
"collector.start-time": "启动时间",
"collector.ip": "IP地址",
"collector.publicIp": "公网IP地址",
"collector.version": "版本",
"collector.node": "节点名称",
"collector.pinned": "固定任务",
"collector.dispatched": "调度任务",
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/assets/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@
"collector.mode.private": "私有云邊模式",
"collector.start-time": "啟動時間",
"collector.ip": "IP地址",
"collector.publicIp": "公網IP地址",
"collector.version": "版本",
"collector.node": "節點名稱",
"collector.pinned": "固定任務",
"collector.dispatched": "調度任務",
Expand Down

0 comments on commit d5366ec

Please sign in to comment.