Skip to content

Commit

Permalink
fix: Fix update of metrics in AdapterHealthCheck (#2328)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikriemer authored Dec 13, 2023
1 parent c68e2fb commit 240d23d
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;

public class AdapterHealthCheck implements Runnable {

Expand Down Expand Up @@ -68,10 +70,6 @@ public void checkAndRestoreAdapters() {
Map<String, AdapterDescription> allRunningInstancesAdapterDescriptions =
this.getAllRunningInstancesAdapterDescriptions();

if (!allRunningInstancesAdapterDescriptions.isEmpty()) {
updateMonitoringMetrics(allRunningInstancesAdapterDescriptions);
}

// Get all worker containers that run adapters
Map<String, List<AdapterDescription>> groupByWorker =
this.getAllWorkersWithAdapters(allRunningInstancesAdapterDescriptions);
Expand All @@ -80,6 +78,21 @@ public void checkAndRestoreAdapters() {
Map<String, AdapterDescription> allAdaptersToRecover =
this.getAdaptersToRecover(groupByWorker, allRunningInstancesAdapterDescriptions);

try {
if (!allRunningInstancesAdapterDescriptions.isEmpty()) {
// Filter adapters so that only healthy and running adapters are updated in the metrics endpoint
updateMonitoringMetrics(
allRunningInstancesAdapterDescriptions
.entrySet()
.stream()
.filter((entry -> !allAdaptersToRecover.containsKey(entry.getKey())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
);
}
} catch (NoSuchElementException e) {
LOG.error("Could not update adapter metrics due to an invalid state. ({})", e.getMessage());
}

// Recover Adapters
this.recoverAdapters(allAdaptersToRecover);
}
Expand Down

0 comments on commit 240d23d

Please sign in to comment.