Skip to content

Commit

Permalink
Fix AgentJanitor bugs (#1225)
Browse files Browse the repository at this point in the history
I previously mis-used Java stream. Fixed them and added more logging.

Validated in pre-prod
  • Loading branch information
tylerwowen committed Aug 1, 2023
1 parent b2bd6b8 commit ebdb28e
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -122,16 +123,18 @@ private boolean isHostStale(HostAgentBean hostAgentBean) {
*/
private void determineStaleHostCandidates() {
long minThreshold = janitorStartTime - minStaleHostThreshold;
long maxThreshold = janitorStartTime - maxLaunchLatencyThreshold;
long maxThreshold = janitorStartTime - maxStaleHostThreshold;
List<HostAgentBean> unreachableHosts;
try {
LOG.debug("getting hosts between {}, {}", maxThreshold, minThreshold);
unreachableHosts = hostAgentDAO.getStaleHosts(maxThreshold, minThreshold);
} catch (Exception ex) {
LOG.error("failed to get unreachable hosts", ex);
return;
}
ArrayList<String> unreachableHostIds = new ArrayList<>();
unreachableHosts.stream().map(hostAgent -> unreachableHostIds.add(hostAgent.getHost_id()));
List<String> unreachableHostIds = unreachableHosts.stream().map(HostAgentBean::getHost_id)
.collect(Collectors.toList());
LOG.debug("fetched {} unreachable hosts", unreachableHostIds.size());

Set<String> terminatedHosts = getTerminatedHostsFromSource(unreachableHostIds);
for (String unreachableId : unreachableHostIds) {
Expand All @@ -152,14 +155,16 @@ private void processStaleHosts() {
long maxThreshold = janitorStartTime - maxStaleHostThreshold;
List<HostAgentBean> staleHosts;
try {
LOG.debug("getting hosts before {}", maxThreshold);
staleHosts = hostAgentDAO.getStaleHosts(maxThreshold);
} catch (Exception ex) {
LOG.error("failed to get stale hosts", ex);
return;
}

Map<String, HostAgentBean> staleHostMap = new HashMap<>();
staleHosts.stream().map(hostAgent -> staleHostMap.put(hostAgent.getHost_id(), hostAgent));
staleHosts.stream().forEach(hostAgent -> staleHostMap.put(hostAgent.getHost_id(), hostAgent));
LOG.debug("fetched {} unreachable hosts", staleHostMap.values().size());

Set<String> terminatedHosts = getTerminatedHostsFromSource(new ArrayList<>(staleHostMap.keySet()));
for (String staleId : staleHostMap.keySet()) {
Expand All @@ -170,6 +175,8 @@ private void processStaleHosts() {
if (isHostStale(hostAgent)) {
LOG.warn("Agent ({}) is stale (not Pinging Teletraan), but might be running.",
hostAgent);
} else {
LOG.debug("host {} is not stale", staleId);
}
}
}
Expand Down

0 comments on commit ebdb28e

Please sign in to comment.