Skip to content

Commit

Permalink
NMS-15776: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
christianpape committed Jul 17, 2023
1 parent ffb4e18 commit 6617ae0
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DefaultPassiveHealthCheck(

@Override
public synchronized void setResponse(Response response) {
LOG.warn("Cache response - healthCheck: {}; status: {}; msg: {}", description, response.getStatus(), response.getMessage());
LOG.debug("Cache response - healthCheck: {}; status: {}; msg: {}", description, response.getStatus(), response.getMessage());
cachedResponse = response;
cachedResponseTimestamp = Instant.now();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,26 @@ public Response perform(Context context) {
if ((b.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
break;
}
health.add(this, new Response(Failure, "Bundle " + b.getBundleId() + " (" + b.getSymbolicName() + ") is resolved, but not active"));
health.add(this, new Response(Failure, "Bundle " + b.getBundleId() + " is resolved, but not active"));
break;
// Waiting for dependencies
case Waiting:
case GracePeriod:
health.add(this, new Response(Starting, "Bundle " + b.getBundleId() + " (" + b.getSymbolicName() + ") is waiting for dependencies"));
health.add(this, new Response(Starting, "Bundle " + b.getBundleId() + " is waiting for dependencies"));
break;
// Installed, but not yet started
case Installed:
health.add(this, new Response(Starting, "Bundle " + b.getBundleId() + " (" + b.getSymbolicName() + ") is not yet started"));
health.add(this, new Response(Starting, "Bundle " + b.getBundleId() + " is not yet started"));
break;
// Starting
case Starting:
health.add(this, new Response(Starting, "Bundle " + b.getBundleId() + " (" + b.getSymbolicName() + ") is starting"));
health.add(this, new Response(Starting, "Bundle " + b.getBundleId() + " is starting"));
break;
// Stopping, Failed ur Unknown are considered Failures
case Stopping:
case Failure:
case Unknown:
health.add(this, new Response(Failure, "Bundle " + b.getBundleId() + " (" + b.getSymbolicName() + ") is not started"));
health.add(this, new Response(Failure, "Bundle " + b.getBundleId() + " is not started"));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@ private CompletionStage<Pair<HealthCheck, Response>> completionStage(HealthCheck
private CompletionStage<Health> runChecks(Context context, List<HealthCheck> checks, ProgressListener listener) {
return FutureUtils.traverse(checks, check -> completionStage(check, context, listener)).thenApply(list -> {
var health = new Health(list);
for(var pair : list) {
if (pair.getRight().isSuccess()) {
LOG.warn("BMRHGA: " + pair.getLeft().getDescription() + ": Success");
} else {
LOG.warn("BMRHGA: " + pair.getLeft().getDescription() + ": Failure (msg = '" + pair.getRight().getMessage() + "')");
}
}

if (listener != null) {
listener.onAllHealthChecksCompleted(health);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
import org.opennms.core.health.api.Health;
import org.opennms.core.health.api.HealthCheckService;
import org.opennms.core.health.rest.HealthCheckRestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.vavr.control.Either;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HealthCheckRestServiceImpl implements HealthCheckRestService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,7 @@ You can also disable this scan by setting `scan-interval` to `-1`.

During the provisioning process hostnames are determined for each interface IP address by DNS reverse lookups.
A thread pool is used to allow concurrent DNS lookups.
You can use the following properties to configure this thread pool:

.Thread pool configuration parameters for DNS lookups
[options="header"]
[cols="1,3,2"]
|===
| Parameter
| Description
| Default value

| org.opennms.netmgt.provision.dns.client.rpc.maxThreadPoolSize
| Maximum thread pool size.
| 64
| org.opennms.netmgt.provision.dns.client.rpc.queueCapacity
| Maximum queue size for pending DNS lookups.
| 4096
|===
You can use the property `org.opennms.netmgt.provision.dns.client.rpc.threadCount` to configure the thread pool's fixed size (default 64).

NOTE: To completely disable DNS reverse lookups, set the property `org.opennms.provisiond.reverseResolveRequisitionIpInterfaceHostnames` to `false`.

Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,8 @@ org.opennms.newts.nan_on_counter_wrap=true
# org.opennms.mate.maxRecursionDepth=8

# ###### DNS tuning options ######
# A thread pool is used to allow concurrent DNS lookups on OpenNMS instance.
# org.opennms.netmgt.provision.dns.client.rpc.maxThreadPoolSize=64
# org.opennms.netmgt.provision.dns.client.rpc.queueCapacity=4096
# A thread pool is used to allow concurrent DNS lookups on OpenNMS Minions.
# org.opennms.netmgt.provision.dns.client.rpc.threadCount=64

# By default hostnames are determined for a node's IP addresses during the provisioning's audit phase.
# org.opennms.provisiond.reverseResolveRequisitionIpInterfaceHostnames=true
5 changes: 0 additions & 5 deletions opennms-provision/opennms-detectorclient-rpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@
<artifactId>dnsjava-dependencies</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-bulkhead</artifactId>
<version>${resilience4jVersion}</version>
</dependency>
<dependency>
<groupId>org.opennms.core.ipc.rpc</groupId>
<artifactId>org.opennms.core.ipc.rpc.jms-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,29 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.opennms.core.rpc.xml.AbstractXmlRpcModule;
import org.opennms.core.utils.InetAddressUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xbill.DNS.Address;

import io.github.resilience4j.bulkhead.ThreadPoolBulkhead;
import io.github.resilience4j.bulkhead.ThreadPoolBulkheadConfig;

public class DnsLookupClientRpcModule extends AbstractXmlRpcModule<DnsLookupRequestDTO, DnsLookupResponseDTO> {

private static final Logger LOG = LoggerFactory.getLogger(DnsLookupClientRpcModule.class);

public static final String RPC_MODULE_ID = "DNS";

private final ThreadPoolBulkhead threadPoolBulkhead;
private final ExecutorService executorService;

public DnsLookupClientRpcModule(final int maxThreadPoolSize, final int queueCapacity) {
public DnsLookupClientRpcModule(final int threadCount) {
super(DnsLookupRequestDTO.class, DnsLookupResponseDTO.class);

final ThreadPoolBulkheadConfig threadPoolBulkheadConfig = ThreadPoolBulkheadConfig.custom()
.queueCapacity(queueCapacity)
.maxThreadPoolSize(maxThreadPoolSize)
.build();

this.threadPoolBulkhead = ThreadPoolBulkhead.of("dns-lookup-rpc-module", threadPoolBulkheadConfig);
this.executorService = Executors.newFixedThreadPool(threadCount);

LOG.debug("Configuring ThreadPoolBulkhead: maxThreadPoolSize={}, queueSize={}", maxThreadPoolSize, queueCapacity);
LOG.debug("Configuring fixed-sized ThreadPool using threadCount={}", threadCount);
}

@Override
Expand All @@ -74,7 +68,7 @@ public String getId() {

@Override
public CompletableFuture<DnsLookupResponseDTO> execute(DnsLookupRequestDTO request) {
return this.threadPoolBulkhead.submit(() -> {
return CompletableFuture.supplyAsync(() -> {
final InetAddress addr = InetAddressUtils.addr(request.getHostRequest());
final DnsLookupResponseDTO dto = new DnsLookupResponseDTO();
final QueryType queryType = request.getQueryType();
Expand All @@ -99,6 +93,6 @@ public CompletableFuture<DnsLookupResponseDTO> execute(DnsLookupRequestDTO reque
dto.setHostResponse(hostName);
}
return dto;
}).toCompletableFuture();
}, this.executorService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<context:annotation-config />

<bean id="dnsLookupClientRpcModule" class="org.opennms.netmgt.provision.dns.client.rpc.DnsLookupClientRpcModule" >
<constructor-arg value="${org.opennms.netmgt.provision.dns.client.rpc.maxThreadPoolSize:4096}"/>
<constructor-arg value="${org.opennms.netmgt.provision.dns.client.rpc.queueCapacity:64}"/>
<constructor-arg value="${org.opennms.netmgt.provision.dns.client.rpc.threadCount:64}"/>
</bean>

<bean id="locationAwareDnsClient" class="org.opennms.netmgt.provision.dns.client.rpc.LocationAwareDnsLookupClientRpcImpl" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

<cm:property-placeholder id="dnsLookupProperties" persistent-id="org.opennms.netmgt.provision.dns.client.rpc" update-strategy="reload">
<cm:default-properties>
<cm:property name="queueCapacity" value="4096"/>
<cm:property name="maxThreadPoolSize" value="64"/>
<cm:property name="threadCount" value="64"/>
</cm:default-properties>
</cm:property-placeholder>

Expand All @@ -28,8 +27,7 @@

<service interface="org.opennms.core.rpc.api.RpcModule">
<bean class="org.opennms.netmgt.provision.dns.client.rpc.DnsLookupClientRpcModule">
<argument value="${maxThreadPoolSize}"/>
<argument value="${queueCapacity}"/>
<argument value="${threadCount}"/>
</bean>
</service>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

import org.opennms.core.utils.InetAddressUtils;
import org.opennms.netmgt.provision.LocationAwareDnsLookupClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -49,6 +50,14 @@ public DefaultHostnameResolver(LocationAwareDnsLookupClient locationAwareDnsLook
@Override
public CompletableFuture<String> getHostnameAsync(final InetAddress addr, final String location) {
LOG.debug("Performing reverse lookup on {} at location {}", addr, location);
return m_locationAwareDnsLookupClient.reverseLookup(addr, location);
return m_locationAwareDnsLookupClient.reverseLookup(addr, location).handle((result, e) -> {
if (e == null) {
LOG.debug("Reverse lookup returned {} for {} at location {}", result, addr, location);
return result;
} else {
LOG.warn("Reverse lookup failed for {} at location {}. Using IP address as hostname.", addr, location);
return InetAddressUtils.str(addr);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,13 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import org.opennms.core.utils.InetAddressUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public interface HostnameResolver {
Logger LOG = LoggerFactory.getLogger(HostnameResolver.class);

default String getHostname(final InetAddress addr, final String location) {
try {
final String result = getHostnameAsync(addr, location).get();
LOG.debug("Reverse lookup returned {} for {} at location {}", result, addr, location);
return result;
return getHostnameAsync(addr, location).get();
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Reverse lookup failed for {} at location {}. Using IP address as hostname.", addr, location);
return InetAddressUtils.str(addr);
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ int dnsLookupsTotal() {
@Override
public void completeModelImport(Requisition req) {
LOG.debug("Waiting for {} scheduled DNS lookups, {} DNS lookups pending", dnsLookupsTotal(), dnsLookupsPending());
CompletableFuture.allOf(m_dnsLookups.toArray(CompletableFuture[]::new)).join();

m_dnsLookups.stream().map(CompletableFuture::join);

LOG.debug("All {} scheduled DNS lookups completed", dnsLookupsTotal());
}
}

0 comments on commit 6617ae0

Please sign in to comment.