Skip to content

Commit

Permalink
[feature] add column version and public Ip on collector page (#2072)
Browse files Browse the repository at this point in the history
Co-authored-by: tomsun28 <[email protected]>
  • Loading branch information
Calvin979 and tomsun28 authored Jun 16, 2024
1 parent b8f2bf3 commit b7217b5
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 6 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 ip;

public String getVersion() {
return version;
}

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

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}
}
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 @@ -130,8 +135,9 @@ public void onChannelActive(Channel channel) {
String mode = CollectServer.this.collectJobService.getCollectorMode();
CollectorInfo collectorInfo = CollectorInfo.builder()
.name(identity)
.ip(IpDomainUtil.getLocalhostIp())
.ip(info.ip)
.mode(mode)
.version(info.version)
// todo more info
.build();
timerDispatch.goOnline();
Expand Down Expand Up @@ -175,4 +181,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.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;
}
}
}
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: 1.5.0
ip: IP
dispatch:
entrance:
netty:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public class CollectorInfo {

@NotNull
private String ip;


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,9 @@ public class Collector {
@NotNull
private String ip;

@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,7 @@ public void collectorGoOnline(String identity, CollectorInfo collectorInfo) {
if (collectorInfo != null) {
collector.setIp(collectorInfo.getIp());
collector.setMode(collectorInfo.getMode());
collector.setVersion(collectorInfo.getVersion());
}
} else {
if (collectorInfo == null) {
Expand All @@ -117,6 +118,7 @@ public void collectorGoOnline(String identity, CollectorInfo collectorInfo) {
.name(identity)
.ip(collectorInfo.getIp())
.mode(collectorInfo.getMode())
.version(collectorInfo.getVersion())
.status(CommonConstants.COLLECTOR_STATUS_ONLINE)
.build();
}
Expand Down Expand Up @@ -267,6 +269,7 @@ public boolean onlineCollector(String identity) {
CollectorInfo collectorInfo = CollectorInfo.builder()
.name(collector.getName())
.ip(collector.getIp())
.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,7 @@ public void run(String... args) throws Exception {
CollectorInfo collectorInfo = CollectorInfo.builder()
.name(CommonConstants.MAIN_COLLECTOR_NODE)
.ip(MAIN_COLLECTOR_NODE_IP)
.version(DEFAULT_COLLECTOR_VERSION)
.build();
collectorScheduling.collectorGoOnline(CommonConstants.MAIN_COLLECTOR_NODE, collectorInfo);
// init jobs
Expand Down
1 change: 1 addition & 0 deletions web-app/src/app/pojo/Collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class Collector {
id!: number;
name!: string;
ip!: 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,7 @@
<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.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 +131,7 @@
</nz-tag>
</td>
<td nzAlign="center">{{ data.collector.ip }}</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
1 change: 1 addition & 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,7 @@
"collector.task": "Total Tasks",
"collector.start-time": "Start Time",
"collector.ip": "IP Address",
"collector.version": "Version",
"collector.node": "Node Name",
"collector.pinned": "Pinned Tasks",
"collector.dispatched": "Dispatched Tasks",
Expand Down
1 change: 1 addition & 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,7 @@
"collector.task": "总任务数量",
"collector.start-time": "启动时间",
"collector.ip": "IP地址",
"collector.version": "版本",
"collector.node": "节点名称",
"collector.pinned": "固定任务",
"collector.dispatched": "调度任务",
Expand Down
1 change: 1 addition & 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,7 @@
"collector.mode.private": "私有云邊模式",
"collector.start-time": "啟動時間",
"collector.ip": "IP地址",
"collector.version": "版本",
"collector.node": "節點名稱",
"collector.pinned": "固定任務",
"collector.dispatched": "調度任務",
Expand Down

0 comments on commit b7217b5

Please sign in to comment.