From 59c461e4760235d07742d6b703e3c83e6a54f777 Mon Sep 17 00:00:00 2001 From: Sid Narayan Date: Fri, 24 Jul 2020 00:21:13 -0700 Subject: [PATCH] Revert "Make RCA framework NOT use ClusterDetailsEventProcessor (#274)" This reverts commit 95c19b69675ae5d3b246cf9fb4171de624f94517. --- .../performanceanalyzer/AppContext.java | 101 ------------------ .../PerformanceAnalyzerApp.java | 27 ++--- .../rca/RcaController.java | 42 +++----- .../rca/framework/core/Node.java | 37 ------- .../rca/framework/util/InstanceDetails.java | 52 --------- .../rca/net/NodeStateManager.java | 16 +-- .../rca/net/WireHopper.java | 34 ++---- .../tasks/BroadcastSubscriptionTxTask.java | 9 +- .../rca/net/tasks/FlowUnitTxTask.java | 10 +- .../rca/net/tasks/SubscriptionTxTask.java | 18 +--- .../net/tasks/UnicastSubscriptionTxTask.java | 6 +- .../rca/scheduler/RCAScheduler.java | 27 ++--- .../rca/scheduler/RCASchedulerTask.java | 22 ++-- .../store/rca/HighHeapUsageClusterRca.java | 12 +-- .../rca/store/rca/HotNodeClusterRca.java | 30 +++--- .../rca/store/rca/HotNodeRca.java | 11 +- .../store/rca/cache/FieldDataCacheRca.java | 10 +- .../store/rca/cache/ShardRequestCacheRca.java | 10 +- .../rca/store/rca/cluster/BaseClusterRca.java | 19 ++-- .../rca/store/rca/cluster/NodeKey.java | 5 - .../rca/hotshard/HotShardClusterRca.java | 10 +- .../rca/store/rca/hotshard/HotShardRca.java | 16 +-- .../rca/remediation/NodeConfigCollector.java | 5 +- .../rca/temperature/NodeTemperatureRca.java | 10 +- .../rca/threadpool/QueueRejectionRca.java | 14 ++- .../rca/util/ClusterUtils.java | 55 +++++++++- .../reader/ClusterDetailsEventProcessor.java | 12 +-- .../reader/ReaderMetricsProcessor.java | 11 +- .../rest/QueryMetricsRequestHandler.java | 32 +++--- .../rest/QueryRcaRequestHandler.java | 10 +- .../collectors/RcaStatsCollectorTest.java | 18 +--- .../deciders/QueueHealthDeciderTest.java | 40 ++----- .../rca/RcaControllerTest.java | 9 +- .../rca/RcaTestHelper.java | 6 +- ...ehavingGraphOperateMethodListenerTest.java | 6 +- .../rca/net/NodeStateManagerTest.java | 13 +-- .../rca/net/SubscribeResponseHandlerTest.java | 3 +- .../rca/net/WireHopperTest.java | 25 ++--- .../PersistFlowUnitAndSummaryTest.java | 74 +++++-------- .../rca/scheduler/RCASchedulerTaskTests.java | 8 +- .../scheduler/RcaSchedulerAsyncTaskTest.java | 7 +- .../rca/store/ResourceHeatMapGraphTest.java | 74 +++++-------- .../rca/util/ClusterUtilsTest.java | 52 +++++---- .../reader/ReaderMetricsProcessorTests.java | 3 +- .../rca/HighHeapUsageClusterRcaTest.java | 33 ++---- .../store/rca/HotNodeClusterRcaTest.java | 36 ++----- .../store/rca/cluster/BaseClusterRcaTest.java | 42 ++------ .../rca/hotshard/HotShardClusterRcaTest.java | 30 ++---- .../store/rca/hotshard/HotShardRcaTest.java | 27 +++-- .../remediation/NodeConfigCollectorTest.java | 13 +-- .../rca/threadpool/QueueRejectionRcaTest.java | 22 +--- 51 files changed, 388 insertions(+), 826 deletions(-) delete mode 100644 src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/AppContext.java delete mode 100644 src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/util/InstanceDetails.java diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/AppContext.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/AppContext.java deleted file mode 100644 index 0efb0e539..000000000 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/AppContext.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.opendistro.elasticsearch.performanceanalyzer; - -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; -import com.google.common.collect.ImmutableList; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -/** - * The PA agent process is composed of multiple components. The PA Reader and RCA are two such components that are - * independent in a way they process information but also share some information such as the node and the cluster - * details. Today, some of these information is accessed by calling static methods and members. This is a bad idea. - * This class encapsulates such information and is created right at the start in the {@code PerformanceAnalyzerApp}. - */ -public class AppContext { - private volatile ClusterDetailsEventProcessor clusterDetailsEventProcessor; - - public AppContext() { - this.clusterDetailsEventProcessor = null; - } - - public void setClusterDetailsEventProcessor(final ClusterDetailsEventProcessor clusterDetailsEventProcessor) { - this.clusterDetailsEventProcessor = clusterDetailsEventProcessor; - } - - public InstanceDetails getMyInstanceDetails() { - InstanceDetails ret = new InstanceDetails(AllMetrics.NodeRole.UNKNOWN); - - if (clusterDetailsEventProcessor != null && clusterDetailsEventProcessor.getCurrentNodeDetails() != null) { - ClusterDetailsEventProcessor.NodeDetails nodeDetails = clusterDetailsEventProcessor.getCurrentNodeDetails(); - ret = new InstanceDetails( - AllMetrics.NodeRole.valueOf(nodeDetails.getRole()), - nodeDetails.getId(), - nodeDetails.getHostAddress(), - nodeDetails.getIsMasterNode()); - } - return ret; - } - - /** - * Can be used to get all the nodes in the cluster. - * - * @return Returns an empty list of the details are not available or else it provides the immutable list of nodes in - * the cluster. - */ - public List getAllClusterInstances() { - List ret = Collections.EMPTY_LIST; - - if (clusterDetailsEventProcessor != null) { - ret = getInstanceDetailsFromNodeDetails(clusterDetailsEventProcessor.getNodesDetails()); - } - return ret; - } - - public List getDataNodeInstances() { - List ret = Collections.EMPTY_LIST; - if (clusterDetailsEventProcessor != null) { - ret = getInstanceDetailsFromNodeDetails(clusterDetailsEventProcessor.getDataNodesDetails()); - } - return ret; - } - - private static List getInstanceDetailsFromNodeDetails( - final List nodeDetails) { - List instances = new ArrayList<>(); - - for (ClusterDetailsEventProcessor.NodeDetails node : nodeDetails) { - InstanceDetails instanceDetails = new InstanceDetails( - AllMetrics.NodeRole.valueOf(node.getRole()), node.getId(), node.getHostAddress(), node.getIsMasterNode()); - instances.add(instanceDetails); - } - return ImmutableList.copyOf(instances); - } - - public List getPeerInstanceIps() { - return ImmutableList.copyOf( - getAllClusterInstances() - .stream() - .skip(1) // Skipping the first instance as it is self. - .map(InstanceDetails::getInstanceIp) - .collect(Collectors.toList())); - } -} diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/PerformanceAnalyzerApp.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/PerformanceAnalyzerApp.java index d781250b2..db39ebb5e 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/PerformanceAnalyzerApp.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/PerformanceAnalyzerApp.java @@ -102,7 +102,7 @@ public class PerformanceAnalyzerApp { public static final BlockingQueue exceptionQueue = new ArrayBlockingQueue<>(EXCEPTION_QUEUE_LENGTH); - public static void main(String[] args) { + public static void main(String[] args) throws Exception { PluginSettings settings = PluginSettings.instance(); StatsCollector.STATS_TYPE = "agent-stats-metadata"; METRIC_COLLECTOR_EXECUTOR.addScheduledMetricCollector(StatsCollector.instance()); @@ -112,19 +112,16 @@ public static void main(String[] args) { final GRPCConnectionManager connectionManager = new GRPCConnectionManager( settings.getHttpsEnabled()); - AppContext appContext = new AppContext(); - final ClientServers clientServers = createClientServers(connectionManager, appContext); + final ClientServers clientServers = createClientServers(connectionManager); startErrorHandlingThread(); - - startReaderThread(appContext); + startReaderThread(); startGrpcServerThread(clientServers.getNetServer()); startWebServerThread(clientServers.getHttpServer()); - startRcaTopLevelThread(clientServers, connectionManager, appContext); + startRcaTopLevelThread(clientServers, connectionManager); } private static void startRcaTopLevelThread(final ClientServers clientServers, - final GRPCConnectionManager connectionManager, - final AppContext appContext) { + final GRPCConnectionManager connectionManager) { rcaController = new RcaController( THREAD_PROVIDER, @@ -133,8 +130,7 @@ private static void startRcaTopLevelThread(final ClientServers clientServers, clientServers, Util.DATA_DIR, RcaConsts.RCA_STATE_CHECK_INTERVAL_IN_MS, - RcaConsts.nodeRolePollerPeriodicityInSeconds * 1000, - appContext + RcaConsts.nodeRolePollerPeriodicityInSeconds * 1000 ); Thread rcaControllerThread = THREAD_PROVIDER.createThreadForRunnable(() -> rcaController.run(), @@ -192,13 +188,13 @@ private static void startGrpcServerThread(final NetServer server) { grpcServerThread.start(); } - private static void startReaderThread(final AppContext appContext) { + private static void startReaderThread() { PluginSettings settings = PluginSettings.instance(); final Thread readerThread = THREAD_PROVIDER.createThreadForRunnable(() -> { while (true) { try { ReaderMetricsProcessor mp = - new ReaderMetricsProcessor(settings.getMetricsLocation(), true, appContext); + new ReaderMetricsProcessor(settings.getMetricsLocation(), true); ReaderMetricsProcessor.setCurrentInstance(mp); mp.run(); } catch (Throwable e) { @@ -225,8 +221,7 @@ private static void startReaderThread(final AppContext appContext) { * * @return gRPC client and the gRPC server and the httpServer wrapped in a class. */ - public static ClientServers createClientServers(final GRPCConnectionManager connectionManager, - final AppContext appContext) { + public static ClientServers createClientServers(final GRPCConnectionManager connectionManager) { boolean useHttps = PluginSettings.instance().getHttpsEnabled(); NetServer netServer = new NetServer(Util.RPC_PORT, 1, useHttps); @@ -236,9 +231,7 @@ public static ClientServers createClientServers(final GRPCConnectionManager conn netServer.setMetricsHandler(new MetricsServerHandler()); HttpServer httpServer = PerformanceAnalyzerWebServer.createInternalServer(PluginSettings.instance()); - httpServer.createContext( - QUERY_URL, - new QueryMetricsRequestHandler(netClient, metricsRestUtil, appContext)); + httpServer.createContext(QUERY_URL, new QueryMetricsRequestHandler(netClient, metricsRestUtil)); return new ClientServers(httpServer, netServer, netClient); } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaController.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaController.java index ea6704718..2122f60b9 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaController.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaController.java @@ -17,7 +17,6 @@ import static com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaConsts.RCA_MUTE_ERROR_METRIC; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.ClientServers; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerThreads; @@ -36,7 +35,6 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.Stats; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.ThresholdMain; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.metrics.RcaRuntimeMetrics; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaConsts; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.NodeStateManager; @@ -50,9 +48,10 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.persistence.PersistenceFactory; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.RCAScheduler; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.RcaSchedulerState; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor.NodeDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rest.QueryRcaRequestHandler; import com.amazon.opendistro.elasticsearch.performanceanalyzer.threads.ThreadProvider; -import com.google.common.annotations.VisibleForTesting; import com.sun.net.httpserver.HttpServer; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -67,6 +66,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -120,8 +120,6 @@ public class RcaController { private AtomicReference networkThreadPoolReference = new AtomicReference<>(); private ReceivedFlowUnitStore receivedFlowUnitStore; - private final AppContext appContext; - public RcaController( final ThreadProvider threadProvider, final ScheduledExecutorService netOpsExecutorService, @@ -129,10 +127,8 @@ public RcaController( final ClientServers clientServers, final String rca_enabled_conf_location, final long rcaStateCheckIntervalMillis, - final long nodeRoleCheckPeriodicityMillis, - final AppContext appContext) { + final long nodeRoleCheckPeriodicityMillis) { this.threadProvider = threadProvider; - this.appContext = appContext; this.netOpsExecutorService = netOpsExecutorService; this.rcaNetClient = clientServers.getNetClient(); this.rcaNetServer = clientServers.getNetServer(); @@ -141,8 +137,8 @@ public RcaController( netPersistor = new NetPersistor(); this.useHttps = PluginSettings.instance().getHttpsEnabled(); subscriptionManager = new SubscriptionManager(grpcConnectionManager); - nodeStateManager = new NodeStateManager(this.appContext); - queryRcaRequestHandler = new QueryRcaRequestHandler(this.appContext); + nodeStateManager = new NodeStateManager(); + queryRcaRequestHandler = new QueryRcaRequestHandler(); this.rcaScheduler = null; this.rcaStateCheckIntervalMillis = rcaStateCheckIntervalMillis; this.roleCheckPeriodicity = nodeRoleCheckPeriodicityMillis; @@ -166,21 +162,16 @@ private void start() { receivedFlowUnitStore = new ReceivedFlowUnitStore(rcaConf.getPerVertexBufferLength()); WireHopper net = new WireHopper(nodeStateManager, rcaNetClient, subscriptionManager, - networkThreadPoolReference, receivedFlowUnitStore, appContext); + networkThreadPoolReference, receivedFlowUnitStore); this.rcaScheduler = - new RCAScheduler(connectedComponents, - db, - rcaConf, - thresholdMain, - persistable, - net, - appContext); + new RCAScheduler(connectedComponents, db, rcaConf, thresholdMain, persistable, net); rcaNetServer.setSendDataHandler(new PublishRequestHandler( nodeStateManager, receivedFlowUnitStore, networkThreadPoolReference)); rcaNetServer.setSubscribeHandler( new SubscribeServerHandler(subscriptionManager, networkThreadPoolReference)); + rcaScheduler.setRole(currentRole); Thread rcaSchedulerThread = threadProvider.createThreadForRunnable(() -> rcaScheduler.start(), PerformanceAnalyzerThreads.RCA_SCHEDULER); @@ -232,8 +223,8 @@ public void run() { readRcaEnabledFromConf(); if (rcaEnabled && tick % nodeRoleCheckInTicks == 0) { tick = 0; - final InstanceDetails nodeDetails = appContext.getMyInstanceDetails(); - if (nodeDetails.getRole() != NodeRole.UNKNOWN) { + final NodeDetails nodeDetails = ClusterDetailsEventProcessor.getCurrentNodeDetails(); + if (nodeDetails != null) { checkUpdateNodeRole(nodeDetails); } } @@ -259,9 +250,9 @@ public void run() { } } - private void checkUpdateNodeRole(final InstanceDetails currentNode) { - final NodeRole currentNodeRole = currentNode.getRole(); - boolean isMasterNode = currentNode.getIsMaster(); + private void checkUpdateNodeRole(final NodeDetails currentNode) { + final NodeRole currentNodeRole = NodeRole.valueOf(currentNode.getRole()); + boolean isMasterNode = currentNode.getIsMasterNode(); currentRole = isMasterNode ? NodeRole.ELECTED_MASTER : currentNodeRole; } @@ -409,11 +400,6 @@ public NodeRole getCurrentRole() { return currentRole; } - @VisibleForTesting - public AppContext getAppContext() { - return this.appContext; - } - public RCAScheduler getRcaScheduler() { return rcaScheduler; } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/core/Node.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/core/Node.java index ce40192a2..59c694959 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/core/Node.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/core/Node.java @@ -15,9 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; import com.google.common.annotations.VisibleForTesting; import java.util.ArrayList; @@ -69,11 +66,6 @@ public abstract class Node { */ private Map tags; - /** - * A view of the instanceDetails that the RCAs can have access to. - */ - private AppContext appContext; - Node(int level, long evaluationIntervalSeconds) { this.downStreams = new ArrayList<>(); this.level = level; @@ -195,33 +187,4 @@ public void setLocalFlowUnit(T localFlowUnit) { public void readRcaConf(RcaConf conf) { return; } - - public void setAppContext(final AppContext appContext) { - this.appContext = appContext; - } - - public InstanceDetails getInstanceDetails() { - InstanceDetails ret = new InstanceDetails(AllMetrics.NodeRole.UNKNOWN); - if (this.appContext != null) { - ret = this.appContext.getMyInstanceDetails(); - } - return ret; - } - - public List getAllClusterInstances() { - List ret = Collections.EMPTY_LIST; - - if (this.appContext != null) { - ret = this.appContext.getAllClusterInstances(); - } - return ret; - } - - public List getDataNodeInstances() { - List ret = Collections.EMPTY_LIST; - if (this.appContext != null) { - return this.appContext.getDataNodeInstances(); - } - return ret; - } } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/util/InstanceDetails.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/util/InstanceDetails.java deleted file mode 100644 index c377a15bb..000000000 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/util/InstanceDetails.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util; - -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; - -public class InstanceDetails { - private final AllMetrics.NodeRole role; - private final String InstanceId; - private final String instanceIp; - private final boolean isMaster; - - public InstanceDetails(AllMetrics.NodeRole role, String instanceId, String instanceIp, boolean isMaster) { - this.role = role; - InstanceId = instanceId; - this.instanceIp = instanceIp; - this.isMaster = isMaster; - } - - public InstanceDetails(AllMetrics.NodeRole role) { - this(role, "", "", false); - } - - public AllMetrics.NodeRole getRole() { - return role; - } - - public String getInstanceId() { - return InstanceId; - } - - public String getInstanceIp() { - return instanceIp; - } - - public boolean getIsMaster() { - return isMaster; - } -} diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/NodeStateManager.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/NodeStateManager.java index a87da4ab7..7da50f813 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/NodeStateManager.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/NodeStateManager.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.SubscribeResponse.SubscriptionStatus; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.util.ClusterUtils; import com.google.common.annotations.VisibleForTesting; @@ -45,12 +44,6 @@ public class NodeStateManager { private final ConcurrentMap> subscriptionStatusMap = new ConcurrentHashMap<>(); - private final AppContext appContext; - - public NodeStateManager(final AppContext appContext) { - this.appContext = appContext; - } - /** * Updates the timestamp for the composite key: (host, vertex) marking when the last successful * flow unit reception happened. @@ -121,12 +114,12 @@ public ImmutableList getStaleOrNotSubscribedNodes(final String graphNode for (final String publisher : publishers) { long lastRxTimestamp = getLastReceivedTimestamp(graphNode, publisher); if (lastRxTimestamp > 0 && currentTime - lastRxTimestamp > maxIdleDuration && ClusterUtils - .isHostAddressInCluster(publisher, appContext.getAllClusterInstances())) { + .isHostAddressInCluster(publisher)) { hostsToSubscribeTo.add(publisher); } } - final List peers = appContext.getPeerInstanceIps(); + final List peers = ClusterUtils.getAllPeerHostAddresses(); if (peers != null) { for (final String peerHost : peers) { String compositeKey = graphNode + SEPARATOR + peerHost; @@ -138,9 +131,4 @@ public ImmutableList getStaleOrNotSubscribedNodes(final String graphNode return ImmutableList.copyOf(hostsToSubscribeTo); } - - @VisibleForTesting - public AppContext getAppContext() { - return appContext; - } } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/WireHopper.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/WireHopper.java index 6c1035b3c..c959794e2 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/WireHopper.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/WireHopper.java @@ -15,13 +15,11 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatExceptionCode; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.FlowUnitMessage; import com.amazon.opendistro.elasticsearch.performanceanalyzer.net.NetClient; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.Node; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.messages.DataMsg; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.messages.IntentMsg; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.messages.UnicastIntentMsg; @@ -29,7 +27,6 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.tasks.FlowUnitTxTask; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.tasks.UnicastSubscriptionTxTask; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.util.ClusterUtils; -import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import java.util.List; import java.util.Set; @@ -49,33 +46,26 @@ public class WireHopper { private final NodeStateManager nodeStateManager; private final AtomicReference executorReference; private final ReceivedFlowUnitStore receivedFlowUnitStore; - private final AppContext appContext; public WireHopper( final NodeStateManager nodeStateManager, final NetClient netClient, final SubscriptionManager subscriptionManager, final AtomicReference executorReference, - final ReceivedFlowUnitStore receivedFlowUnitStore, - final AppContext appContext) { + final ReceivedFlowUnitStore receivedFlowUnitStore) { this.netClient = netClient; this.subscriptionManager = subscriptionManager; this.nodeStateManager = nodeStateManager; this.executorReference = executorReference; this.receivedFlowUnitStore = receivedFlowUnitStore; - this.appContext = appContext; } public void sendIntent(IntentMsg msg) { ExecutorService executor = executorReference.get(); if (executor != null) { try { - executor.execute(new BroadcastSubscriptionTxTask( - netClient, - msg, - subscriptionManager, - nodeStateManager, - appContext)); + executor.execute(new BroadcastSubscriptionTxTask(netClient, msg, subscriptionManager, + nodeStateManager)); } catch (final RejectedExecutionException ree) { LOG.warn("Dropped sending subscription because the threadpool queue is full"); StatsCollector.instance() @@ -88,7 +78,7 @@ public void sendData(DataMsg msg) { ExecutorService executor = executorReference.get(); if (executor != null) { try { - executor.execute(new FlowUnitTxTask(netClient, subscriptionManager, msg, appContext)); + executor.execute(new FlowUnitTxTask(netClient, subscriptionManager, msg)); } catch (final RejectedExecutionException ree) { LOG.warn("Dropped sending flow unit because the threadpool queue is full"); StatsCollector.instance() @@ -97,11 +87,6 @@ public void sendData(DataMsg msg) { } } - @VisibleForTesting - public AppContext getAppContext() { - return appContext; - } - public List readFromWire(Node node) { final String nodeName = node.name(); final long intervalInSeconds = node.getEvaluationIntervalSeconds(); @@ -110,7 +95,7 @@ public List readFromWire(Node node) { final Set publisherSet = subscriptionManager.getPublishersForNode(nodeName); for (final String publisher : publisherSet) { - if (!ClusterUtils.isHostAddressInCluster(publisher, appContext.getAllClusterInstances())) { + if (!ClusterUtils.isHostAddressInCluster(publisher)) { subscriptionManager.unsubscribeAndTerminateConnection(nodeName, publisher); } } @@ -123,12 +108,9 @@ public List readFromWire(Node node) { final ExecutorService executor = executorReference.get(); if (executor != null) { try { - executor.execute(new UnicastSubscriptionTxTask( - netClient, - new UnicastIntentMsg("", nodeName, node.getTags(), host), - subscriptionManager, - nodeStateManager, - appContext)); + executor.execute(new UnicastSubscriptionTxTask(netClient, new UnicastIntentMsg("", + nodeName, node.getTags(), host), + subscriptionManager, nodeStateManager)); } catch (final RejectedExecutionException ree) { LOG.warn("Dropped sending subscription request because the threadpool queue is " + "full"); diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/BroadcastSubscriptionTxTask.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/BroadcastSubscriptionTxTask.java index f871d1173..233ce3e89 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/BroadcastSubscriptionTxTask.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/BroadcastSubscriptionTxTask.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.tasks; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.net.NetClient; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.messages.IntentMsg; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.NodeStateManager; @@ -27,13 +26,13 @@ * Task that broadcasts a subscription request to the current node's peers. */ public class BroadcastSubscriptionTxTask extends SubscriptionTxTask { + public BroadcastSubscriptionTxTask( NetClient netClient, IntentMsg intentMsg, SubscriptionManager subscriptionManager, - NodeStateManager nodeStateManager, - final AppContext appContext) { - super(netClient, intentMsg, subscriptionManager, nodeStateManager, appContext); + NodeStateManager nodeStateManager) { + super(netClient, intentMsg, subscriptionManager, nodeStateManager); } /** @@ -47,7 +46,7 @@ public void run() { final String destinationVertex = intentMsg.getDestinationNode(); final Map tags = intentMsg.getRcaConfTags(); - for (final String remoteHost : getPeerIps()) { + for (final String remoteHost : ClusterUtils.getAllPeerHostAddresses()) { sendSubscribeRequest(remoteHost, requesterVertex, destinationVertex, tags); } } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/FlowUnitTxTask.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/FlowUnitTxTask.java index b491c21c9..83b796595 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/FlowUnitTxTask.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/FlowUnitTxTask.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.tasks; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatExceptionCode; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatsCollector; @@ -54,17 +53,13 @@ public class FlowUnitTxTask implements Runnable { */ private final DataMsg dataMsg; - private final AppContext appContext; - public FlowUnitTxTask( final NetClient client, final SubscriptionManager subscriptionManager, - final DataMsg dataMsg, - final AppContext appContext) { + final DataMsg dataMsg) { this.client = client; this.subscriptionManager = subscriptionManager; this.dataMsg = dataMsg; - this.appContext = appContext; } /** @@ -75,8 +70,7 @@ public FlowUnitTxTask( @Override public void run() { final String sourceNode = dataMsg.getSourceNode(); - final String esNode = appContext.getMyInstanceDetails().getInstanceIp(); - + final String esNode = ClusterUtils.getCurrentNodeHostAddress(); if (subscriptionManager.isNodeSubscribed(sourceNode)) { final Set downstreamHostAddresses = subscriptionManager .getSubscribersFor(sourceNode); diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/SubscriptionTxTask.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/SubscriptionTxTask.java index ed47c51ba..20eece40f 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/SubscriptionTxTask.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/SubscriptionTxTask.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.tasks; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.SubscribeMessage; import com.amazon.opendistro.elasticsearch.performanceanalyzer.net.NetClient; @@ -25,7 +24,6 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.SubscribeResponseHandler; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.SubscriptionManager; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.util.ClusterUtils; -import java.util.List; import java.util.Map; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -57,19 +55,15 @@ public abstract class SubscriptionTxTask implements Runnable { */ protected final NodeStateManager nodeStateManager; - private final AppContext appContext; - public SubscriptionTxTask( final NetClient netClient, final IntentMsg intentMsg, final SubscriptionManager subscriptionManager, - final NodeStateManager nodeStateManager, - final AppContext appContext) { + final NodeStateManager nodeStateManager) { this.netClient = netClient; this.intentMsg = intentMsg; this.subscriptionManager = subscriptionManager; this.nodeStateManager = nodeStateManager; - this.appContext = appContext; } protected void sendSubscribeRequest(final String remoteHost, final String requesterVertex, @@ -79,9 +73,9 @@ protected void sendSubscribeRequest(final String remoteHost, final String reques .setDestinationNode(destinationVertex) .setRequesterNode(requesterVertex) .putTags("locus", tags.get("locus")) - .putTags( - "requester", - appContext.getMyInstanceDetails().getInstanceIp()) + .putTags("requester", + ClusterUtils + .getCurrentNodeHostAddress()) .build(); netClient.subscribe(remoteHost, subscribeMessage, new SubscribeResponseHandler(subscriptionManager, nodeStateManager, remoteHost, @@ -90,8 +84,4 @@ protected void sendSubscribeRequest(final String remoteHost, final String reques .updateStat(RcaGraphMetrics.RCA_NODES_SUB_REQ_COUNT, requesterVertex + ":" + destinationVertex, 1); } - - public List getPeerIps() { - return appContext.getPeerInstanceIps(); - } } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/UnicastSubscriptionTxTask.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/UnicastSubscriptionTxTask.java index 981950b69..15759747f 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/UnicastSubscriptionTxTask.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/tasks/UnicastSubscriptionTxTask.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.tasks; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.net.NetClient; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.messages.UnicastIntentMsg; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.NodeStateManager; @@ -36,9 +35,8 @@ public UnicastSubscriptionTxTask( NetClient netClient, UnicastIntentMsg intentMsg, SubscriptionManager subscriptionManager, - NodeStateManager nodeStateManager, - final AppContext appContext) { - super(netClient, intentMsg, subscriptionManager, nodeStateManager, appContext); + NodeStateManager nodeStateManager) { + super(netClient, intentMsg, subscriptionManager, nodeStateManager); this.destinationHostAddress = intentMsg.getUnicastDestinationHostAddress(); } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCAScheduler.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCAScheduler.java index 46f1518f7..6ef46fe7c 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCAScheduler.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCAScheduler.java @@ -15,16 +15,13 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.NodeRole; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.ConnectedComponent; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.Queryable; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.ThresholdMain; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.WireHopper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.persistence.Persistable; -import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.sql.SQLException; import java.util.List; @@ -51,9 +48,7 @@ public class RCAScheduler { private WireHopper net; private boolean shutdownRequested; private volatile RcaSchedulerState schedulerState = RcaSchedulerState.STATE_NOT_STARTED; - private final NodeRole role; - private final AppContext appContext; - + private NodeRole role = NodeRole.UNKNOWN; final ThreadFactory schedThreadFactory = new ThreadFactoryBuilder().setNameFormat("sched-%d").setDaemon(true).build(); @@ -71,6 +66,7 @@ public class RCAScheduler { Persistable persistable; static final int PERIODICITY_SECONDS = 1; static final int PERIODICITY_IN_MS = PERIODICITY_SECONDS * 1000; + ScheduledFuture futureHandle; private static final Logger LOG = LogManager.getLogger(RCAScheduler.class); @@ -80,8 +76,7 @@ public RCAScheduler( RcaConf rcaConf, ThresholdMain thresholdMain, Persistable persistable, - WireHopper net, - final AppContext appContext) { + WireHopper net) { this.connectedComponents = connectedComponents; this.db = db; this.rcaConf = rcaConf; @@ -89,8 +84,6 @@ public RCAScheduler( this.persistable = persistable; this.net = net; this.shutdownRequested = false; - this.appContext = appContext; - this.role = this.appContext.getMyInstanceDetails().getRole(); } public void start() { @@ -103,14 +96,7 @@ public void start() { schedulerState = RcaSchedulerState.STATE_STARTED; final RCASchedulerTask task = new RCASchedulerTask( - 10000, - rcaSchedulerPeriodicExecutor, - connectedComponents, - db, - persistable, - rcaConf, - net, - appContext); + 10000, rcaSchedulerPeriodicExecutor, connectedComponents, db, persistable, rcaConf, net); while (schedulerState == RcaSchedulerState.STATE_STARTED) { try { long startTime = System.currentTimeMillis(); @@ -176,8 +162,7 @@ public NodeRole getRole() { return role; } - @VisibleForTesting - public void setQueryable(Queryable queryable) { - this.db = queryable; + public void setRole(NodeRole role) { + this.role = role; } } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCASchedulerTask.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCASchedulerTask.java index d070da058..71c347c0f 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCASchedulerTask.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCASchedulerTask.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.ConnectedComponent; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.Node; @@ -102,8 +101,7 @@ public RCASchedulerTask( final Queryable db, final Persistable persistable, final RcaConf conf, - final WireHopper hopper, - final AppContext appContext) { + final WireHopper hopper) { this.maxTicks = maxTicks; this.executorPool = executorPool; this.remotelyDesirableNodeSet = new HashMap<>(); @@ -118,8 +116,7 @@ public RCASchedulerTask( hopper, db, persistable, - nodeTaskletMap, - appContext); + nodeTaskletMap); // Merge the list across connected components. dependencyOrderedLocallyExecutables = @@ -176,13 +173,12 @@ public static List> mergeLists(List> l1, List> l2) { * @return a level ordered list of Tasklets. */ private List> getLocallyExecutableNodes( - final List>> orderedNodes, - final RcaConf conf, - final WireHopper hopper, - final Queryable db, - final Persistable persistable, - final Map, Tasklet> nodeTaskletMap, - final AppContext appContext) { + List>> orderedNodes, + RcaConf conf, + WireHopper hopper, + Queryable db, + Persistable persistable, + Map, Tasklet> nodeTaskletMap) { // This is just used for membership check in the createTaskletAndSendIntent. If a node is // present here, then the tasklet corresponding to it will be doing local evaluation or else, // the tasklet will read data from the read API provided by the wirehopper. @@ -194,8 +190,6 @@ private List> getLocallyExecutableNodes( for (List> levelNodes : orderedNodes) { List locallyExecutableInThisLevel = new ArrayList<>(); for (Node node : levelNodes) { - node.setAppContext(appContext); - if (RcaUtil.shouldExecuteLocally(node, conf)) { // This node will be executed locally, so add it to the set to keep track of this. locallyExecutableSet.add(node); diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HighHeapUsageClusterRca.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HighHeapUsageClusterRca.java index ae8ae4c93..f28ae6ed2 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HighHeapUsageClusterRca.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HighHeapUsageClusterRca.java @@ -25,8 +25,8 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.metrics.RcaVerticesMetrics; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -80,8 +80,9 @@ private List getUnhealthyNodeList() { List unhealthyNodeList = new ArrayList<>(); ConcurrentMap>> currentMap = this.nodeStateCache.asMap(); - for (InstanceDetails nodeDetails : getDataNodeInstances()) { - ImmutableList> nodeStateList = currentMap.get(nodeDetails.getInstanceId()); + for (ClusterDetailsEventProcessor.NodeDetails nodeDetails : ClusterDetailsEventProcessor + .getDataNodesDetails()) { + ImmutableList> nodeStateList = currentMap.get(nodeDetails.getId()); if (nodeStateList != null) { List oldGenSummaries = new ArrayList<>(); List youngGenSummaries = new ArrayList<>(); @@ -101,7 +102,7 @@ else if (resourceSummary.getResource().getResourceEnum() == ResourceEnum.OLD_GEN // youngGenSummaries can have multiple elements but we will only consider it as unhealthy if // three consecutive summaries are all unhealthy and we will then pick the first element as the summary for output. if (youngGenSummaries.size() >= UNHEALTHY_FLOWUNIT_THRESHOLD || oldGenSummaries.size() >= UNHEALTHY_FLOWUNIT_THRESHOLD) { - HotNodeSummary nodeSummary = new HotNodeSummary(nodeDetails.getInstanceId(), nodeDetails.getInstanceIp()); + HotNodeSummary nodeSummary = new HotNodeSummary(nodeDetails.getId(), nodeDetails.getHostAddress()); if (youngGenSummaries.size() >= UNHEALTHY_FLOWUNIT_THRESHOLD) { nodeSummary.appendNestedSummary(youngGenSummaries.get(0)); } @@ -149,8 +150,7 @@ public ResourceFlowUnit operate() { LOG.debug("Unhealthy node id list : {}", unhealthyNodeList); if (unhealthyNodeList.size() > 0) { context = new ResourceContext(Resources.State.UNHEALTHY); - summary = new HotClusterSummary( - getAllClusterInstances().size(), + summary = new HotClusterSummary(ClusterDetailsEventProcessor.getNodesDetails().size(), unhealthyNodeList.size()); for (HotNodeSummary unhealthyNodeSummary : unhealthyNodeList) { summary.appendNestedSummary(unhealthyNodeSummary); diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HotNodeClusterRca.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HotNodeClusterRca.java index b34aa1654..35e745a6c 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HotNodeClusterRca.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HotNodeClusterRca.java @@ -25,11 +25,13 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor.NodeDetails; import com.google.common.collect.HashBasedTable; import com.google.common.collect.ImmutableList; import com.google.common.collect.Table; + import java.time.Clock; import java.util.ArrayList; import java.util.Comparator; @@ -52,7 +54,7 @@ public class HotNodeClusterRca extends Rca> private final Table nodeTable; private final int rcaPeriod; private int counter; - private List dataNodesDetails; + private List dataNodesDetails; private double unbalancedResourceThreshold; private double resourceUsageLowerBoundThreshold; protected Clock clock; @@ -110,15 +112,15 @@ private ResourceFlowUnit checkUnbalancedNode() { final List resourceTypeColumnKeys = ImmutableList.copyOf(nodeTable.columnKeySet()); for (Resource resourceType : resourceTypeColumnKeys) { List resourceUsages = new ArrayList<>(); - for (InstanceDetails nodeDetail : dataNodesDetails) { - NodeResourceUsage currentUsage = nodeTable.get(nodeDetail.getInstanceId(), resourceType); + for (NodeDetails nodeDetail : dataNodesDetails) { + NodeResourceUsage currentUsage = nodeTable.get(nodeDetail.getId(), resourceType); // some node does not has this resource type in table. if (currentUsage == null) { continue; } // drop the value if the timestamp expires if (currTimestamp - currentUsage.timestamp > TimeUnit.MINUTES.toMillis(TIMESTAMP_EXPIRATION_IN_MINS)) { - nodeTable.row(nodeDetail.getInstanceId()).remove(resourceType); + nodeTable.row(nodeDetail.getId()).remove(resourceType); continue; } resourceUsages.add(currentUsage); @@ -145,8 +147,8 @@ private ResourceFlowUnit checkUnbalancedNode() { double medium = resourceUsages.get(mediumIdx).resourceSummary.getValue(); //iterate the nodeid list again and check if some node is unbalanced - for (InstanceDetails nodeDetail : dataNodesDetails) { - NodeResourceUsage currentUsage = nodeTable.get(nodeDetail.getInstanceId(), resourceType); + for (NodeDetails nodeDetail : dataNodesDetails) { + NodeResourceUsage currentUsage = nodeTable.get(nodeDetail.getId(), resourceType); if (currentUsage == null) { continue; } @@ -156,11 +158,11 @@ private ResourceFlowUnit checkUnbalancedNode() { if (currentUsage.resourceSummary.getValue() >= medium * (1 + unbalancedResourceThreshold) && currentUsage.resourceSummary.getValue() >= currentUsage.resourceSummary.getThreshold() * resourceUsageLowerBoundThreshold) { - if (!nodeSummaryMap.containsKey(nodeDetail.getInstanceId())) { - nodeSummaryMap.put(nodeDetail.getInstanceId(), - new HotNodeSummary(nodeDetail.getInstanceId(), nodeDetail.getInstanceIp())); + if (!nodeSummaryMap.containsKey(nodeDetail.getId())) { + nodeSummaryMap.put(nodeDetail.getId(), + new HotNodeSummary(nodeDetail.getId(), nodeDetail.getHostAddress())); } - nodeSummaryMap.get(nodeDetail.getInstanceId()).appendNestedSummary(currentUsage.resourceSummary); + nodeSummaryMap.get(nodeDetail.getId()).appendNestedSummary(currentUsage.resourceSummary); } } } @@ -185,8 +187,8 @@ private ResourceFlowUnit checkUnbalancedNode() { // so we don't have to keep polling the NodeDetails in every time window. private void removeInactiveNodeFromTable() { Set nodeIdSet = new HashSet<>(); - for (InstanceDetails nodeDetail : dataNodesDetails) { - nodeIdSet.add(nodeDetail.getInstanceId()); + for (NodeDetails nodeDetail : dataNodesDetails) { + nodeIdSet.add(nodeDetail.getId()); } for (String nodeId : nodeTable.rowKeySet()) { if (!nodeIdSet.contains(nodeId)) { @@ -197,7 +199,7 @@ private void removeInactiveNodeFromTable() { @Override public ResourceFlowUnit operate() { - dataNodesDetails = getDataNodeInstances(); + dataNodesDetails = ClusterDetailsEventProcessor.getDataNodesDetails(); //skip this RCA if the cluster has only single data node if (dataNodesDetails.size() <= 1) { return new ResourceFlowUnit<>(System.currentTimeMillis()); diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HotNodeRca.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HotNodeRca.java index 79de8b31c..d7202a1a6 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HotNodeRca.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/HotNodeRca.java @@ -22,8 +22,9 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.flow_units.ResourceFlowUnit; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.GenericSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -77,9 +78,9 @@ public ResourceFlowUnit operate() { if (counter == rcaPeriod) { ResourceContext context; - - InstanceDetails instanceDetails = getInstanceDetails(); - HotNodeSummary summary = new HotNodeSummary(instanceDetails.getInstanceId(), instanceDetails.getInstanceIp()); + ClusterDetailsEventProcessor.NodeDetails currentNode = ClusterDetailsEventProcessor + .getCurrentNodeDetails(); + HotNodeSummary summary = new HotNodeSummary(currentNode.getId(), currentNode.getHostAddress()); for (HotResourceSummary hotResourceSummary : hotResourceSummaryList) { summary.appendNestedSummary(hotResourceSummary); @@ -96,7 +97,7 @@ public ResourceFlowUnit operate() { hasUnhealthyFlowUnit = false; //check if the current node is data node. If it is the data node //then HotNodeRca is the top level RCA on this node and we want to persist summaries in flowunit. - boolean isDataNode = !instanceDetails.getIsMaster(); + boolean isDataNode = !currentNode.getIsMasterNode(); return new ResourceFlowUnit<>(System.currentTimeMillis(), context, summary, isDataNode); } else { return new ResourceFlowUnit<>(System.currentTimeMillis()); diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cache/FieldDataCacheRca.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cache/FieldDataCacheRca.java index a32bb5ad2..888ffd7ba 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cache/FieldDataCacheRca.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cache/FieldDataCacheRca.java @@ -31,8 +31,8 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.google.common.annotations.VisibleForTesting; import java.time.Clock; import java.util.ArrayList; @@ -112,12 +112,13 @@ public ResourceFlowUnit operate() { ResourceContext context; HotNodeSummary nodeSummary; - InstanceDetails instanceDetails = getInstanceDetails(); Boolean exceedsSizeThreshold = isSizeThresholdExceeded( fieldDataCacheSizeGroupByOperation, fieldDataCacheMaxSizeGroupByOperation, cacheSizeThreshold); if (cacheEvictionCollector.isUnhealthy(currTimestamp) && exceedsSizeThreshold) { context = new ResourceContext(Resources.State.UNHEALTHY); - nodeSummary = new HotNodeSummary(instanceDetails.getInstanceId(), instanceDetails.getInstanceIp()); + nodeSummary = new HotNodeSummary( + ClusterDetailsEventProcessor.getCurrentNodeDetails().getId(), + ClusterDetailsEventProcessor.getCurrentNodeDetails().getHostAddress()); nodeSummary.appendNestedSummary(cacheEvictionCollector.generateSummary(currTimestamp)); } else { @@ -126,7 +127,8 @@ public ResourceFlowUnit operate() { } counter = 0; - return new ResourceFlowUnit<>(currTimestamp, context, nodeSummary, !instanceDetails.getIsMaster()); + return new ResourceFlowUnit<>(currTimestamp, context, nodeSummary, + !ClusterDetailsEventProcessor.getCurrentNodeDetails().getIsMasterNode()); } else { return new ResourceFlowUnit<>(currTimestamp); diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cache/ShardRequestCacheRca.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cache/ShardRequestCacheRca.java index f0d69fb86..06bfa9993 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cache/ShardRequestCacheRca.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cache/ShardRequestCacheRca.java @@ -32,8 +32,8 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.google.common.annotations.VisibleForTesting; import java.time.Clock; import java.util.ArrayList; @@ -124,7 +124,6 @@ public ResourceFlowUnit operate() { ResourceContext context; HotNodeSummary nodeSummary; - InstanceDetails instanceDetails = getInstanceDetails(); Boolean exceedsSizeThreshold = isSizeThresholdExceeded( shardRequestCacheSizeGroupByOperation, shardRequestCacheMaxSizeGroupByOperation, cacheSizeThreshold); @@ -134,7 +133,9 @@ public ResourceFlowUnit operate() { && cacheHitCollector.isMetricPresentForThresholdTime(currTimestamp) && exceedsSizeThreshold) { context = new ResourceContext(Resources.State.UNHEALTHY); - nodeSummary = new HotNodeSummary(instanceDetails.getInstanceId(), instanceDetails.getInstanceIp()); + nodeSummary = new HotNodeSummary( + ClusterDetailsEventProcessor.getCurrentNodeDetails().getId(), + ClusterDetailsEventProcessor.getCurrentNodeDetails().getHostAddress()); nodeSummary.appendNestedSummary(cacheEvictionCollector.generateSummary(currTimestamp)); } else { context = new ResourceContext(Resources.State.HEALTHY); @@ -142,7 +143,8 @@ public ResourceFlowUnit operate() { } counter = 0; - return new ResourceFlowUnit<>(currTimestamp, context, nodeSummary, !instanceDetails.getIsMaster()); + return new ResourceFlowUnit<>(currTimestamp, context, nodeSummary, + !ClusterDetailsEventProcessor.getCurrentNodeDetails().getIsMasterNode()); } else { return new ResourceFlowUnit<>(currTimestamp); diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cluster/BaseClusterRca.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cluster/BaseClusterRca.java index 7195efef3..8c43830e2 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cluster/BaseClusterRca.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cluster/BaseClusterRca.java @@ -22,8 +22,9 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.flow_units.ResourceFlowUnit; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotClusterSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor.NodeDetails; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; @@ -114,12 +115,12 @@ private void addUpstreamFlowUnits(Rca> nodeRca) } } - private List getClusterNodesDetails() { + private List getClusterNodesDetails() { if (collectFromMasterNode) { - return getAllClusterInstances(); + return ClusterDetailsEventProcessor.getNodesDetails(); } else { - return getDataNodeInstances(); + return ClusterDetailsEventProcessor.getDataNodesDetails(); } } @@ -129,8 +130,8 @@ private List getClusterNodesDetails() { private void removeInactiveNodeFromNodeMap() { Set nodeIdSet = new HashSet<>(); List inactiveNodes = new ArrayList<>(); - for (InstanceDetails nodeDetail : getClusterNodesDetails()) { - nodeIdSet.add(nodeDetail.getInstanceId()); + for (NodeDetails nodeDetail : getClusterNodesDetails()) { + nodeIdSet.add(nodeDetail.getId()); } for (NodeKey nodeKey : nodeTable.rowKeySet()) { if (!nodeIdSet.contains(nodeKey.getNodeId())) { @@ -150,10 +151,10 @@ private void removeInactiveNodeFromNodeMap() { private ResourceFlowUnit generateFlowUnit() { List unhealthyNodeSummaries = new ArrayList<>(); long timestamp = clock.millis(); - List clusterNodesDetails = getClusterNodesDetails(); + List clusterNodesDetails = getClusterNodesDetails(); // iterate through this table - for (InstanceDetails nodeDetails : clusterNodesDetails) { - NodeKey nodeKey = new NodeKey(nodeDetails.getInstanceId(), nodeDetails.getInstanceIp()); + for (NodeDetails nodeDetails : clusterNodesDetails) { + NodeKey nodeKey = new NodeKey(nodeDetails.getId(), nodeDetails.getHostAddress()); // skip if the node is not found in table if (!nodeTable.containsRow(nodeKey)) { continue; diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cluster/NodeKey.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cluster/NodeKey.java index 4725297e6..bb37997a4 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cluster/NodeKey.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/cluster/NodeKey.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.cluster; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import org.apache.commons.lang3.builder.HashCodeBuilder; public class NodeKey { @@ -27,10 +26,6 @@ public NodeKey(String nodeId, String hostAddress) { this.hostAddress = hostAddress; } - public NodeKey(InstanceDetails instanceDetails) { - this(instanceDetails.getInstanceId(), instanceDetails.getInstanceIp()); - } - public String getNodeId() { return nodeId; } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/hotshard/HotShardClusterRca.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/hotshard/HotShardClusterRca.java index a01adfabf..ddc29d8d6 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/hotshard/HotShardClusterRca.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/hotshard/HotShardClusterRca.java @@ -28,8 +28,8 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.GenericSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; import java.util.ArrayList; @@ -184,7 +184,7 @@ public ResourceFlowUnit operate() { List hotShardSummaryList = new ArrayList<>(); ResourceContext context; HotClusterSummary summary = new HotClusterSummary( - getAllClusterInstances().size(), unhealthyNodes.size()); + ClusterDetailsEventProcessor.getNodesDetails().size(), unhealthyNodes.size()); // We evaluate hot shards individually on all the 3 dimensions findHotShardAndCreateSummary( @@ -203,10 +203,8 @@ public ResourceFlowUnit operate() { context = new ResourceContext(Resources.State.HEALTHY); } else { context = new ResourceContext(Resources.State.UNHEALTHY); - - InstanceDetails instanceDetails = getInstanceDetails(); - HotNodeSummary nodeSummary = new HotNodeSummary(instanceDetails.getInstanceId(), - instanceDetails.getInstanceIp()); + ClusterDetailsEventProcessor.NodeDetails currentNode = ClusterDetailsEventProcessor.getCurrentNodeDetails(); + HotNodeSummary nodeSummary = new HotNodeSummary(currentNode.getId(), currentNode.getHostAddress()); for (HotResourceSummary hotResourceSummary : hotShardSummaryList) { nodeSummary.appendNestedSummary(hotResourceSummary); } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/hotshard/HotShardRca.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/hotshard/HotShardRca.java index 84dc1289e..7caeed265 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/hotshard/HotShardRca.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/hotshard/HotShardRca.java @@ -21,6 +21,9 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.FlowUnitMessage; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.MetricEnum; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.Resource; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.ResourceEnum; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metricsdb.MetricsDB; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.configs.HotShardRcaConfig; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Metric; @@ -34,8 +37,8 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotShardSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import java.time.Clock; import java.util.ArrayList; import java.util.HashMap; @@ -161,15 +164,13 @@ public ResourceFlowUnit operate() { if (counter == rcaPeriod) { ResourceContext context = new ResourceContext(Resources.State.HEALTHY); - - InstanceDetails instanceDetails = getInstanceDetails(); + ClusterDetailsEventProcessor.NodeDetails currentNode = ClusterDetailsEventProcessor.getCurrentNodeDetails(); Set indexShardKeySet = new HashSet<>(cpuUtilizationMap.keySet()); indexShardKeySet.addAll(ioTotThroughputMap.keySet()); indexShardKeySet.addAll(ioTotSyscallRateMap.keySet()); - HotNodeSummary nodeSummary = new HotNodeSummary(instanceDetails.getInstanceId(), - instanceDetails.getInstanceIp()); + HotNodeSummary nodeSummary = new HotNodeSummary(currentNode.getId(), currentNode.getHostAddress()); for (IndexShardKey indexShardKey : indexShardKeySet) { double avgCpuUtilization = fetchUsageValueFromMap(cpuUtilizationMap, indexShardKey); double avgIoTotThroughput = fetchUsageValueFromMap(ioTotThroughputMap, indexShardKey); @@ -179,8 +180,7 @@ public ResourceFlowUnit operate() { || avgIoTotThroughput > ioTotThroughputThreshold || avgIoTotSyscallRate > ioTotSysCallRateThreshold) { HotShardSummary summary = new HotShardSummary(indexShardKey.getIndexName(), - String.valueOf(indexShardKey.getShardId()), instanceDetails.getInstanceId(), - SLIDING_WINDOW_IN_SECONDS); + String.valueOf(indexShardKey.getShardId()), currentNode.getId(), SLIDING_WINDOW_IN_SECONDS); summary.setcpuUtilization(avgCpuUtilization); summary.setCpuUtilizationThreshold(cpuUtilizationThreshold); summary.setIoThroughput(avgIoTotThroughput); @@ -199,7 +199,7 @@ public ResourceFlowUnit operate() { //check if the current node is data node. If it is the data node //then HotNodeRca is the top level RCA on this node and we want to persist summaries in flowunit. - boolean isDataNode = !instanceDetails.getIsMaster(); + boolean isDataNode = !currentNode.getIsMasterNode(); return new ResourceFlowUnit<>(this.clock.millis(), context, nodeSummary, isDataNode); } else { LOG.debug("Empty FlowUnit returned for Hot Shard RCA"); diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/remediation/NodeConfigCollector.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/remediation/NodeConfigCollector.java index a05f0e4ce..4a38df7e7 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/remediation/NodeConfigCollector.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/remediation/NodeConfigCollector.java @@ -27,6 +27,7 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.persist.SQLParsingUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.cluster.NodeKey; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import java.util.HashMap; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -86,7 +87,9 @@ public NodeConfigFlowUnit operate() { } if (counter == rcaPeriod) { counter = 0; - NodeConfigFlowUnit flowUnits = new NodeConfigFlowUnit(System.currentTimeMillis(), new NodeKey(getInstanceDetails())); + NodeConfigFlowUnit flowUnits = new NodeConfigFlowUnit(System.currentTimeMillis(), + new NodeKey(ClusterDetailsEventProcessor.getCurrentNodeDetails().getId(), + ClusterDetailsEventProcessor.getCurrentNodeDetails().getHostAddress())); configResult.forEach(flowUnits::addConfig); return flowUnits; } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/temperature/NodeTemperatureRca.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/temperature/NodeTemperatureRca.java index b90f2c2cd..80dbadf70 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/temperature/NodeTemperatureRca.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/temperature/NodeTemperatureRca.java @@ -24,11 +24,11 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.temperature.CompactNodeSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.temperature.FullNodeTemperatureSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.temperature.NodeLevelDimensionalSummary; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.temperature.dimension.CpuUtilDimensionTemperatureRca; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.temperature.dimension.HeapAllocRateTemperatureRca; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.temperature.dimension.ShardSizeDimensionTemperatureRca; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import java.util.ArrayList; import java.util.List; import org.apache.logging.log4j.LogManager; @@ -128,11 +128,11 @@ public CompactNodeTemperatureFlowUnit operate() { private FullNodeTemperatureSummary buildNodeProfile( List dimensionProfiles) { - - InstanceDetails instanceDetails = getInstanceDetails(); + ClusterDetailsEventProcessor.NodeDetails currentNodeDetails = + ClusterDetailsEventProcessor.getCurrentNodeDetails(); FullNodeTemperatureSummary nodeProfile = new FullNodeTemperatureSummary( - instanceDetails.getInstanceId(), - instanceDetails.getInstanceIp()); + currentNodeDetails.getId(), + currentNodeDetails.getHostAddress()); for (NodeLevelDimensionalSummary profile : dimensionProfiles) { nodeProfile.updateNodeDimensionProfile(profile); } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/threadpool/QueueRejectionRca.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/threadpool/QueueRejectionRca.java index 8f52c7847..86763b433 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/threadpool/QueueRejectionRca.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/rca/threadpool/QueueRejectionRca.java @@ -18,7 +18,9 @@ import static com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.ThreadPoolDimension.THREAD_POOL_TYPE; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.FlowUnitMessage; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.MetricEnum; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.Resource; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.ResourceEnum; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.ThreadPoolType; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metricsdb.MetricsDB; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Metric; @@ -31,8 +33,8 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.google.common.annotations.VisibleForTesting; import java.time.Clock; import java.util.ArrayList; @@ -85,12 +87,16 @@ public ResourceFlowUnit operate() { } if (counter == rcaPeriod) { counter = 0; - InstanceDetails instanceDetails = getInstanceDetails(); - HotNodeSummary nodeSummary = new HotNodeSummary(instanceDetails.getInstanceId(), instanceDetails.getInstanceIp()); + ClusterDetailsEventProcessor.NodeDetails currentNode = ClusterDetailsEventProcessor + .getCurrentNodeDetails(); boolean hasUnhealthyQueue = false; + HotNodeSummary nodeSummary = null; for (QueueRejectionCollector collector : queueRejectionCollectors) { // if we've see thread pool rejection in the last 5 mins, the thread pool is considered as contended if (collector.isUnhealthy(currTimestamp)) { + if (nodeSummary == null) { + nodeSummary = new HotNodeSummary(currentNode.getId(), currentNode.getHostAddress()); + } nodeSummary.appendNestedSummary(collector.generateSummary(currTimestamp)); hasUnhealthyQueue = true; } @@ -102,7 +108,7 @@ public ResourceFlowUnit operate() { else { context = new ResourceContext(Resources.State.UNHEALTHY); } - boolean isDataNode = !instanceDetails.getIsMaster(); + boolean isDataNode = !currentNode.getIsMasterNode(); return new ResourceFlowUnit<>(currTimestamp, context, nodeSummary, isDataNode); } else { diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/util/ClusterUtils.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/util/ClusterUtils.java index da390a600..d9552f924 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/util/ClusterUtils.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/util/ClusterUtils.java @@ -1,20 +1,65 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.util; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor.NodeDetails; +import com.google.common.annotations.VisibleForTesting; + import java.util.List; +import java.util.stream.Collectors; /** * Utility class to get details about the nodes in the cluster. */ public class ClusterUtils { - public static boolean isHostAddressInCluster(final String hostAddress, final List clusterInstances) { - if (clusterInstances.size() > 0) { - for (InstanceDetails node : clusterInstances) { - if (node.getInstanceIp().equals(hostAddress)) { + + @VisibleForTesting + static final String EMPTY_STRING = ""; + + + /** + * Get the current host's ip address. + * + * @return The host address for the current node. + */ + public static String getCurrentNodeHostAddress() { + final NodeDetails currentNodeDetails = ClusterDetailsEventProcessor.getCurrentNodeDetails(); + if (currentNodeDetails != null) { + return currentNodeDetails.getHostAddress(); + } + + return EMPTY_STRING; + } + + /** + * Get host addresses for all the other nodes in the cluster. + * + * @return List of host addresses. + */ + public static List getAllPeerHostAddresses() { + return ClusterDetailsEventProcessor.getNodesDetails().stream() + .skip(1) + .map(NodeDetails::getHostAddress) + .collect(Collectors.toList()); + } + + /** + * Checks if the given host address is part of the cluster. + * + * @param hostAddress The host address to check membership for. + * @return true if the host address is part of the cluster, false otherwise. + */ + public static boolean isHostAddressInCluster(final String hostAddress) { + final List nodes = ClusterDetailsEventProcessor.getNodesDetails(); + + if (nodes.size() > 0) { + for (NodeDetails node : nodes) { + if (node.getHostAddress() + .equals(hostAddress)) { return true; } } } + return false; } } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ClusterDetailsEventProcessor.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ClusterDetailsEventProcessor.java index 155f86ab1..03ae8cb0d 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ClusterDetailsEventProcessor.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ClusterDetailsEventProcessor.java @@ -20,7 +20,6 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.RcaControllerHelper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader_writer_shared.Event; import com.amazon.opendistro.elasticsearch.performanceanalyzer.util.JsonConverter; -import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Collections; @@ -115,7 +114,6 @@ public static List getDataNodesDetails() { } } - @Deprecated public static NodeDetails getCurrentNodeDetails() { List allNodes = getNodesDetails(); if (allNodes.size() > 0) { @@ -132,7 +130,7 @@ public static class NodeDetails { private String role; private Boolean isMasterNode; - NodeDetails(String stringifiedMetrics) { + public NodeDetails(String stringifiedMetrics) { Map map = JsonConverter .createMapFrom(stringifiedMetrics); id = (String) map.get(AllMetrics.NodeDetailColumns.ID.toString()); @@ -142,14 +140,6 @@ public static class NodeDetails { isMasterNode = isMasterNodeObject != null ? (Boolean) isMasterNodeObject : null; } - @VisibleForTesting - public NodeDetails(AllMetrics.NodeRole role, String id, String hostAddress, boolean isMaster) { - this.id = id; - this.hostAddress = hostAddress; - this.isMasterNode = isMaster; - this.role = role.toString(); - } - @Override public String toString() { StringBuilder stringBuilder = new StringBuilder(); diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessor.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessor.java index eaa4cd804..759bb33d5 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessor.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessor.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.reader; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatExceptionCode; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.PluginSettings; @@ -67,8 +66,6 @@ public class ReaderMetricsProcessor implements Runnable { private static final Map TIMING_STATS = new HashMap<>(); private static final Map STATS_DATA = new HashMap<>(); - private final AppContext appContext; - static { STATS_DATA.put("MethodName", "ProcessMetrics"); } @@ -86,10 +83,10 @@ public static ReaderMetricsProcessor getInstance() { } public ReaderMetricsProcessor(String rootLocation) throws Exception { - this(rootLocation, false, null); + this(rootLocation, false); } - public ReaderMetricsProcessor(String rootLocation, boolean processNewFormat, final AppContext appContext) throws Exception { + public ReaderMetricsProcessor(String rootLocation, boolean processNewFormat) throws Exception { conn = DriverManager.getConnection(DB_URL); create = DSL.using(conn, SQLDialect.SQLITE); metricsDBMap = new ConcurrentSkipListMap<>(); @@ -106,7 +103,6 @@ public ReaderMetricsProcessor(String rootLocation, boolean processNewFormat, fin } eventLogFileHandler = new EventLogFileHandler(new EventLog(), rootLocation); this.processNewFormat = processNewFormat; - this.appContext = appContext; } @Override @@ -437,9 +433,6 @@ is ready so it starts to read that file (go back two windows and NodeMetricsEventProcessor.buildNodeMetricEventsProcessor( currWindowStartTime, conn, nodeMetricsMap); EventProcessor clusterDetailsEventsProcessor = new ClusterDetailsEventProcessor(); - if (appContext != null) { - appContext.setClusterDetailsEventProcessor((ClusterDetailsEventProcessor) clusterDetailsEventsProcessor); - } // The event dispatcher dispatches events to each of the registered event processors. // In addition to event processing each processor has an initialize/finalize function that is diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java index 5b741293b..cfc4b9594 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rest; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatExceptionCode; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.core.Util; @@ -26,7 +25,7 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.model.MetricAttributes; import com.amazon.opendistro.elasticsearch.performanceanalyzer.model.MetricsModel; import com.amazon.opendistro.elasticsearch.performanceanalyzer.net.NetClient; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ReaderMetricsProcessor; import com.amazon.opendistro.elasticsearch.performanceanalyzer.util.JsonConverter; import com.sun.net.httpserver.HttpExchange; @@ -63,12 +62,10 @@ public class QueryMetricsRequestHandler extends MetricsHandler implements HttpHa private static final TimeUnit TIME_OUT_UNIT = TimeUnit.SECONDS; private NetClient netClient; MetricsRestUtil metricsRestUtil; - private final AppContext appContext; - public QueryMetricsRequestHandler(NetClient netClient, MetricsRestUtil metricsRestUtil, final AppContext appContext) { + public QueryMetricsRequestHandler(NetClient netClient, MetricsRestUtil metricsRestUtil) { this.netClient = netClient; this.metricsRestUtil = metricsRestUtil; - this.appContext = appContext; } @Override @@ -151,10 +148,11 @@ public void handle(HttpExchange exchange) throws IOException { String localResponseWithTimestamp = String.format("{\"timestamp\": %d, \"data\": %s}", dbTimestamp, localResponse); ConcurrentHashMap nodeResponses = new ConcurrentHashMap<>(); - final List allNodes = appContext.getAllClusterInstances(); + final List allNodes = ClusterDetailsEventProcessor + .getNodesDetails(); String localNodeId = "local"; if (allNodes.size() != 0) { - localNodeId = allNodes.get(0).getInstanceId(); + localNodeId = allNodes.get(0).getId(); } nodeResponses.put(localNodeId, localResponseWithTimestamp); String response = metricsRestUtil.nodeJsonBuilder(nodeResponses); @@ -164,14 +162,14 @@ public void handle(HttpExchange exchange) throws IOException { } else if (nodes.equals("all")) { CountDownLatch doneSignal = new CountDownLatch(allNodes.size() - 1); for (int i = 1; i < allNodes.size(); i++) { - InstanceDetails node = allNodes.get(i); + ClusterDetailsEventProcessor.NodeDetails node = allNodes.get(i); LOG.debug("Collecting remote stats"); try { collectRemoteStats(node, metricList, aggList, dimList, nodeResponses, doneSignal); } catch (Exception e) { LOG.error( "Unable to collect stats for node, addr:{}, exception: {} ExceptionCode: {}", - node.getInstanceIp(), + node.getHostAddress(), e, StatExceptionCode.REQUEST_REMOTE_ERROR.toString()); StatsCollector.instance().logException(StatExceptionCode.REQUEST_REMOTE_ERROR); @@ -218,12 +216,14 @@ public void handle(HttpExchange exchange) throws IOException { } void collectRemoteStats( - InstanceDetails node, + ClusterDetailsEventProcessor.NodeDetails node, List metricList, List aggList, List dimList, final ConcurrentHashMap nodeResponses, - final CountDownLatch doneSignal) { + final CountDownLatch doneSignal) + throws Exception { + // create a request MetricsRequest request = MetricsRequest.newBuilder() .addAllMetricList(metricList) @@ -233,7 +233,7 @@ void collectRemoteStats( ThreadSafeStreamObserver responseObserver = new ThreadSafeStreamObserver(node, nodeResponses, doneSignal); try { - this.netClient.getMetrics(node.getInstanceIp(), request, responseObserver); + this.netClient.getMetrics(node.getHostAddress(), request, responseObserver); } catch (Exception e) { LOG.error("Metrics : Exception occurred while getting Metrics {}", e.getCause()); } @@ -319,10 +319,10 @@ private void sendResponse(HttpExchange exchange, String response, int status) th private static class ThreadSafeStreamObserver implements StreamObserver { private final CountDownLatch doneSignal; private final ConcurrentHashMap nodeResponses; - private final InstanceDetails node; + private final ClusterDetailsEventProcessor.NodeDetails node; ThreadSafeStreamObserver( - InstanceDetails node, + ClusterDetailsEventProcessor.NodeDetails node, ConcurrentHashMap nodeResponses, CountDownLatch doneSignal) { this.node = node; @@ -331,12 +331,12 @@ private static class ThreadSafeStreamObserver implements StreamObserver rcaList) { // check if we are querying from elected master private boolean validNodeRole() { - return appContext.getMyInstanceDetails().getIsMaster(); + ClusterDetailsEventProcessor.NodeDetails currentNode = ClusterDetailsEventProcessor + .getCurrentNodeDetails(); + return currentNode.getIsMasterNode(); } private JsonElement getRcaData(Persistable persistable, List rcaList) { diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/RcaStatsCollectorTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/RcaStatsCollectorTest.java index a4ae85a79..f27e01a64 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/RcaStatsCollectorTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/RcaStatsCollectorTest.java @@ -15,9 +15,7 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.RcaTestHelper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.AnalysisGraph; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Metric; @@ -36,10 +34,8 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.RCASchedulerTask; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.spec.MetricsDBProviderTestHelper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.stats.measurements.MeasurementSet; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import java.nio.file.Paths; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.concurrent.Executors; @@ -102,17 +98,6 @@ public void rcaGraphMetrics() throws Exception { RcaUtil.getAnalysisGraphComponents(new FaultyAnalysisGraph()); RcaConf rcaConf = new RcaConf(Paths.get(RcaConsts.TEST_CONFIG_PATH, "rca.conf").toString()); - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - clusterDetailsEventProcessor.setNodesDetails( - Collections.singletonList(new ClusterDetailsEventProcessor.NodeDetails( - AllMetrics.NodeRole.UNKNOWN, - "node1", - "127.0.0.1", - false)) - ); - AppContext appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); - RCASchedulerTask rcaSchedulerTask = new RCASchedulerTask( 1000, @@ -121,8 +106,7 @@ public void rcaGraphMetrics() throws Exception { new MetricsDBProviderTestHelper(true), null, rcaConf, - null, - appContext); + null); rcaSchedulerTask.run(); StatsCollector statsCollector = new StatsCollector("test-stats", 0, new HashMap<>()); diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDeciderTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDeciderTest.java index b3267b9a8..5febda9ab 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDeciderTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDeciderTest.java @@ -19,7 +19,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.actions.Action; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.ResourceEnum; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.NodeRole; @@ -28,47 +27,29 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.cluster.QueueRejectionClusterRca; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; -import java.util.ArrayList; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; +import java.sql.SQLException; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.junit.Before; import org.junit.Test; public class QueueHealthDeciderTest { - AppContext appContext; @Before - public void setupCluster() { - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - ClusterDetailsEventProcessor.NodeDetails node1 = - new ClusterDetailsEventProcessor.NodeDetails(NodeRole.DATA, "node1", "127.0.0.1", false); - ClusterDetailsEventProcessor.NodeDetails node2 = - new ClusterDetailsEventProcessor.NodeDetails(NodeRole.DATA, "node2", "127.0.0.2", false); - ClusterDetailsEventProcessor.NodeDetails node3 = - new ClusterDetailsEventProcessor.NodeDetails(NodeRole.DATA, "node3", "127.0.0.3", false); - ClusterDetailsEventProcessor.NodeDetails node4 = - new ClusterDetailsEventProcessor.NodeDetails(NodeRole.DATA, "node3", "127.0.0.4", false); - ClusterDetailsEventProcessor.NodeDetails master = - new ClusterDetailsEventProcessor.NodeDetails(NodeRole.ELECTED_MASTER, "master", "127.0.0.9", true); - - List nodes = new ArrayList<>(); - nodes.add(node1); - nodes.add(node2); - nodes.add(node3); - nodes.add(node4); - nodes.add(master); - clusterDetailsEventProcessor.setNodesDetails(nodes); - - appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); + public void setupCluster() throws SQLException, ClassNotFoundException { + ClusterDetailsEventProcessorTestHelper clusterDetailsEventProcessorTestHelper = new ClusterDetailsEventProcessorTestHelper(); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node1", "127.0.0.1", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node2", "127.0.0.2", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node3", "127.0.0.3", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node4", "127.0.0.4", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("master", "127.0.0.9", NodeRole.ELECTED_MASTER, true); + clusterDetailsEventProcessorTestHelper.generateClusterDetailsEvent(); } @Test public void testHighRejectionRemediation() { RcaTestHelper nodeRca = new RcaTestHelper<>("QueueRejectionNodeRca"); - nodeRca.setAppContext(appContext); // node1: Both write and search queues unhealthy // node2: Only write unhealthy // node3: Only search unhealthy @@ -82,7 +63,6 @@ public void testHighRejectionRemediation() { ); QueueRejectionClusterRca queueClusterRca = new QueueRejectionClusterRca(1, nodeRca); - queueClusterRca.setAppContext(appContext); queueClusterRca.generateFlowUnitListFromLocal(null); QueueHealthDecider decider = new QueueHealthDecider(5, 12, queueClusterRca); diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaControllerTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaControllerTest.java index cb8ef36a0..525baee15 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaControllerTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaControllerTest.java @@ -2,7 +2,6 @@ import static com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.RcaTestHelper.updateConfFileForMutedRcas; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.ClientServers; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerThreads; @@ -72,7 +71,7 @@ public void setUp() throws Exception { 3, new ThreadFactoryBuilder().setNameFormat("test-network-thread-%d").build()); boolean useHttps = PluginSettings.instance().getHttpsEnabled(); connectionManager = new GRPCConnectionManager(useHttps); - clientServers = PerformanceAnalyzerApp.createClientServers(connectionManager, new AppContext()); + clientServers = PerformanceAnalyzerApp.createClientServers(connectionManager); clientServers.getHttpServer().start(); URI uri = URI.create(RcaController.getCatMasterUrl()); @@ -113,8 +112,7 @@ public void setUp() throws Exception { clientServers, rcaEnabledFileLoc.toString(), 100, - 200, - new AppContext() + 200 ); setMyIp(masterIP, AllMetrics.NodeRole.UNKNOWN); @@ -370,7 +368,6 @@ private void setMyIp(String ip, AllMetrics.NodeRole nodeRole) { ClusterDetailsEventProcessor eventProcessor = new ClusterDetailsEventProcessor(); eventProcessor.processEvent( new Event("", jtime.toString() + System.lineSeparator() + jNode.toString(), 0)); - rcaController.getAppContext().setClusterDetailsEventProcessor(eventProcessor); } enum RcaState { @@ -394,7 +391,7 @@ private void changeRcaRunState(RcaState state) throws IOException { private boolean check(IEval eval, T expected) { final long SLEEP_TIME_MILLIS = 1000; - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 2; i++) { if (eval.evaluateAndCheck(expected)) { return true; } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaTestHelper.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaTestHelper.java index 60c32e797..ecf6fece8 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaTestHelper.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaTestHelper.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.ConnectedComponent; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.Node; @@ -130,7 +129,7 @@ public static void setEvaluationTimeForAllNodes(List connect } } - public static AppContext setMyIp(String ip, AllMetrics.NodeRole nodeRole) { + public static void setMyIp(String ip, AllMetrics.NodeRole nodeRole) { JSONObject jtime = new JSONObject(); jtime.put("current_time", 1566414001749L); @@ -144,9 +143,6 @@ public static AppContext setMyIp(String ip, AllMetrics.NodeRole nodeRole) { ClusterDetailsEventProcessor eventProcessor = new ClusterDetailsEventProcessor(); eventProcessor.processEvent( new Event("", jtime.toString() + System.lineSeparator() + jNode.toString(), 0)); - AppContext appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(eventProcessor); - return appContext; } public static void truncate(File file) { diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListenerTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListenerTest.java index 9bdb732f0..70d26bdb3 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListenerTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListenerTest.java @@ -15,10 +15,8 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.listener; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatsCollector; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.RcaTestHelper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.AnalysisGraph; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Metric; @@ -32,7 +30,6 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.Stats; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaConsts; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.RCASchedulerTask; @@ -106,8 +103,7 @@ public void rcaMutedForThrowingExceptions() throws Exception { new MetricsDBProviderTestHelper(true), null, rcaConf, - null, - new AppContext()); + null); for (int i = 0; i <= MisbehavingGraphOperateMethodListener.TOLERANCE_LIMIT; i++) { rcaSchedulerTask.run(); diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/NodeStateManagerTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/NodeStateManagerTest.java index 5597e5129..490bc7d81 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/NodeStateManagerTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/NodeStateManagerTest.java @@ -1,6 +1,5 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.SubscribeResponse.SubscriptionStatus; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; @@ -28,7 +27,7 @@ public class NodeStateManagerTest { @Before public void setUp() { - this.testNodeStateManager = new NodeStateManager(new AppContext()); + this.testNodeStateManager = new NodeStateManager(); } @Test @@ -56,16 +55,12 @@ public void testNewNodesAddedToCluster() { testNodeStateManager .updateSubscriptionState(TEST_NODE_1, TEST_HOST_1, SubscriptionStatus.SUCCESS); - - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - clusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( + ClusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( EMPTY_DETAILS, ClusterDetailsEventProcessorTestHelper.newNodeDetails(null, TEST_HOST_1, false), ClusterDetailsEventProcessorTestHelper.newNodeDetails(null, TEST_HOST_2, false) )); - testNodeStateManager.getAppContext().setClusterDetailsEventProcessor(clusterDetailsEventProcessor); - ImmutableList hostsToSubscribeTo = testNodeStateManager.getStaleOrNotSubscribedNodes(TEST_NODE_1, TEN_S_IN_MILLIS, ImmutableSet.of(TEST_HOST_1)); @@ -86,14 +81,12 @@ public void testStaleNodesAndNewNodesAddedToCluster() { testNodeStateManager.updateReceiveTime(TEST_HOST_2, TEST_NODE_1, currentTime); testNodeStateManager.updateSubscriptionState(TEST_NODE_1, TEST_HOST_2, SubscriptionStatus.SUCCESS); - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - clusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( + ClusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( EMPTY_DETAILS, ClusterDetailsEventProcessorTestHelper.newNodeDetails(null, TEST_HOST_1, false), ClusterDetailsEventProcessorTestHelper.newNodeDetails(null, TEST_HOST_2, false), ClusterDetailsEventProcessorTestHelper.newNodeDetails(null, TEST_HOST_3, false) )); - testNodeStateManager.getAppContext().setClusterDetailsEventProcessor(clusterDetailsEventProcessor); ImmutableList hostsToSubscribeTo = testNodeStateManager.getStaleOrNotSubscribedNodes(TEST_NODE_1, TEN_S_IN_MILLIS, diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/SubscribeResponseHandlerTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/SubscribeResponseHandlerTest.java index 67ad59941..631a0ea22 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/SubscribeResponseHandlerTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/SubscribeResponseHandlerTest.java @@ -1,6 +1,5 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.SubscribeResponse; import com.amazon.opendistro.elasticsearch.performanceanalyzer.net.GRPCConnectionManager; import com.google.common.collect.Sets; @@ -20,7 +19,7 @@ public class SubscribeResponseHandlerTest { public void setup() { GRPCConnectionManager grpcConnectionManager = new GRPCConnectionManager(true); subscriptionManager = new SubscriptionManager(grpcConnectionManager); - nodeStateManager = new NodeStateManager(new AppContext()); + nodeStateManager = new NodeStateManager(); uut = new SubscribeResponseHandler(subscriptionManager, nodeStateManager, HOST, NODE); } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/WireHopperTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/WireHopperTest.java index 39f7290b0..32c7ac9d7 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/WireHopperTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/WireHopperTest.java @@ -1,6 +1,5 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.FlowUnitMessage; import com.amazon.opendistro.elasticsearch.performanceanalyzer.net.GRPCConnectionManager; import com.amazon.opendistro.elasticsearch.performanceanalyzer.net.NetClient; @@ -22,6 +21,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; + import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -30,6 +30,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; + import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -81,13 +82,11 @@ public static void setupClass() throws Exception { @Before public void setup() { - AppContext appContext = new AppContext(); - nodeStateManager = new NodeStateManager(appContext); + nodeStateManager = new NodeStateManager(); receivedFlowUnitStore = new ReceivedFlowUnitStore(); subscriptionManager = new SubscriptionManager(connectionManager); clientExecutor.set(null); - uut = new WireHopper(nodeStateManager, netClient, subscriptionManager, clientExecutor, receivedFlowUnitStore, - appContext); + uut = new WireHopper(nodeStateManager, netClient, subscriptionManager, clientExecutor, receivedFlowUnitStore); } @AfterClass @@ -111,13 +110,10 @@ public void testSendIntent() throws Exception { // verify method generates appropriate task clientExecutor.set(executorService); subscriptionManager.setCurrentLocus(RcaConsts.RcaTagConstants.LOCUS_DATA_NODE); - - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - clusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( + ClusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( ClusterDetailsEventProcessorTestHelper.newNodeDetails(NODE1, LOCALHOST, false), ClusterDetailsEventProcessorTestHelper.newNodeDetails(node.name(), LOCALHOST, false) )); - uut.getAppContext().setClusterDetailsEventProcessor(clusterDetailsEventProcessor); uut.sendIntent(msg); WaitFor.waitFor(() -> subscriptionManager.getSubscribersFor(node.name()).size() == 1, 5, TimeUnit.SECONDS); @@ -142,13 +138,10 @@ public void testSendData() throws Exception { subscriptionManager.setCurrentLocus(LOCUS); subscriptionManager.addSubscriber(NODE1, LOCALHOST, LOCUS); // verify sendData works - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - clusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( + ClusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( ClusterDetailsEventProcessorTestHelper.newNodeDetails(NODE1, LOCALHOST, false), ClusterDetailsEventProcessorTestHelper.newNodeDetails(NODE2, LOCALHOST, false) )); - uut.getAppContext().setClusterDetailsEventProcessor(clusterDetailsEventProcessor); - uut.sendData(msg); WaitFor.waitFor(() -> nodeStateManager.getLastReceivedTimestamp(NODE1, LOCALHOST) != 0, 1, TimeUnit.SECONDS); @@ -172,13 +165,9 @@ public void testReadFromWire() throws Exception { uut.readFromWire(node); // Execute test method and verify return value clientExecutor.set(executorService); - - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - clusterDetailsEventProcessor.setNodesDetails(Collections.singletonList( + ClusterDetailsEventProcessor.setNodesDetails(Collections.singletonList( ClusterDetailsEventProcessorTestHelper.newNodeDetails( node.name(), LOCALHOST, false))); - uut.getAppContext().setClusterDetailsEventProcessor(clusterDetailsEventProcessor); - subscriptionManager.setCurrentLocus(RcaConsts.RcaTagConstants.LOCUS_DATA_NODE); subscriptionManager.addPublisher(node.name(), LOCALHOST); subscriptionManager.addPublisher(node.name(), HOST_NOT_IN_CLUSTER); diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/persistence/PersistFlowUnitAndSummaryTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/persistence/PersistFlowUnitAndSummaryTest.java index 42dfec083..442da7f5d 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/persistence/PersistFlowUnitAndSummaryTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/persistence/PersistFlowUnitAndSummaryTest.java @@ -15,7 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.persistence; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerThreads; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.NodeRole; @@ -34,7 +33,6 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.Queryable; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.ThresholdMain; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaConsts; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaConsts.RcaTagConstants; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaUtil; @@ -44,14 +42,11 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.spec.MetricsDBProviderTestHelper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.HighHeapUsageClusterRca; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.HotNodeRca; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.threads.ThreadProvider; import com.amazon.opendistro.elasticsearch.performanceanalyzer.util.WaitFor; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Collections; -import java.util.List; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Assert; @@ -140,8 +135,7 @@ public void before() throws Exception { queryable = new MetricsDBProviderTestHelper(false); } - private RCAScheduler startScheduler(RcaConf rcaConf, AnalysisGraph graph, Persistable persistable, - Queryable queryable, AppContext appContext) { + private RCAScheduler startScheduler(RcaConf rcaConf, AnalysisGraph graph, Persistable persistable, Queryable queryable, NodeRole role) { RCAScheduler scheduler = new RCAScheduler( RcaUtil.getAnalysisGraphComponents(graph), @@ -150,10 +144,8 @@ private RCAScheduler startScheduler(RcaConf rcaConf, AnalysisGraph graph, Persis new ThresholdMain( Paths.get(RcaConsts.TEST_CONFIG_PATH, "thresholds").toString(), rcaConf), persistable, - new WireHopper(null, null, null, null, - null, appContext), - appContext - ); + new WireHopper(null, null, null, null, null)); + scheduler.setRole(role); ThreadProvider threadProvider = new ThreadProvider(); Thread rcaSchedulerThread = threadProvider.createThreadForRunnable(scheduler::start, PerformanceAnalyzerThreads.RCA_SCHEDULER); @@ -161,46 +153,24 @@ private RCAScheduler startScheduler(RcaConf rcaConf, AnalysisGraph graph, Persis return scheduler; } - private AppContext createAppContextWithDataNodes(String nodeName, NodeRole role, boolean isMaster) { - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - List nodes = new ArrayList<>(); - - ClusterDetailsEventProcessor.NodeDetails node1 = - new ClusterDetailsEventProcessor.NodeDetails(role, nodeName, "127.0.0.0", isMaster); - nodes.add(node1); - - clusterDetailsEventProcessor.setNodesDetails(nodes); - - AppContext appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); - return appContext; - } - - /** - * Add testPersistSummaryOnDataNode() and testPersistSummaryOnMasterNode() into a single UT - * This will force both tests to run in sequential and can avoid access contention to the - * same db file. - * @throws Exception SQL exception - */ @Test - public void testPersisSummary() throws Exception { + public void testPersistSummaryOnDataNode() throws Exception { + try { + ClusterDetailsEventProcessorTestHelper clusterDetailsEventProcessorTestHelper = new ClusterDetailsEventProcessorTestHelper(); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node1", "127.0.0.0", false); + clusterDetailsEventProcessorTestHelper.generateClusterDetailsEvent(); + } catch (Exception e) { + Assert.assertTrue("got exception when generating cluster details event", false); + return; + } + AnalysisGraph graph = new DataNodeGraph(); RcaConf rcaConf = new RcaConf(Paths.get(RcaConsts.TEST_CONFIG_PATH, "rca.conf").toString()); RcaConf masterRcaConf = new RcaConf(Paths.get(RcaConsts.TEST_CONFIG_PATH, "rca_elected_master.conf").toString()); Persistable persistable = PersistenceFactory.create(rcaConf); - testPersistSummaryOnDataNode(rcaConf, persistable); - testPersistSummaryOnMasterNode(masterRcaConf, persistable); - persistable.close(); - } - - private void testPersistSummaryOnDataNode(RcaConf rcaConf, Persistable persistable) throws Exception { - AppContext appContext = createAppContextWithDataNodes("node1", NodeRole.DATA, false); - - AnalysisGraph graph = new DataNodeGraph(); - RCAScheduler scheduler = startScheduler(rcaConf, graph, persistable, this.queryable, appContext); + RCAScheduler scheduler = startScheduler(rcaConf, graph, persistable, this.queryable, AllMetrics.NodeRole.DATA); // Wait at most 1 minute for the persisted data to show up with the correct contents WaitFor.waitFor(() -> { String readTableStr = persistable.read(); - System.out.println(readTableStr); if (readTableStr != null) { // HighHeapUsageClusterRcaX is a cluster level RCA so it should not be scheduled and persisted on // data node. @@ -213,10 +183,20 @@ private void testPersistSummaryOnDataNode(RcaConf rcaConf, Persistable persistab persistable.close(); } - private void testPersistSummaryOnMasterNode(RcaConf rcaConf, Persistable persistable) throws Exception { - AppContext appContext = createAppContextWithDataNodes("node1", NodeRole.DATA, true); + @Test + public void testPersistSummaryOnMasterNode() throws Exception { + try { + ClusterDetailsEventProcessorTestHelper clusterDetailsEventProcessorTestHelper = new ClusterDetailsEventProcessorTestHelper(); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node1", "127.0.0.0", true); + clusterDetailsEventProcessorTestHelper.generateClusterDetailsEvent(); + } catch (Exception e) { + Assert.assertTrue("got exception when generating cluster details event", false); + return; + } AnalysisGraph graph = new MasterNodeGraph(); - RCAScheduler scheduler = startScheduler(rcaConf, graph, persistable, this.queryable, appContext); + RcaConf rcaConf = new RcaConf(Paths.get(RcaConsts.TEST_CONFIG_PATH, "rca_elected_master.conf").toString()); + Persistable persistable = PersistenceFactory.create(rcaConf); + RCAScheduler scheduler = startScheduler(rcaConf, graph, persistable, this.queryable, NodeRole.ELECTED_MASTER); // Wait at most 1 minute for the persisted data to show up with the correct contents WaitFor.waitFor(() -> { String readTableStr = persistable.read(); diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCASchedulerTaskTests.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCASchedulerTaskTests.java index b1f43fc0f..3cbfe8987 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCASchedulerTaskTests.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RCASchedulerTaskTests.java @@ -17,8 +17,6 @@ import static org.junit.Assert.assertEquals; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.GradleTaskForRca; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.AnalysisGraph; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Metric; @@ -30,7 +28,6 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.Node; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.Queryable; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.messages.DataMsg; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.messages.IntentMsg; @@ -221,7 +218,7 @@ private WireHopperDerived(IntentMsg intentMsg, DataMsg dataMsg) { } private WireHopperDerived(List intentMsg, DataMsg dataMsg) { - super(null, null, null, null, null, new AppContext()); + super(null, null, null, null, null); this.intentMsgs = intentMsg; this.dataMsg = dataMsg; } @@ -253,8 +250,7 @@ private RCASchedulerTaskMock(RcaConf conf, WireHopper wireHopper) { null, null, conf, - wireHopper, - new AppContext()); + wireHopper); } } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RcaSchedulerAsyncTaskTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RcaSchedulerAsyncTaskTest.java index 0704b6570..531adcf27 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RcaSchedulerAsyncTaskTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/scheduler/RcaSchedulerAsyncTaskTest.java @@ -15,8 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.AnalysisGraph; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Metric; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Symptom; @@ -26,11 +24,9 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.metrics.Sched_Waittime; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.ConnectedComponent; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaConsts; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.spec.MetricsDBProviderTestHelper; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; @@ -126,8 +122,7 @@ public RcaSchedulerTaskT(List connectedComponents) throws Ex new MetricsDBProviderTestHelper(true), null, new RcaConf(Paths.get(RcaConsts.TEST_CONFIG_PATH, "rca.conf").toString()), - null, - new AppContext()); + null); } @Override diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/ResourceHeatMapGraphTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/ResourceHeatMapGraphTest.java index 3cc31e6a7..0efb71c8c 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/ResourceHeatMapGraphTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/store/ResourceHeatMapGraphTest.java @@ -22,7 +22,6 @@ import static com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaConsts.RcaTagConstants.TAG_LOCUS; import static com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.SQLiteQueryUtils.ALL_TEMPERATURE_DIMENSIONS; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.ClientServers; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; import com.amazon.opendistro.elasticsearch.performanceanalyzer.core.Util; @@ -46,7 +45,6 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.Stats; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.temperature.HeatZoneAssigner; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.temperature.TemperatureDimension; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaConsts; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.RcaUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.net.NodeStateManager; @@ -130,14 +128,14 @@ public static void init() { } AllMetrics.NodeRole nodeRole2 = AllMetrics.NodeRole.ELECTED_MASTER; - AppContext appContext = RcaTestHelper.setMyIp("192.168.0.2", nodeRole2); + RcaTestHelper.setMyIp("192.168.0.2", nodeRole2); connectionManager = new GRPCConnectionManager(false); - clientServers = PerformanceAnalyzerApp.createClientServers(connectionManager, new AppContext()); + clientServers = PerformanceAnalyzerApp.createClientServers(connectionManager); HttpServer httpServer = clientServers.getHttpServer(); httpServer.start(); - QueryRcaRequestHandler rcaRequestHandler = new QueryRcaRequestHandler(appContext); + QueryRcaRequestHandler rcaRequestHandler = new QueryRcaRequestHandler(); rcaRequestHandler.setPersistable(persistable); httpServer.createContext(Util.RCA_QUERY_URL, rcaRequestHandler); @@ -160,7 +158,7 @@ public void construct() { } } - private List createAndExecuteRcaGraph(AppContext appContext) { + private List createAndExecuteRcaGraph() { AnalysisGraph analysisGraph = new AnalysisGraphX(); List connectedComponents = RcaUtil.getAnalysisGraphComponents(analysisGraph); @@ -173,12 +171,11 @@ private List createAndExecuteRcaGraph(AppContext appContext) new SubscriptionManager(new GRPCConnectionManager(false)); subscriptionManager.setCurrentLocus(rcaConf.getTagMap().get("locus")); - WireHopper wireHopper = new WireHopper(new NodeStateManager(new AppContext()), clientServers.getNetClient(), + WireHopper wireHopper = new WireHopper(new NodeStateManager(), clientServers.getNetClient(), subscriptionManager, networkThreadPoolReference, - new ReceivedFlowUnitStore(rcaConf.getPerVertexBufferLength()), appContext); + new ReceivedFlowUnitStore(rcaConf.getPerVertexBufferLength())); - InstanceDetails instanceDetails = appContext.getMyInstanceDetails(); RCASchedulerTask rcaSchedulerTaskData = new RCASchedulerTask( 1000, @@ -187,10 +184,9 @@ private List createAndExecuteRcaGraph(AppContext appContext) reader, persistable, rcaConf, - wireHopper, - appContext); - - RcaTestHelper.setMyIp(instanceDetails.getInstanceIp(), instanceDetails.getRole()); + wireHopper); + AllMetrics.NodeRole nodeRole = AllMetrics.NodeRole.DATA; + RcaTestHelper.setMyIp("192.168.0.1", nodeRole); rcaSchedulerTaskData.run(); return connectedComponents; } @@ -266,9 +262,7 @@ private String makeRestRequest(final String[] params) { @Test public void clusterTemperatureProfile() { - AppContext appContext = RcaTestHelper.setMyIp("192.168.0.2", AllMetrics.NodeRole.ELECTED_MASTER); - - List connectedComponents = createAndExecuteRcaGraph(appContext); + List connectedComponents = createAndExecuteRcaGraph(); System.out.println("Now for the MAster RCA."); String masterNodeRcaConf = Paths.get(RcaConsts.TEST_CONFIG_PATH, "rca_elected_master.conf").toString(); @@ -277,13 +271,11 @@ public void clusterTemperatureProfile() { new SubscriptionManager(new GRPCConnectionManager(false)); subscriptionManager2.setCurrentLocus(rcaConf2.getTagMap().get("locus")); - - WireHopper wireHopper2 = new WireHopper(new NodeStateManager(new AppContext()), clientServers.getNetClient(), + WireHopper wireHopper2 = new WireHopper(new NodeStateManager(), clientServers.getNetClient(), subscriptionManager2, networkThreadPoolReference, - new ReceivedFlowUnitStore(rcaConf.getPerVertexBufferLength()), appContext); + new ReceivedFlowUnitStore(rcaConf.getPerVertexBufferLength())); - InstanceDetails instanceDetails = appContext.getMyInstanceDetails(); RCASchedulerTask rcaSchedulerTaskMaster = new RCASchedulerTask( 1000, @@ -292,10 +284,9 @@ public void clusterTemperatureProfile() { reader, persistable, rcaConf2, - wireHopper2, - appContext); - AllMetrics.NodeRole nodeRole2 = instanceDetails.getRole(); - RcaTestHelper.setMyIp(instanceDetails.getInstanceIp(), nodeRole2); + wireHopper2); + AllMetrics.NodeRole nodeRole2 = AllMetrics.NodeRole.ELECTED_MASTER; + RcaTestHelper.setMyIp("192.168.0.2", nodeRole2); rcaSchedulerTaskMaster.run(); testJsonResponse(makeRestRequest( @@ -304,8 +295,7 @@ public void clusterTemperatureProfile() { @Test public void fullNodeTemperatureProfile() { - AppContext appContext = RcaTestHelper.setMyIp("192.168.0.3", AllMetrics.NodeRole.DATA); - createAndExecuteRcaGraph(appContext); + createAndExecuteRcaGraph(); verifyFullNodeTemperatureProfile(makeRestRequest( new String[]{ "name", ALL_TEMPERATURE_DIMENSIONS, @@ -317,8 +307,7 @@ public void fullNodeTemperatureProfile() { // {"AllTemperatureDimensions":[]} @Test public void mutedTemperatureProfile() { - AppContext appContext = RcaTestHelper.setMyIp("192.168.0.7", AllMetrics.NodeRole.MASTER); - createAndExecuteRcaGraph(appContext); + createAndExecuteRcaGraph(); Set oldMuted = new HashSet<>(); for (String muted : Stats.getInstance().getMutedGraphNodes()) { @@ -1069,13 +1058,11 @@ public void testHotShardClusterApiResponse() { new SubscriptionManager(new GRPCConnectionManager(false)); subscriptionManager.setCurrentLocus(rcaConf.getTagMap().get("locus")); - AppContext appContext = RcaTestHelper.setMyIp("192.168.0.1", AllMetrics.NodeRole.DATA); - - WireHopper wireHopper = new WireHopper(new NodeStateManager(new AppContext()), clientServers.getNetClient(), + WireHopper wireHopper = new WireHopper(new NodeStateManager(), clientServers.getNetClient(), subscriptionManager, networkThreadPoolReference, - new ReceivedFlowUnitStore(rcaConf.getPerVertexBufferLength()), appContext); - InstanceDetails dataInstance = appContext.getMyInstanceDetails(); + new ReceivedFlowUnitStore(rcaConf.getPerVertexBufferLength())); + RCASchedulerTask rcaSchedulerTaskData = new RCASchedulerTask( 1000, @@ -1084,10 +1071,9 @@ public void testHotShardClusterApiResponse() { reader, persistable, rcaConf, - wireHopper, - appContext); - AllMetrics.NodeRole nodeRole = dataInstance.getRole(); - RcaTestHelper.setMyIp(dataInstance.getInstanceIp(), nodeRole); + wireHopper); + AllMetrics.NodeRole nodeRole = AllMetrics.NodeRole.DATA; + RcaTestHelper.setMyIp("192.168.0.1", nodeRole); rcaSchedulerTaskData.run(); String masterNodeRcaConf = @@ -1097,14 +1083,11 @@ public void testHotShardClusterApiResponse() { new SubscriptionManager(new GRPCConnectionManager(false)); subscriptionManager2.setCurrentLocus(rcaConf2.getTagMap().get("locus")); - AppContext appContextMaster = RcaTestHelper.setMyIp("192.168.0.4", AllMetrics.NodeRole.ELECTED_MASTER); - - WireHopper wireHopper2 = new WireHopper(new NodeStateManager(new AppContext()), clientServers.getNetClient(), + WireHopper wireHopper2 = new WireHopper(new NodeStateManager(), clientServers.getNetClient(), subscriptionManager2, networkThreadPoolReference, - new ReceivedFlowUnitStore(rcaConf.getPerVertexBufferLength()), appContextMaster); + new ReceivedFlowUnitStore(rcaConf.getPerVertexBufferLength())); - InstanceDetails masterInstance = appContextMaster.getMyInstanceDetails(); RCASchedulerTask rcaSchedulerTaskMaster = new RCASchedulerTask( 1000, @@ -1113,10 +1096,9 @@ public void testHotShardClusterApiResponse() { reader, persistable, rcaConf2, - wireHopper2, - appContextMaster); - AllMetrics.NodeRole nodeRole2 = masterInstance.getRole(); - RcaTestHelper.setMyIp(masterInstance.getInstanceIp(), nodeRole2); + wireHopper2); + AllMetrics.NodeRole nodeRole2 = AllMetrics.NodeRole.ELECTED_MASTER; + RcaTestHelper.setMyIp("1c", nodeRole2); rcaSchedulerTaskMaster.run(); URL url = null; diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/util/ClusterUtilsTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/util/ClusterUtilsTest.java index a491bb501..6f9c73731 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/util/ClusterUtilsTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/util/ClusterUtilsTest.java @@ -1,13 +1,9 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.util; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; import com.google.common.collect.Lists; -import java.util.ArrayList; import java.util.Collections; -import java.util.List; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -18,34 +14,48 @@ public class ClusterUtilsTest { private static final ClusterDetailsEventProcessor.NodeDetails EMPTY_DETAILS = ClusterDetailsEventProcessorTestHelper.newNodeDetails("", "", false); - private List getInstancesFromHost(List hostIps) { - List instances = new ArrayList<>(); - for (String ip: hostIps) { - InstanceDetails instance = new InstanceDetails(AllMetrics.NodeRole.UNKNOWN, "", ip, false); - instances.add(instance); - } - return instances; - } - @Before public void setup() { ClusterDetailsEventProcessor.setNodesDetails(Collections.singletonList(EMPTY_DETAILS)); } + @Test + public void testGetCurrentHostAddress() { + Assert.assertEquals(ClusterUtils.EMPTY_STRING, ClusterUtils.getCurrentNodeHostAddress()); + ClusterDetailsEventProcessor.setNodesDetails(Collections.singletonList( + ClusterDetailsEventProcessorTestHelper.newNodeDetails(null, HOST, false) + )); + Assert.assertEquals(HOST, ClusterUtils.getCurrentNodeHostAddress()); + } + + @Test + public void testGetAllPeerHostAddresses() { + // method should behave when fed an empty list of peers + Assert.assertEquals(Collections.emptyList(), ClusterUtils.getAllPeerHostAddresses()); + // method should not include the current node in the list of peers + ClusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( + ClusterDetailsEventProcessorTestHelper.newNodeDetails(null, HOST, false) + )); + Assert.assertEquals(Collections.emptyList(), ClusterUtils.getAllPeerHostAddresses()); + // method should return the appropriate peers when peers exist + ClusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( + ClusterDetailsEventProcessorTestHelper.newNodeDetails(null, HOST, false), + ClusterDetailsEventProcessorTestHelper.newNodeDetails(null, HOST2, false) + )); + Assert.assertEquals(Collections.singletonList(HOST2), ClusterUtils.getAllPeerHostAddresses()); + } + @Test public void testIsHostAddressInCluster() { + // Explicitly reset ClusterDetailsEventProcessor. Test fails on mac otherwise. + ClusterDetailsEventProcessor.setNodesDetails(Collections.singletonList(EMPTY_DETAILS)); // method should return false when there are no peers - Assert.assertFalse(ClusterUtils.isHostAddressInCluster(HOST, getInstancesFromHost(Collections.EMPTY_LIST))); + Assert.assertFalse(ClusterUtils.isHostAddressInCluster(HOST)); // method should properly recognize which hosts are peers and which aren't ClusterDetailsEventProcessor.setNodesDetails(Lists.newArrayList( ClusterDetailsEventProcessorTestHelper.newNodeDetails(null, HOST, false) )); - - - - List instances = getInstancesFromHost(Collections.singletonList(HOST)); - - Assert.assertTrue(ClusterUtils.isHostAddressInCluster(HOST, instances)); - Assert.assertFalse(ClusterUtils.isHostAddressInCluster(HOST2, instances)); + Assert.assertTrue(ClusterUtils.isHostAddressInCluster(HOST)); + Assert.assertFalse(ClusterUtils.isHostAddressInCluster(HOST2)); } } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java index f80be272a..3e91deb3d 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java @@ -18,7 +18,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.MasterPendingValue; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.MetricName; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.MetricsConfiguration; @@ -53,7 +52,7 @@ public void before() throws Exception { @Test public void testReaderMetricsProcessorFrequently() throws Exception { deleteAll(); - ReaderMetricsProcessor mp = new ReaderMetricsProcessor(rootLocation, true, new AppContext()); + ReaderMetricsProcessor mp = new ReaderMetricsProcessor(rootLocation, true); mp.processMetrics(rootLocation, 1566413975000L); mp.processMetrics(rootLocation, 1566413980000L); diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/HighHeapUsageClusterRcaTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/HighHeapUsageClusterRcaTest.java index 1da40e5d2..f365f8ea6 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/HighHeapUsageClusterRcaTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/HighHeapUsageClusterRcaTest.java @@ -15,17 +15,12 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.store.rca; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.GradleTaskForRca; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.RcaTestHelper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Resources.State; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.HighHeapUsageClusterRca; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; -import java.util.ArrayList; -import java.util.List; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -35,25 +30,19 @@ public class HighHeapUsageClusterRcaTest { @Test public void testOperate() { - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - ClusterDetailsEventProcessor.NodeDetails node1 = - new ClusterDetailsEventProcessor.NodeDetails(AllMetrics.NodeRole.DATA, "node1", "127.0.0.0", false); - ClusterDetailsEventProcessor.NodeDetails node2 = - new ClusterDetailsEventProcessor.NodeDetails(AllMetrics.NodeRole.DATA, "node2", "127.0.0.1", false); - - List nodes = new ArrayList<>(); - nodes.add(node1); - nodes.add(node2); - clusterDetailsEventProcessor.setNodesDetails(nodes); - - AppContext appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); - RcaTestHelper nodeRca = new RcaTestHelper(); - nodeRca.setAppContext(appContext); - HighHeapUsageClusterRca clusterRca = new HighHeapUsageClusterRca(1, nodeRca); - clusterRca.setAppContext(appContext); + + //setup cluster details + try { + ClusterDetailsEventProcessorTestHelper clusterDetailsEventProcessorTestHelper = new ClusterDetailsEventProcessorTestHelper(); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node1", "127.0.0.0", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node2", "127.0.0.1", false); + clusterDetailsEventProcessorTestHelper.generateClusterDetailsEvent(); + } catch (Exception e) { + Assert.assertTrue("got exception when generating cluster details event", false); + return; + } // send three young gen flowunits (healthy, unhealthy, unhealthy) to node1 // the cluterRca will generate three healthy flowunits diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/HotNodeClusterRcaTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/HotNodeClusterRcaTest.java index cda06e4ff..a75fe38e5 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/HotNodeClusterRcaTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/HotNodeClusterRcaTest.java @@ -18,9 +18,7 @@ import static java.time.Instant.ofEpochMilli; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.Resource; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.GradleTaskForRca; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Rca; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.RcaTestHelper; @@ -32,14 +30,11 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.HotNodeClusterRca; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; import java.sql.SQLException; import java.time.Clock; import java.time.Duration; import java.time.ZoneId; -import java.util.ArrayList; -import java.util.List; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -47,34 +42,21 @@ @Category(GradleTaskForRca.class) public class HotNodeClusterRcaTest { - private AppContext appContext; + @Before - public void setupCluster() { - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - ClusterDetailsEventProcessor.NodeDetails node1 = - new ClusterDetailsEventProcessor.NodeDetails(AllMetrics.NodeRole.DATA, "node1", "127.0.0.0", false); - ClusterDetailsEventProcessor.NodeDetails node2 = - new ClusterDetailsEventProcessor.NodeDetails(AllMetrics.NodeRole.DATA, "node2", "127.0.0.1", false); - ClusterDetailsEventProcessor.NodeDetails node3 = - new ClusterDetailsEventProcessor.NodeDetails(AllMetrics.NodeRole.DATA, "node3", "127.0.0.2", false); - - List nodes = new ArrayList<>(); - nodes.add(node1); - nodes.add(node2); - nodes.add(node3); - clusterDetailsEventProcessor.setNodesDetails(nodes); - - appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); + public void setupCluster() throws SQLException, ClassNotFoundException { + ClusterDetailsEventProcessorTestHelper clusterDetailsEventProcessorTestHelper = new ClusterDetailsEventProcessorTestHelper(); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node1", "127.0.0.0", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node2", "127.0.0.1", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node3", "127.0.0.2", false); + clusterDetailsEventProcessorTestHelper.generateClusterDetailsEvent(); } @Test public void testNodeCntThresholdAndTimestampExpiration() { RcaTestHelper nodeRca = new RcaTestHelper(); - nodeRca.setAppContext(appContext); HotNodeClusterRcaX clusterRca = new HotNodeClusterRcaX(1, nodeRca); - clusterRca.setAppContext(appContext); Clock constantClock = Clock.fixed(ofEpochMilli(0), ZoneId.systemDefault()); clusterRca.setClock(constantClock); @@ -96,9 +78,7 @@ public void testNodeCntThresholdAndTimestampExpiration() { public void testCaptureHotNode() { ResourceFlowUnit fu; RcaTestHelper nodeRca = new RcaTestHelper(); - nodeRca.setAppContext(appContext); HotNodeClusterRcaX clusterRca = new HotNodeClusterRcaX(1, nodeRca); - clusterRca.setAppContext(appContext); //medium = 5, below the 30% threshold nodeRca.mockFlowUnit(generateFlowUnit(ResourceUtil.OLD_GEN_HEAP_USAGE, 4, "node1")); @@ -130,9 +110,7 @@ public void testCaptureHotNode() { //check whether can filter out noise data if the resource usage is very small public void testFilterNoiseData() { RcaTestHelper nodeRca = new RcaTestHelper(); - nodeRca.setAppContext(appContext); HotNodeClusterRcaX clusterRca = new HotNodeClusterRcaX(1, nodeRca); - clusterRca.setAppContext(appContext); //medium = 0.2, 0.8 is above the 30% threshold. but since the data is too small, we will drop it nodeRca.mockFlowUnit(generateFlowUnit(ResourceUtil.OLD_GEN_HEAP_USAGE, 0.1, "node1")); diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/cluster/BaseClusterRcaTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/cluster/BaseClusterRcaTest.java index 2ef1a1b72..4d0da32c3 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/cluster/BaseClusterRcaTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/cluster/BaseClusterRcaTest.java @@ -17,7 +17,6 @@ import static java.time.Instant.ofEpochMilli; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.grpc.Resource; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.NodeRole; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.GradleTaskForRca; @@ -29,14 +28,11 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.cluster.BaseClusterRca; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; import java.sql.SQLException; import java.time.Clock; import java.time.Duration; import java.time.ZoneId; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.junit.Before; @@ -51,41 +47,23 @@ public class BaseClusterRcaTest { private Resource type1; private Resource type2; private Resource invalidType; - private AppContext appContext; @Before - public void init() { - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - ClusterDetailsEventProcessor.NodeDetails node1 = - new ClusterDetailsEventProcessor.NodeDetails(NodeRole.DATA, "node1", "127.0.0.0", false); - ClusterDetailsEventProcessor.NodeDetails node2 = - new ClusterDetailsEventProcessor.NodeDetails(NodeRole.DATA, "node2", "127.0.0.1", false); - ClusterDetailsEventProcessor.NodeDetails node3 = - new ClusterDetailsEventProcessor.NodeDetails(NodeRole.DATA, "node3", "127.0.0.2", false); - ClusterDetailsEventProcessor.NodeDetails master = - new ClusterDetailsEventProcessor.NodeDetails(NodeRole.ELECTED_MASTER, "master", "127.0.0.9", true); - - List nodes = new ArrayList<>(); - nodes.add(node1); - nodes.add(node2); - nodes.add(node3); - nodes.add(master); - clusterDetailsEventProcessor.setNodesDetails(nodes); - - appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); + public void setupCluster() throws SQLException, ClassNotFoundException { + ClusterDetailsEventProcessorTestHelper clusterDetailsEventProcessorTestHelper = new ClusterDetailsEventProcessorTestHelper(); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node1", "127.0.0.0", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node2", "127.0.0.1", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node3", "127.0.0.2", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("master", "127.0.0.9", NodeRole.ELECTED_MASTER, true); + clusterDetailsEventProcessorTestHelper.generateClusterDetailsEvent(); + } + @Before + public void init() { nodeRca = new RcaTestHelper<>("RCA1"); - nodeRca.setAppContext(appContext); - nodeRca2 = new RcaTestHelper<>("RCA2"); - nodeRca2.setAppContext(appContext); - invalidType = ResourceUtil.OLD_GEN_HEAP_USAGE; - clusterRca = new BaseClusterRca(1, nodeRca, nodeRca2); - clusterRca.setAppContext(appContext); - type1 = ResourceUtil.OLD_GEN_HEAP_USAGE; type2 = ResourceUtil.CPU_USAGE; } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/hotshard/HotShardClusterRcaTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/hotshard/HotShardClusterRcaTest.java index 473685cac..60f414fe3 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/hotshard/HotShardClusterRcaTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/hotshard/HotShardClusterRcaTest.java @@ -15,8 +15,6 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.store.rca.hotshard; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.GradleTaskForRca; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.RcaTestHelper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Resources; @@ -24,12 +22,13 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.GenericSummary; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.util.InstanceDetails; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.hotshard.HotShardClusterRca; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; + import java.util.Arrays; import java.util.Collections; import java.util.List; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -42,6 +41,8 @@ public class HotShardClusterRcaTest { private HotShardClusterRca hotShardClusterRca; + private ClusterDetailsEventProcessorTestHelper clusterDetailsEventProcessorTestHelper; + private enum index { index_1, index_2 @@ -64,23 +65,10 @@ public void setup() { try { hotShardRca = new RcaTestHelper(); hotShardClusterRca = new HotShardClusterRca(1, hotShardRca); - - InstanceDetails instanceDetails = - new InstanceDetails(AllMetrics.NodeRole.DATA, "node1", "127.0.0.1", false); - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - clusterDetailsEventProcessor.setNodesDetails(Collections.singletonList( - new ClusterDetailsEventProcessor.NodeDetails( - AllMetrics.NodeRole.DATA, - "node1", - "127.0.0.1", - false - ) - )); - AppContext appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); - - hotShardRca.setAppContext(appContext); - hotShardClusterRca.setAppContext(appContext); + clusterDetailsEventProcessorTestHelper = new ClusterDetailsEventProcessorTestHelper(); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node1", "127.0.0.0", false); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node2", "127.0.0.1", false); + clusterDetailsEventProcessorTestHelper.generateClusterDetailsEvent(); } catch (Exception e) { Assert.assertTrue("Exception when generating cluster details event", false); return; diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/hotshard/HotShardRcaTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/hotshard/HotShardRcaTest.java index a02da16ae..9e03cf84a 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/hotshard/HotShardRcaTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/hotshard/HotShardRcaTest.java @@ -4,8 +4,6 @@ import static com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.CommonDimension.SHARD_ID; import static java.time.Instant.ofEpochMilli; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metricsdb.MetricsDB; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.GradleTaskForRca; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.Metric; @@ -15,13 +13,15 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotShardSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.GenericSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.hotshard.HotShardRca; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; + import java.time.Clock; import java.time.Duration; import java.time.ZoneId; import java.util.Arrays; import java.util.Collections; import java.util.List; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -36,6 +36,8 @@ public class HotShardRcaTest { private MetricTestHelper ioTotSyscallRate; private List columnName; + private ClusterDetailsEventProcessorTestHelper clusterDetailsEventProcessorTestHelper; + private enum index { index_1, index_2 @@ -50,17 +52,14 @@ public void setup() { cpuUtilization, ioTotThroughput, ioTotSyscallRate); columnName = Arrays.asList(INDEX_NAME.toString(), SHARD_ID.toString(), MetricsDB.SUM); - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - clusterDetailsEventProcessor.setNodesDetails( - Collections.singletonList(new ClusterDetailsEventProcessor.NodeDetails( - AllMetrics.NodeRole.DATA, - "node1", - "127.0.0.1", - false)) - ); - AppContext appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); - hotShardRcaX.setAppContext(appContext); + try { + clusterDetailsEventProcessorTestHelper = new ClusterDetailsEventProcessorTestHelper(); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node1", "127.0.0.0", false); + clusterDetailsEventProcessorTestHelper.generateClusterDetailsEvent(); + } catch (Exception e) { + Assert.assertTrue("Exception when generating cluster details event", false); + return; + } } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/remediation/NodeConfigCollectorTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/remediation/NodeConfigCollectorTest.java index c8c520a9c..5bf2074b1 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/remediation/NodeConfigCollectorTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/remediation/NodeConfigCollectorTest.java @@ -2,7 +2,6 @@ import static com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.ThreadPoolDimension.THREAD_POOL_TYPE; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.ThreadPoolType; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metricsdb.MetricsDB; @@ -18,9 +17,11 @@ import java.util.Collections; import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; +@Ignore @Category(GradleTaskForRca.class) public class NodeConfigCollectorTest { @@ -29,16 +30,6 @@ public class NodeConfigCollectorTest { @Before public void init() { - threadPool_QueueCapacity = new ThreadPool_QueueCapacity(); - nodeConfigCollector = new NodeConfigCollector(1, threadPool_QueueCapacity); - - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - ClusterDetailsEventProcessor.NodeDetails node1 = - new ClusterDetailsEventProcessor.NodeDetails(AllMetrics.NodeRole.DATA, "node1", "127.0.0.0", false); - clusterDetailsEventProcessor.setNodesDetails(Collections.singletonList(node1)); - AppContext appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); - nodeConfigCollector.setAppContext(appContext); } /** diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/threadpool/QueueRejectionRcaTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/threadpool/QueueRejectionRcaTest.java index 2700b8b74..dda9c9202 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/threadpool/QueueRejectionRcaTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/store/rca/threadpool/QueueRejectionRcaTest.java @@ -18,8 +18,6 @@ import static com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.ThreadPoolDimension.THREAD_POOL_TYPE; import static java.time.Instant.ofEpochMilli; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.ThreadPoolType; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metricsdb.MetricsDB; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.GradleTaskForRca; @@ -29,12 +27,11 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.threadpool.QueueRejectionRca; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; import java.time.Clock; import java.time.Duration; import java.time.ZoneId; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.Assert; import org.junit.Before; @@ -65,20 +62,9 @@ public void init() throws Exception { threadPool_RejectedReqs = new MetricTestHelper(5); queueRejectionRca = new QueueRejectionRca(1, threadPool_RejectedReqs); columnName = Arrays.asList(THREAD_POOL_TYPE.toString(), MetricsDB.MAX); - - ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); - clusterDetailsEventProcessor.setNodesDetails(Collections.singletonList( - new ClusterDetailsEventProcessor.NodeDetails( - AllMetrics.NodeRole.DATA, - "node1", - "127.0.0.1", - false - ) - )); - AppContext appContext = new AppContext(); - appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); - - queueRejectionRca.setAppContext(appContext); + ClusterDetailsEventProcessorTestHelper clusterDetailsEventProcessorTestHelper = new ClusterDetailsEventProcessorTestHelper(); + clusterDetailsEventProcessorTestHelper.addNodeDetails("node1", "127.0.0.0", false); + clusterDetailsEventProcessorTestHelper.generateClusterDetailsEvent(); } @Test