diff --git a/collector/collector-basic/pom.xml b/collector/collector-basic/pom.xml
index 805bccb24d4..5a32d27b1b4 100644
--- a/collector/collector-basic/pom.xml
+++ b/collector/collector-basic/pom.xml
@@ -125,18 +125,6 @@
dnsjava
${dnsjava.version}
-
-
- com.ecwid.consul
- consul-api
- ${consul-api.version}
-
-
-
- com.alibaba.nacos
- nacos-client
- ${nacos-client.version}
-
com.hivemq
diff --git a/collector/collector-discovery/pom.xml b/collector/collector-discovery/pom.xml
new file mode 100644
index 00000000000..337425773a9
--- /dev/null
+++ b/collector/collector-discovery/pom.xml
@@ -0,0 +1,57 @@
+
+
+
+ 4.0.0
+
+ org.apache.hertzbeat
+ hertzbeat-collector
+ 2.0-SNAPSHOT
+
+
+ hertzbeat-collector-discovery
+ ${project.artifactId}
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+ org.apache.hertzbeat
+ hertzbeat-collector-common
+ provided
+
+
+
+ com.ecwid.consul
+ consul-api
+ ${consul-api.version}
+
+
+
+ com.alibaba.nacos
+ nacos-client
+ ${nacos-client.version}
+
+
+
+
diff --git a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/DiscoveryClient.java b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/DiscoveryClient.java
similarity index 75%
rename from collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/DiscoveryClient.java
rename to collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/DiscoveryClient.java
index b6329996766..301345d4d81 100644
--- a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/DiscoveryClient.java
+++ b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/DiscoveryClient.java
@@ -17,13 +17,14 @@
* under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd.discovery;
+package org.apache.hertzbeat.collector.collect.discovery;
import java.util.List;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ConnectConfig;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ServerInfo;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ServiceInstance;
-import org.apache.hertzbeat.common.entity.job.protocol.HttpsdProtocol;
+
+import org.apache.hertzbeat.collector.collect.discovery.entity.ConnectConfig;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ServerInfo;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ServiceInstance;
+import org.apache.hertzbeat.common.entity.job.protocol.DiscoveryProtocol;
/**
* DiscoveryClient interface.
@@ -32,10 +33,10 @@ public interface DiscoveryClient extends AutoCloseable {
/**
* Build connect config.
- * @param httpsdProtocol httpsd protocol.
+ * @param discoveryProtocol discovery protocol.
* @return connect config object.
*/
- ConnectConfig buildConnectConfig(HttpsdProtocol httpsdProtocol);
+ ConnectConfig buildConnectConfig(DiscoveryProtocol discoveryProtocol);
/**
* Initialize client.
diff --git a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/DiscoveryClientManagement.java b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/DiscoveryClientManagement.java
similarity index 65%
rename from collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/DiscoveryClientManagement.java
rename to collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/DiscoveryClientManagement.java
index 493658d5316..bbc7751069b 100644
--- a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/DiscoveryClientManagement.java
+++ b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/DiscoveryClientManagement.java
@@ -17,39 +17,39 @@
* under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd.discovery;
+package org.apache.hertzbeat.collector.collect.discovery;
import java.util.Objects;
-import org.apache.hertzbeat.collector.collect.httpsd.constant.DiscoveryClientInstance;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.impl.ConsulDiscoveryClient;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.impl.NacosDiscoveryClient;
-import org.apache.hertzbeat.common.entity.job.protocol.HttpsdProtocol;
+import org.apache.hertzbeat.collector.collect.discovery.constant.DiscoveryClientInstance;
+import org.apache.hertzbeat.collector.collect.discovery.impl.ConsulDiscoveryClient;
+import org.apache.hertzbeat.collector.collect.discovery.impl.NacosDiscoveryClient;
+import org.apache.hertzbeat.common.entity.job.protocol.DiscoveryProtocol;
/**
* Discovery Client Management
*/
public class DiscoveryClientManagement {
- public DiscoveryClient getClient(HttpsdProtocol httpsdProtocol) {
+ public DiscoveryClient getClient(DiscoveryProtocol httpsdProtocol) {
return createClient(httpsdProtocol, DiscoveryClientInstance.getByName(httpsdProtocol.getDiscoveryClientTypeName()));
}
- private DiscoveryClient createClient(HttpsdProtocol httpsdProtocol, DiscoveryClientInstance discoveryClientInstance) {
+ private DiscoveryClient createClient(DiscoveryProtocol discoveryProtocol, DiscoveryClientInstance discoveryClientInstance) {
if (Objects.equals(discoveryClientInstance, DiscoveryClientInstance.NOT_SUPPORT)) {
return null;
}
- return doCreateClient(httpsdProtocol, discoveryClientInstance);
+ return doCreateClient(discoveryProtocol, discoveryClientInstance);
}
- private DiscoveryClient doCreateClient(HttpsdProtocol httpsdProtocol, DiscoveryClientInstance discoveryClientInstance) {
+ private DiscoveryClient doCreateClient(DiscoveryProtocol discoveryProtocol, DiscoveryClientInstance discoveryClientInstance) {
DiscoveryClient discoveryClient;
switch (discoveryClientInstance) {
case CONSUL -> discoveryClient = new ConsulDiscoveryClient();
case NACOS -> discoveryClient = new NacosDiscoveryClient();
default -> { return null; }
}
- discoveryClient.initClient(discoveryClient.buildConnectConfig(httpsdProtocol));
+ discoveryClient.initClient(discoveryClient.buildConnectConfig(discoveryProtocol));
return discoveryClient;
}
}
diff --git a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/HttpsdImpl.java b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/DiscoveryImpl.java
similarity index 85%
rename from collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/HttpsdImpl.java
rename to collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/DiscoveryImpl.java
index 92d494ca7d8..c91ff2be3fb 100644
--- a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/HttpsdImpl.java
+++ b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/DiscoveryImpl.java
@@ -17,32 +17,32 @@
* under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd;
+package org.apache.hertzbeat.collector.collect.discovery;
-import com.ecwid.consul.transport.TransportException;
-import com.google.common.annotations.VisibleForTesting;
import java.lang.reflect.Field;
import java.util.Objects;
+
+import com.ecwid.consul.transport.TransportException;
+import com.google.common.annotations.VisibleForTesting;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.collector.collect.AbstractCollect;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.DiscoveryClient;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.DiscoveryClientManagement;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ServerInfo;
import org.apache.hertzbeat.collector.constants.CollectorConstants;
import org.apache.hertzbeat.collector.dispatch.DispatchConstants;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ServerInfo;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.job.Metrics;
-import org.apache.hertzbeat.common.entity.job.protocol.HttpsdProtocol;
import org.apache.hertzbeat.common.entity.message.CollectRep;
import org.apache.hertzbeat.common.util.CommonUtil;
/**
- * http_sd protocol collection implementation
+ * Discovery collect implementation
*/
+
@Slf4j
-public class HttpsdImpl extends AbstractCollect {
+public class DiscoveryImpl extends AbstractCollect {
+
private static final String SERVER = "server";
@Setter
@@ -51,17 +51,17 @@ public class HttpsdImpl extends AbstractCollect {
@Override
public void preCheck(Metrics metrics) throws IllegalArgumentException {
- HttpsdProtocol httpsdProtocol = metrics.getHttpsd();
- if (Objects.isNull(httpsdProtocol) || httpsdProtocol.isInvalid()){
+ var discoveryProtocol = metrics.getDiscovery();
+ if (Objects.isNull(discoveryProtocol) || discoveryProtocol.isInvalid()){
throw new IllegalArgumentException("http_sd collect must have a valid http_sd protocol param! ");
}
}
@Override
public void collect(CollectRep.MetricsData.Builder builder, long monitorId, String app, Metrics metrics) {
- HttpsdProtocol httpsdProtocol = metrics.getHttpsd();
+ var discoveryProtocol = metrics.getDiscovery();
- try (DiscoveryClient discoveryClient = discoveryClientManagement.getClient(httpsdProtocol)) {
+ try (DiscoveryClient discoveryClient = discoveryClientManagement.getClient(discoveryProtocol)) {
collectMetrics(builder, metrics, discoveryClient);
} catch (TransportException e1) {
String errorMsg = "Consul " + CommonUtil.getMessageFromThrowable(e1);
@@ -106,10 +106,6 @@ public String supportProtocol() {
return DispatchConstants.PROTOCOL_HTTP_SD;
}
- private boolean checkParamsFailed(HttpsdProtocol httpsd) {
- return Objects.isNull(httpsd) || httpsd.isInvalid();
- }
-
private void addColumnIfMatched(String fieldName, Object sourceObj, CollectRep.ValueRow.Builder valueRowBuilder) {
String columnValue = null;
try {
diff --git a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/constant/DiscoveryClientHealthStatus.java b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/constant/DiscoveryClientHealthStatus.java
similarity index 94%
rename from collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/constant/DiscoveryClientHealthStatus.java
rename to collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/constant/DiscoveryClientHealthStatus.java
index 4f113bfd20e..d4f7788b532 100644
--- a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/constant/DiscoveryClientHealthStatus.java
+++ b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/constant/DiscoveryClientHealthStatus.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd.constant;
+package org.apache.hertzbeat.collector.collect.discovery.constant;
/**
* Discovery client instance status.
diff --git a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/constant/DiscoveryClientInstance.java b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/constant/DiscoveryClientInstance.java
similarity index 95%
rename from collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/constant/DiscoveryClientInstance.java
rename to collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/constant/DiscoveryClientInstance.java
index 3d34fe11306..c548f74fd78 100644
--- a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/constant/DiscoveryClientInstance.java
+++ b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/constant/DiscoveryClientInstance.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd.constant;
+package org.apache.hertzbeat.collector.collect.discovery.constant;
import java.util.Arrays;
import org.apache.commons.lang3.StringUtils;
diff --git a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/entity/ConnectConfig.java b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/entity/ConnectConfig.java
similarity index 93%
rename from collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/entity/ConnectConfig.java
rename to collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/entity/ConnectConfig.java
index 68bb93f067f..f8620ee11e5 100644
--- a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/entity/ConnectConfig.java
+++ b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/entity/ConnectConfig.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd.discovery.entity;
+package org.apache.hertzbeat.collector.collect.discovery.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
diff --git a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/entity/ServerInfo.java b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/entity/ServerInfo.java
similarity index 93%
rename from collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/entity/ServerInfo.java
rename to collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/entity/ServerInfo.java
index 52e23621bca..e4643b16800 100644
--- a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/entity/ServerInfo.java
+++ b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/entity/ServerInfo.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd.discovery.entity;
+package org.apache.hertzbeat.collector.collect.discovery.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
diff --git a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/entity/ServiceInstance.java b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/entity/ServiceInstance.java
similarity index 94%
rename from collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/entity/ServiceInstance.java
rename to collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/entity/ServiceInstance.java
index b0d26fb571c..b50ffbbc29f 100644
--- a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/entity/ServiceInstance.java
+++ b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/entity/ServiceInstance.java
@@ -17,9 +17,10 @@
* under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd.discovery.entity;
+package org.apache.hertzbeat.collector.collect.discovery.entity;
import java.util.Map;
+
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
diff --git a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/impl/ConsulDiscoveryClient.java b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/impl/ConsulDiscoveryClient.java
similarity index 84%
rename from collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/impl/ConsulDiscoveryClient.java
rename to collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/impl/ConsulDiscoveryClient.java
index 67ba993f555..c7d50eeb737 100644
--- a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/impl/ConsulDiscoveryClient.java
+++ b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/impl/ConsulDiscoveryClient.java
@@ -17,22 +17,23 @@
* under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd.discovery.impl;
+package org.apache.hertzbeat.collector.collect.discovery.impl;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.agent.model.Check;
import com.ecwid.consul.v1.agent.model.Self;
import com.ecwid.consul.v1.agent.model.Service;
import com.google.common.collect.Lists;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
+import org.apache.hertzbeat.collector.collect.discovery.DiscoveryClient;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ConnectConfig;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ServerInfo;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ServiceInstance;
import org.apache.commons.lang3.StringUtils;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.DiscoveryClient;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ConnectConfig;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ServerInfo;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ServiceInstance;
-import org.apache.hertzbeat.common.entity.job.protocol.HttpsdProtocol;
+import org.apache.hertzbeat.common.entity.job.protocol.DiscoveryProtocol;
/**
* DiscoveryClient impl of Consul
@@ -41,10 +42,10 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
private ConsulClient consulClient;
@Override
- public ConnectConfig buildConnectConfig(HttpsdProtocol httpsdProtocol) {
+ public ConnectConfig buildConnectConfig(DiscoveryProtocol discoveryProtocol) {
return ConnectConfig.builder()
- .host(httpsdProtocol.getHost())
- .port(Integer.parseInt(httpsdProtocol.getPort()))
+ .host(discoveryProtocol.getHost())
+ .port(Integer.parseInt(discoveryProtocol.getPort()))
.build();
}
diff --git a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/impl/NacosDiscoveryClient.java b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/impl/NacosDiscoveryClient.java
similarity index 85%
rename from collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/impl/NacosDiscoveryClient.java
rename to collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/impl/NacosDiscoveryClient.java
index 15838312485..43cb512f9fa 100644
--- a/collector/collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/httpsd/discovery/impl/NacosDiscoveryClient.java
+++ b/collector/collector-discovery/src/main/java/org/apache/hertzbeat/collector/collect/discovery/impl/NacosDiscoveryClient.java
@@ -17,22 +17,23 @@
* under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd.discovery.impl;
+package org.apache.hertzbeat.collector.collect.discovery.impl;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.google.common.collect.Lists;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
-import org.apache.hertzbeat.collector.collect.httpsd.constant.DiscoveryClientHealthStatus;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.DiscoveryClient;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ConnectConfig;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ServerInfo;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ServiceInstance;
-import org.apache.hertzbeat.common.entity.job.protocol.HttpsdProtocol;
+import org.apache.hertzbeat.collector.collect.discovery.DiscoveryClient;
+import org.apache.hertzbeat.collector.collect.discovery.constant.DiscoveryClientHealthStatus;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ConnectConfig;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ServerInfo;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ServiceInstance;
+import org.apache.hertzbeat.common.entity.job.protocol.DiscoveryProtocol;
/**
* DiscoveryClient impl of Nacos
@@ -43,10 +44,10 @@ public class NacosDiscoveryClient implements DiscoveryClient {
private ConnectConfig localConnectConfig;
@Override
- public ConnectConfig buildConnectConfig(HttpsdProtocol httpsdProtocol) {
+ public ConnectConfig buildConnectConfig(DiscoveryProtocol discoveryProtocol) {
return ConnectConfig.builder()
- .host(httpsdProtocol.getHost())
- .port(Integer.parseInt(httpsdProtocol.getPort()))
+ .host(discoveryProtocol.getHost())
+ .port(Integer.parseInt(discoveryProtocol.getPort()))
.build();
}
diff --git a/collector/collector-basic/src/test/java/org/apache/hertzbeat/collector/collect/httpsd/HttpsdImplTest.java b/collector/collector-discovery/src/test/java/org/apache/hertzbeat/collector/collect/discovery/test/DiscoveryImplTest.java
similarity index 66%
rename from collector/collector-basic/src/test/java/org/apache/hertzbeat/collector/collect/httpsd/HttpsdImplTest.java
rename to collector/collector-discovery/src/test/java/org/apache/hertzbeat/collector/collect/discovery/test/DiscoveryImplTest.java
index 6ebf95bdce5..bd79874c146 100644
--- a/collector/collector-basic/src/test/java/org/apache/hertzbeat/collector/collect/httpsd/HttpsdImplTest.java
+++ b/collector/collector-discovery/src/test/java/org/apache/hertzbeat/collector/collect/discovery/test/DiscoveryImplTest.java
@@ -15,19 +15,19 @@
* limitations under the License.
*/
-package org.apache.hertzbeat.collector.collect.httpsd;
+package org.apache.hertzbeat.collector.collect.discovery.test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.ArrayList;
import java.util.List;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.DiscoveryClient;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.DiscoveryClientManagement;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ServerInfo;
-import org.apache.hertzbeat.collector.collect.httpsd.discovery.entity.ServiceInstance;
+import org.apache.hertzbeat.collector.collect.discovery.DiscoveryImpl;
+import org.apache.hertzbeat.collector.collect.discovery.DiscoveryClient;
+import org.apache.hertzbeat.collector.collect.discovery.DiscoveryClientManagement;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ServerInfo;
+import org.apache.hertzbeat.collector.collect.discovery.entity.ServiceInstance;
import org.apache.hertzbeat.common.entity.job.Metrics;
-import org.apache.hertzbeat.common.entity.job.protocol.HttpsdProtocol;
+import org.apache.hertzbeat.common.entity.job.protocol.DiscoveryProtocol;
import org.apache.hertzbeat.common.entity.message.CollectRep;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@@ -37,13 +37,14 @@
import org.mockito.junit.jupiter.MockitoExtension;
/**
- * Test case for {@link HttpsdImpl}
+ * Test case for {@link DiscoveryImpl}
*/
@ExtendWith(MockitoExtension.class)
-class HttpsdImplTest {
+class DiscoveryImplTest {
+
@InjectMocks
@Spy
- private HttpsdImpl httpsd;
+ private DiscoveryImpl discovery;
@Mock
private DiscoveryClient client;
@@ -57,7 +58,7 @@ void testServerCollect() {
String port = "123";
String host = "127.0.0.1";
- HttpsdProtocol httpsdProtocol = HttpsdProtocol.builder()
+ var httpsdProtocol = DiscoveryProtocol.builder()
.port(port)
.host(host)
.discoveryClientTypeName("consul")
@@ -68,7 +69,7 @@ void testServerCollect() {
aliasField.add("responseTime");
Metrics metrics = new Metrics();
metrics.setName("server");
- metrics.setHttpsd(httpsdProtocol);
+ metrics.setDiscovery(httpsdProtocol);
metrics.setAliasFields(aliasField);
Mockito.when(discoveryClientManagement.getClient(httpsdProtocol)).thenReturn(client);
@@ -77,13 +78,13 @@ void testServerCollect() {
.port(port)
.build();
Mockito.when(client.getServerInfo()).thenReturn(serverInfo);
- httpsd.setDiscoveryClientManagement(discoveryClientManagement);
- httpsd.preCheck(metrics);
- httpsd.collect(builder, 1L, "test", metrics);
+ discovery.setDiscoveryClientManagement(discoveryClientManagement);
+ discovery.preCheck(metrics);
+ discovery.collect(builder, 1L, "test", metrics);
for (CollectRep.ValueRow valueRow : builder.getValuesList()) {
- assertEquals(host, valueRow.getColumns(0));
- assertEquals(port, valueRow.getColumns(1));
- assertNotNull(valueRow.getColumns(2));
+ Assertions.assertEquals(host, valueRow.getColumns(0));
+ Assertions.assertEquals(port, valueRow.getColumns(1));
+ Assertions.assertNotNull(valueRow.getColumns(2));
}
}
@@ -93,7 +94,7 @@ void testServiceCollect() {
String port = "123";
String host = "127.0.0.1";
- HttpsdProtocol httpsdProtocol = HttpsdProtocol.builder()
+ var discoveryProtocol = DiscoveryProtocol.builder()
.port(port)
.host(host)
.discoveryClientTypeName("consul")
@@ -105,10 +106,10 @@ void testServiceCollect() {
aliasField.add("port");
Metrics metrics = new Metrics();
metrics.setName("service");
- metrics.setHttpsd(httpsdProtocol);
+ metrics.setDiscovery(discoveryProtocol);
metrics.setAliasFields(aliasField);
- Mockito.when(discoveryClientManagement.getClient(httpsdProtocol)).thenReturn(client);
+ Mockito.when(discoveryClientManagement.getClient(discoveryProtocol)).thenReturn(client);
String serviceId = "test";
String serviceName = "service";
@@ -121,16 +122,16 @@ void testServiceCollect() {
.build());
Mockito.when(client.getServices()).thenReturn(serviceInstances);
- httpsd.setDiscoveryClientManagement(discoveryClientManagement);
- httpsd.preCheck(metrics);
- httpsd.collect(builder, 1L, "test", metrics);
- assertEquals(builder.getValuesCount(), 1);
+ discovery.setDiscoveryClientManagement(discoveryClientManagement);
+ discovery.preCheck(metrics);
+ discovery.collect(builder, 1L, "test", metrics);
+ Assertions.assertEquals(builder.getValuesCount(), 1);
for (CollectRep.ValueRow valueRow : builder.getValuesList()) {
- assertEquals(serviceId, valueRow.getColumns(0));
- assertEquals(serviceName, valueRow.getColumns(1));
- assertEquals(host, valueRow.getColumns(2));
- assertEquals(port, valueRow.getColumns(3));
+ Assertions.assertEquals(serviceId, valueRow.getColumns(0));
+ Assertions.assertEquals(serviceName, valueRow.getColumns(1));
+ Assertions.assertEquals(host, valueRow.getColumns(2));
+ Assertions.assertEquals(port, valueRow.getColumns(3));
}
}
-}
\ No newline at end of file
+}
diff --git a/collector/collector/pom.xml b/collector/collector/pom.xml
index e4e2801b1f8..d2b7b8ba824 100644
--- a/collector/collector/pom.xml
+++ b/collector/collector/pom.xml
@@ -63,6 +63,12 @@
${hertzbeat.version}
+
+ org.apache.hertzbeat
+ hertzbeat-collector-discovery
+ ${hertzbeat.version}
+
+
org.springframework.boot
diff --git a/collector/collector/src/main/resources/META-INF/services/org.apache.hertzbeat.collector.collect.AbstractCollect b/collector/collector/src/main/resources/META-INF/services/org.apache.hertzbeat.collector.collect.AbstractCollect
index 69b4076fe4f..badb4c377c8 100644
--- a/collector/collector/src/main/resources/META-INF/services/org.apache.hertzbeat.collector.collect.AbstractCollect
+++ b/collector/collector/src/main/resources/META-INF/services/org.apache.hertzbeat.collector.collect.AbstractCollect
@@ -20,7 +20,7 @@ org.apache.hertzbeat.collector.collect.nginx.NginxCollectImpl
org.apache.hertzbeat.collector.collect.memcached.MemcachedCollectImpl
org.apache.hertzbeat.collector.collect.nebulagraph.NebulaGraphCollectImpl
org.apache.hertzbeat.collector.collect.pop3.Pop3CollectImpl
-org.apache.hertzbeat.collector.collect.httpsd.HttpsdImpl
+org.apache.hertzbeat.collector.collect.discovery.DiscoveryImpl
org.apache.hertzbeat.collector.collect.redfish.RedfishCollectImpl
org.apache.hertzbeat.collector.collect.nebulagraph.NgqlCollectImpl
org.apache.hertzbeat.collector.collect.imap.ImapCollectImpl
diff --git a/collector/pom.xml b/collector/pom.xml
index d1dccb9d625..886e2c3167d 100644
--- a/collector/pom.xml
+++ b/collector/pom.xml
@@ -40,7 +40,8 @@
collector-mongodb
collector-nebulagraph
collector-rocketmq
-
+ collector-discovery
+
@@ -69,6 +70,11 @@
hertzbeat-collector-rocketmq
${hertzbeat.version}
+
+ org.apache.hertzbeat
+ hertzbeat-collector-discovery
+ ${hertzbeat.version}
+
@@ -77,13 +83,10 @@
org.apache.hertzbeat
hertzbeat-common
-
apache-${project.artifactId}-${hzb.version}
-
-
diff --git a/common/src/main/java/org/apache/hertzbeat/common/entity/job/Metrics.java b/common/src/main/java/org/apache/hertzbeat/common/entity/job/Metrics.java
index 37b96db3307..9a798cfc84c 100644
--- a/common/src/main/java/org/apache/hertzbeat/common/entity/job/Metrics.java
+++ b/common/src/main/java/org/apache/hertzbeat/common/entity/job/Metrics.java
@@ -28,10 +28,10 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.hertzbeat.common.entity.job.protocol.DiscoveryProtocol;
import org.apache.hertzbeat.common.entity.job.protocol.DnsProtocol;
import org.apache.hertzbeat.common.entity.job.protocol.FtpProtocol;
import org.apache.hertzbeat.common.entity.job.protocol.HttpProtocol;
-import org.apache.hertzbeat.common.entity.job.protocol.HttpsdProtocol;
import org.apache.hertzbeat.common.entity.job.protocol.IcmpProtocol;
import org.apache.hertzbeat.common.entity.job.protocol.ImapProtocol;
import org.apache.hertzbeat.common.entity.job.protocol.JdbcProtocol;
@@ -209,7 +209,7 @@ public class Metrics {
/**
* Monitoring configuration information using the public http_sd protocol
*/
- private HttpsdProtocol httpsd;
+ private DiscoveryProtocol discovery;
/**
* Monitoring configuration information using the public redfish protocol
*/
diff --git a/common/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpsdProtocol.java b/common/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DiscoveryProtocol.java
similarity index 95%
rename from common/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpsdProtocol.java
rename to common/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DiscoveryProtocol.java
index 94df4de175e..2bf164a8e42 100644
--- a/common/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpsdProtocol.java
+++ b/common/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DiscoveryProtocol.java
@@ -26,13 +26,14 @@
import org.apache.commons.lang3.StringUtils;
/**
- * Httpsd protocol
+ * Discovery protocol
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
-public class HttpsdProtocol {
+public class DiscoveryProtocol {
+
private String host;
private String port;
private String discoveryClientTypeName;
diff --git a/home/blog/2024-06-15-hertzbeat-v1.6.0.md b/home/blog/2024-06-15-hertzbeat-v1.6.0.md
index 8b13b01f293..dfd61b0bdf0 100644
--- a/home/blog/2024-06-15-hertzbeat-v1.6.0.md
+++ b/home/blog/2024-06-15-hertzbeat-v1.6.0.md
@@ -190,7 +190,7 @@ Upgrade Guide:
* [improve] Optimize websocket monitor by @LiuTianyou in
* [refactor] Split the WarehouseProperties class by @xuziyang in
-* [test] Add test for HttpsdImpl by @crossoverJie in
+* [test] Add test for Service Discovery by @crossoverJie in
* [fix] Fix the wrong comment by @xuziyang in
* [refactor] trans and use assert by @dukbong in
* [bugfix] modify the command in the mongodb monitoring template by @LiuTianyou in
diff --git a/home/i18n/zh-cn/docusaurus-plugin-content-blog/2024-06-15-hertzbeat-v1.6.0.md b/home/i18n/zh-cn/docusaurus-plugin-content-blog/2024-06-15-hertzbeat-v1.6.0.md
index 974381300de..c451a2fef44 100644
--- a/home/i18n/zh-cn/docusaurus-plugin-content-blog/2024-06-15-hertzbeat-v1.6.0.md
+++ b/home/i18n/zh-cn/docusaurus-plugin-content-blog/2024-06-15-hertzbeat-v1.6.0.md
@@ -190,7 +190,7 @@ keywords: [open source, monitoring, alerting]
- [feature] Add Apache Hbase RegionServer monitoring by @zhangshenghang in
- [improve] Optimize websocket monitor by @LiuTianyou in
- [refactor] Split the WarehouseProperties class by @xuziyang in
-- [test] Add test for HttpsdImpl by @crossoverJie in
+- [test] Add test for Service Discovery by @crossoverJie in
- [fix] Fix the wrong comment by @xuziyang in
- [refactor] trans and use assert by @dukbong in
- [bugfix] modify the command in the mongodb monitoring template by @LiuTianyou in
diff --git a/manager/src/main/resources/define/app-http_sd.yml b/manager/src/main/resources/define/app-http_sd.yml
index e3803b5c1b8..2c0b820dea9 100644
--- a/manager/src/main/resources/define/app-http_sd.yml
+++ b/manager/src/main/resources/define/app-http_sd.yml
@@ -16,16 +16,16 @@
# The monitoring type category:service-application service monitoring db-database monitoring mid-middleware custom-custom monitoring os-operating system monitoring
category: service
# The monitoring type eg: linux windows tomcat mysql aws...
-app: httpsd
+app: service-discovery
# The monitoring i18n name
name:
- zh-CN: HTTP SD监控
- en-US: HTTP SD MONITORS
+ zh-CN: Service Discovery 监控
+ en-US: Service Discovery MONITORS
# The description and help of this monitoring type
help:
- zh-CN: HertzBeat 对 HTTP SD 的相关指标进行监测。
- en-US: HertzBeat monitors related indicators of HTTP SD.
- zh-TW: HertzBeat對HTTP SD相關名額進行監測。
+ zh-CN: HertzBeat 对服务发现的相关指标进行监测。
+ en-US: HertzBeat monitors related indicators of service discovery.
+ zh-TW: HertzBeat對服務發現相關名額進行監測。
# Input params define for monitoring(render web ui by the definition)
params:
# field-param field key
@@ -89,8 +89,8 @@ metrics:
i18n:
zh-CN: 响应时间
en-US: Response Time
- protocol: httpsd
- httpsd:
+ protocol: discovery
+ discovery:
host: ^_^host^_^
port: ^_^port^_^
discoveryClientTypeName: ^_^discoveryClientTypeName^_^
@@ -127,8 +127,8 @@ metrics:
i18n:
zh-CN: 服务健康状态
en-US: Health Status
- protocol: httpsd
- httpsd:
+ protocol: discovery
+ discovery:
host: ^_^host^_^
port: ^_^port^_^
discoveryClientTypeName: ^_^discoveryClientTypeName^_^
diff --git a/pom.xml b/pom.xml
index 0c8039e2fb7..7f3b6ed0d03 100644
--- a/pom.xml
+++ b/pom.xml
@@ -154,7 +154,7 @@
4.9.4
3.5.2
1.4.5
- 2.2.1
+ 2.2.4
3.6.0
4.0.2
1.0.0