Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support for batch creating task through http_sd #2018

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fb67763
feature: http_sd
Calvin979 May 19, 2024
96e0f6e
feature: batch create monitor through one time http_sd job
Calvin979 May 19, 2024
b27b66e
feature: batch create task through http_sd
Calvin979 May 20, 2024
3471c42
feature: batch create task through http_sd
Calvin979 May 20, 2024
97b2047
Merge remote-tracking branch 'origin/master' into feature/http_sd
Calvin979 May 23, 2024
dcdb0fe
fixed: resolve conflict
Calvin979 May 23, 2024
a97761e
fixed: resolve conflict
Calvin979 May 23, 2024
b925cf4
Merge remote-tracking branch 'origin/master' into feature/http_sd
Calvin979 May 23, 2024
e9d715e
Merge remote-tracking branch 'origin/master' into feature/http_sd
Calvin979 May 24, 2024
dd4a98b
fixed: resolve conflict
Calvin979 May 24, 2024
f9f718e
Merge branch 'master' into feature/http_sd
tomsun28 Jun 12, 2024
91dd6b6
Merge branch 'master' into feature/http_sd
tomsun28 Jun 15, 2024
9f355c9
Merge branch 'master' into feature/http_sd
tomsun28 Jun 16, 2024
6b67f85
Merge branch 'master' into feature/http_sd
Calvin979 Jul 13, 2024
fefa867
[refactor] resolve conflict
Calvin979 Jul 13, 2024
ce4927b
[feature] auto create monitor by sd
Calvin979 Jul 14, 2024
4c7a2ae
[feature] auto create monitor by sd
Calvin979 Jul 14, 2024
da8fbb9
[feature] auto create monitor by sd
Calvin979 Jul 19, 2024
7f57fd9
Merge branch 'master' into feature/http_sd
Calvin979 Aug 1, 2024
2d2b7b2
[improve] resolve conflict
Calvin979 Aug 1, 2024
73c07bf
Merge branch 'master' into feature/http_sd
tomsun28 Aug 2, 2024
f1f7398
Merge branch 'refs/heads/master' into feature/http_sd
Calvin979 Aug 29, 2024
d474ef3
[improve] resolve conflict
Calvin979 Aug 29, 2024
6a02d43
Merge branch 'master' into feature/http_sd
Calvin979 Aug 30, 2024
9672b5b
Merge branch 'master' into feature/http_sd
Aias00 Sep 2, 2024
7734999
Merge branch 'master' into feature/http_sd
Aias00 Sep 3, 2024
3f2cd71
Merge remote-tracking branch 'origin/master' into feature/http_sd
Calvin979 Sep 6, 2024
ea0c6a0
[refactor] resolve conflict and fix npt of deleteGrafanaDashboard
Calvin979 Sep 6, 2024
d1dbb63
Merge branch 'master' into feature/http_sd
Calvin979 Sep 8, 2024
8036479
Merge branch 'master' into feature/http_sd
Calvin979 Sep 10, 2024
80e3f8d
Merge branch 'master' into feature/http_sd
Calvin979 Sep 11, 2024
6ef1134
Merge branch 'master' into feature/http_sd
Aias00 Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.hertzbeat.collector.collect.httpsd;
package org.apache.hertzbeat.collector.collect.registry;

import com.ecwid.consul.transport.TransportException;
import com.google.common.annotations.VisibleForTesting;
Expand All @@ -27,22 +27,22 @@
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.registry.discovery.DiscoveryClient;
import org.apache.hertzbeat.collector.collect.registry.discovery.DiscoveryClientManagement;
import org.apache.hertzbeat.collector.collect.registry.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.job.protocol.RegistryProtocol;
import org.apache.hertzbeat.common.entity.message.CollectRep;
import org.apache.hertzbeat.common.util.CommonUtil;

/**
* http_sd protocol collection implementation
* registry protocol collection implementation
*/
@Slf4j
public class HttpsdImpl extends AbstractCollect {
public class RegistryImpl extends AbstractCollect {
private static final String SERVER = "server";

@Setter
Expand All @@ -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()){
throw new IllegalArgumentException("http_sd collect must have a valid http_sd protocol param! ");
RegistryProtocol registryProtocol = metrics.getRegistry();
if (Objects.isNull(registryProtocol) || registryProtocol.isInvalid()){
throw new IllegalArgumentException("registry collect must have a valid registry protocol param! ");
}
}

@Override
public void collect(CollectRep.MetricsData.Builder builder, long monitorId, String app, Metrics metrics) {
HttpsdProtocol httpsdProtocol = metrics.getHttpsd();
RegistryProtocol registryProtocol = metrics.getRegistry();

try (DiscoveryClient discoveryClient = discoveryClientManagement.getClient(httpsdProtocol)) {
try (DiscoveryClient discoveryClient = discoveryClientManagement.getClient(registryProtocol)) {
collectMetrics(builder, metrics, discoveryClient);
} catch (TransportException e1) {
String errorMsg = "Consul " + CommonUtil.getMessageFromThrowable(e1);
Expand Down Expand Up @@ -103,11 +103,11 @@ private void collectMetrics(CollectRep.MetricsData.Builder builder, Metrics metr

@Override
public String supportProtocol() {
return DispatchConstants.PROTOCOL_HTTP_SD;
return DispatchConstants.PROTOCOL_REGISTRY;
}

private boolean checkParamsFailed(HttpsdProtocol httpsd) {
return Objects.isNull(httpsd) || httpsd.isInvalid();
private boolean checkParamsFailed(RegistryProtocol registry) {
return Objects.isNull(registry) || registry.isInvalid();
}

private void addColumnIfMatched(String fieldName, Object sourceObj, CollectRep.ValueRow.Builder valueRowBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.hertzbeat.collector.collect.httpsd.constant;
package org.apache.hertzbeat.collector.collect.registry.constant;

/**
* Discovery client instance status.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.hertzbeat.collector.collect.httpsd.constant;
package org.apache.hertzbeat.collector.collect.registry.constant;

import java.util.Arrays;
import org.apache.commons.lang3.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* under the License.
*/

package org.apache.hertzbeat.collector.collect.httpsd.discovery;
package org.apache.hertzbeat.collector.collect.registry.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.registry.discovery.entity.ConnectConfig;
import org.apache.hertzbeat.collector.collect.registry.discovery.entity.ServerInfo;
import org.apache.hertzbeat.collector.collect.registry.discovery.entity.ServiceInstance;
import org.apache.hertzbeat.common.entity.job.protocol.RegistryProtocol;

/**
* DiscoveryClient interface.
Expand All @@ -32,10 +32,10 @@ public interface DiscoveryClient extends AutoCloseable {

/**
* Build connect config.
* @param httpsdProtocol httpsd protocol.
* @param registryProtocol httpsd protocol.
* @return connect config object.
*/
ConnectConfig buildConnectConfig(HttpsdProtocol httpsdProtocol);
ConnectConfig buildConnectConfig(RegistryProtocol registryProtocol);

/**
* Initialize client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@
* under the License.
*/

package org.apache.hertzbeat.collector.collect.httpsd.discovery;
package org.apache.hertzbeat.collector.collect.registry.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.registry.constant.DiscoveryClientInstance;
import org.apache.hertzbeat.collector.collect.registry.discovery.impl.ConsulDiscoveryClient;
import org.apache.hertzbeat.collector.collect.registry.discovery.impl.NacosDiscoveryClient;
import org.apache.hertzbeat.common.entity.job.protocol.RegistryProtocol;

/**
* Discovery Client Management
*/
public class DiscoveryClientManagement {

public DiscoveryClient getClient(HttpsdProtocol httpsdProtocol) {
return createClient(httpsdProtocol, DiscoveryClientInstance.getByName(httpsdProtocol.getDiscoveryClientTypeName()));
public DiscoveryClient getClient(RegistryProtocol registryProtocol) {
return createClient(registryProtocol, DiscoveryClientInstance.getByName(registryProtocol.getDiscoveryClientTypeName()));
}

private DiscoveryClient createClient(HttpsdProtocol httpsdProtocol, DiscoveryClientInstance discoveryClientInstance) {
private DiscoveryClient createClient(RegistryProtocol registryProtocol, DiscoveryClientInstance discoveryClientInstance) {
if (Objects.equals(discoveryClientInstance, DiscoveryClientInstance.NOT_SUPPORT)) {
return null;
}

return doCreateClient(httpsdProtocol, discoveryClientInstance);
return doCreateClient(registryProtocol, discoveryClientInstance);
}

private DiscoveryClient doCreateClient(HttpsdProtocol httpsdProtocol, DiscoveryClientInstance discoveryClientInstance) {
private DiscoveryClient doCreateClient(RegistryProtocol registryProtocol, 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(registryProtocol));
return discoveryClient;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.hertzbeat.collector.collect.httpsd.discovery.entity;
package org.apache.hertzbeat.collector.collect.registry.discovery.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.hertzbeat.collector.collect.httpsd.discovery.entity;
package org.apache.hertzbeat.collector.collect.registry.discovery.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.hertzbeat.collector.collect.httpsd.discovery.entity;
package org.apache.hertzbeat.collector.collect.registry.discovery.entity;

import java.util.Map;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.hertzbeat.collector.collect.httpsd.discovery.impl;
package org.apache.hertzbeat.collector.collect.registry.discovery.impl;

import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.agent.model.Check;
Expand All @@ -28,11 +28,11 @@
import java.util.List;
import java.util.Map;
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.collector.collect.registry.discovery.DiscoveryClient;
import org.apache.hertzbeat.collector.collect.registry.discovery.entity.ConnectConfig;
import org.apache.hertzbeat.collector.collect.registry.discovery.entity.ServerInfo;
import org.apache.hertzbeat.collector.collect.registry.discovery.entity.ServiceInstance;
import org.apache.hertzbeat.common.entity.job.protocol.RegistryProtocol;

/**
* DiscoveryClient impl of Consul
Expand All @@ -41,10 +41,10 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
private ConsulClient consulClient;

@Override
public ConnectConfig buildConnectConfig(HttpsdProtocol httpsdProtocol) {
public ConnectConfig buildConnectConfig(RegistryProtocol registryProtocol) {
return ConnectConfig.builder()
.host(httpsdProtocol.getHost())
.port(Integer.parseInt(httpsdProtocol.getPort()))
.host(registryProtocol.getHost())
.port(Integer.parseInt(registryProtocol.getPort()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.hertzbeat.collector.collect.httpsd.discovery.impl;
package org.apache.hertzbeat.collector.collect.registry.discovery.impl;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingFactory;
Expand All @@ -27,12 +27,12 @@
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.registry.constant.DiscoveryClientHealthStatus;
import org.apache.hertzbeat.collector.collect.registry.discovery.DiscoveryClient;
import org.apache.hertzbeat.collector.collect.registry.discovery.entity.ConnectConfig;
import org.apache.hertzbeat.collector.collect.registry.discovery.entity.ServerInfo;
import org.apache.hertzbeat.collector.collect.registry.discovery.entity.ServiceInstance;
import org.apache.hertzbeat.common.entity.job.protocol.RegistryProtocol;

/**
* DiscoveryClient impl of Nacos
Expand All @@ -43,10 +43,10 @@ public class NacosDiscoveryClient implements DiscoveryClient {
private ConnectConfig localConnectConfig;

@Override
public ConnectConfig buildConnectConfig(HttpsdProtocol httpsdProtocol) {
public ConnectConfig buildConnectConfig(RegistryProtocol registryProtocol) {
return ConnectConfig.builder()
.host(httpsdProtocol.getHost())
.port(Integer.parseInt(httpsdProtocol.getPort()))
.host(registryProtocol.getHost())
.port(Integer.parseInt(registryProtocol.getPort()))
.build();
}

Expand Down
Loading
Loading