This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Fix failures in ResourceHeatMapGraphTest #321
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ | |
import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.net.GRPCConnectionManager; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.RcaTestHelper; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.exceptions.MalformedConfig; | ||
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.metrics.CPU_Utilization; | ||
|
@@ -67,15 +66,11 @@ | |
import com.google.gson.JsonParser; | ||
import com.sun.net.httpserver.HttpServer; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.ProtocolException; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.sql.SQLException; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
|
@@ -88,7 +83,6 @@ | |
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
public class ResourceHeatMapGraphTest { | ||
|
@@ -109,25 +103,9 @@ public class ResourceHeatMapGraphTest { | |
private static AtomicReference<ExecutorService> networkThreadPoolReference; | ||
|
||
@BeforeClass | ||
public static void init() { | ||
try { | ||
persistable = PersistenceFactory.create(rcaConf); | ||
} catch (MalformedConfig malformedConfig) { | ||
malformedConfig.printStackTrace(); | ||
Assert.fail(); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
try { | ||
reader = new SQLiteReader(sqliteFile.toString()); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
public static void init() throws Exception { | ||
persistable = PersistenceFactory.create(rcaConf); | ||
reader = new SQLiteReader(sqliteFile.toString()); | ||
|
||
AllMetrics.NodeRole nodeRole2 = AllMetrics.NodeRole.ELECTED_MASTER; | ||
AppContext appContext = RcaTestHelper.setMyIp("192.168.0.2", nodeRole2); | ||
|
@@ -151,6 +129,12 @@ public static void shutdown() { | |
clientServers.getHttpServer().stop(0); | ||
clientServers.getNetServer().stop(); | ||
clientServers.getNetClient().stop(); | ||
|
||
try { | ||
Thread.sleep(1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this sleep needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't strictly necessary, I'm mimicking similar logic from RcaControllerTest which does this sleep after stopping its clients and servers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Maybe it’s a good idea to abstract the shutdown logic with sleep into its own method so that we don’t have to carry the sleep change wherever we use shutdown? |
||
} catch (InterruptedException ie) { | ||
ie.printStackTrace(); | ||
} | ||
} | ||
|
||
private static class AnalysisGraphX extends ElasticSearchAnalysisGraph { | ||
|
@@ -195,7 +179,7 @@ private List<ConnectedComponent> createAndExecuteRcaGraph(AppContext appContext) | |
return connectedComponents; | ||
} | ||
|
||
private String makeRestRequest(final String[] params) { | ||
private String makeRestRequest(final String[] params) throws Exception { | ||
// The params are key/value pairs and therefore there should be even numbers of them. | ||
Assert.assertEquals(0, params.length % 2); | ||
StringBuilder queryString = new StringBuilder(); | ||
|
@@ -209,63 +193,31 @@ private String makeRestRequest(final String[] params) { | |
uri.append("?").append(queryString); | ||
|
||
|
||
URL url = null; | ||
try { | ||
url = new URL(uri.toString()); | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
URL url = new URL(uri.toString()); | ||
|
||
String response = ""; | ||
HttpURLConnection connection = null; | ||
|
||
try { | ||
connection = (HttpURLConnection) url.openConnection(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
|
||
try { | ||
connection.setRequestMethod("GET"); | ||
} catch (ProtocolException e) { | ||
e.printStackTrace(); | ||
connection.disconnect(); | ||
Assert.fail(); | ||
} | ||
|
||
try { | ||
int status = connection.getResponseCode(); | ||
if (status != 200) { | ||
List<String> ret = | ||
new BufferedReader(new InputStreamReader(connection.getErrorStream())).lines().collect(Collectors.toList()); | ||
throw new IllegalStateException(ret.toString()); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
connection.disconnect(); | ||
Assert.fail(); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.setRequestMethod("GET"); | ||
int status = connection.getResponseCode(); | ||
if (status != 200) { | ||
List<String> ret = | ||
new BufferedReader(new InputStreamReader(connection.getErrorStream())).lines().collect(Collectors.toList()); | ||
throw new IllegalStateException(ret.toString()); | ||
} | ||
|
||
try (BufferedReader in = new BufferedReader( | ||
new InputStreamReader(connection.getInputStream()))) { | ||
String inputLine; | ||
StringBuffer content = new StringBuffer(); | ||
while ((inputLine = in.readLine()) != null) { | ||
content.append(inputLine); | ||
} | ||
response = content.toString(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
connection.disconnect(); | ||
Assert.fail(); | ||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
String inputLine; | ||
StringBuffer content = new StringBuffer(); | ||
while ((inputLine = in.readLine()) != null) { | ||
content.append(inputLine); | ||
} | ||
response = content.toString(); | ||
in.close(); | ||
return response; | ||
} | ||
|
||
@Test | ||
public void clusterTemperatureProfile() { | ||
public void clusterTemperatureProfile() throws Exception { | ||
AppContext appContext = RcaTestHelper.setMyIp("192.168.0.2", AllMetrics.NodeRole.ELECTED_MASTER); | ||
|
||
List<ConnectedComponent> connectedComponents = createAndExecuteRcaGraph(appContext); | ||
|
@@ -303,7 +255,7 @@ public void clusterTemperatureProfile() { | |
} | ||
|
||
@Test | ||
public void fullNodeTemperatureProfile() { | ||
public void fullNodeTemperatureProfile() throws Exception { | ||
AppContext appContext = RcaTestHelper.setMyIp("192.168.0.3", AllMetrics.NodeRole.DATA); | ||
createAndExecuteRcaGraph(appContext); | ||
verifyFullNodeTemperatureProfile(makeRestRequest( | ||
|
@@ -1056,7 +1008,7 @@ public void construct() { | |
} | ||
|
||
@Test | ||
public void testHotShardClusterApiResponse() { | ||
public void testHotShardClusterApiResponse() throws Exception { | ||
AnalysisGraph analysisGraph = new AnalysisGraphHotShard(); | ||
List<ConnectedComponent> connectedComponents = | ||
RcaUtil.getAnalysisGraphComponents(analysisGraph); | ||
|
@@ -1120,45 +1072,36 @@ public void testHotShardClusterApiResponse() { | |
rcaSchedulerTaskMaster.run(); | ||
|
||
URL url = null; | ||
try { | ||
url = new URL("http://localhost:9600" + Util.RCA_QUERY_URL + "?name=" + HotShardClusterRca.RCA_TABLE_NAME); | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
url = new URL("http://localhost:9600" + Util.RCA_QUERY_URL + "?name=" | ||
+ HotShardClusterRca.RCA_TABLE_NAME); | ||
|
||
try { | ||
HttpURLConnection con = (HttpURLConnection) url.openConnection(); | ||
con.setRequestMethod("GET"); | ||
|
||
int status = con.getResponseCode(); | ||
System.out.println("Response status: " + status); | ||
try (BufferedReader in = new BufferedReader( | ||
new InputStreamReader(con.getInputStream()))) { | ||
String inputLine; | ||
StringBuffer content = new StringBuffer(); | ||
while ((inputLine = in.readLine()) != null) { | ||
content.append(inputLine); | ||
} | ||
final String hotShardClusterRcaName = HotShardClusterRca.RCA_TABLE_NAME; | ||
final String hotClusterSummaryName = HotClusterSummary.HOT_CLUSTER_SUMMARY_TABLE; | ||
HttpURLConnection con = (HttpURLConnection) url.openConnection(); | ||
con.setRequestMethod("GET"); | ||
|
||
JsonParser parser = new JsonParser(); | ||
JsonElement jsonElement = parser.parse(content.toString()); | ||
JsonObject hotShardClusterRca = | ||
jsonElement.getAsJsonObject().get(hotShardClusterRcaName).getAsJsonArray().get(0).getAsJsonObject(); | ||
int status = con.getResponseCode(); | ||
System.out.println("Response status: " + status); | ||
try (BufferedReader in = new BufferedReader( | ||
new InputStreamReader(con.getInputStream()))) { | ||
String inputLine; | ||
StringBuffer content = new StringBuffer(); | ||
while ((inputLine = in.readLine()) != null) { | ||
content.append(inputLine); | ||
} | ||
final String hotShardClusterRcaName = HotShardClusterRca.RCA_TABLE_NAME; | ||
final String hotClusterSummaryName = HotClusterSummary.HOT_CLUSTER_SUMMARY_TABLE; | ||
|
||
JsonParser parser = new JsonParser(); | ||
JsonElement jsonElement = parser.parse(content.toString()); | ||
JsonObject hotShardClusterRca = | ||
jsonElement.getAsJsonObject().get(hotShardClusterRcaName).getAsJsonArray().get(0).getAsJsonObject(); | ||
|
||
Assert.assertEquals(hotShardClusterRcaName, hotShardClusterRca.get("rca_name").getAsString()); | ||
Assert.assertEquals("unhealthy", hotShardClusterRca.get("state").getAsString()); | ||
Assert.assertEquals(hotShardClusterRcaName, hotShardClusterRca.get("rca_name").getAsString()); | ||
Assert.assertEquals("unhealthy", hotShardClusterRca.get("state").getAsString()); | ||
|
||
JsonObject hotClusterSummary = | ||
hotShardClusterRca.get(hotClusterSummaryName).getAsJsonArray().get(0).getAsJsonObject(); | ||
Assert.assertEquals(1, hotClusterSummary.get("number_of_unhealthy_nodes").getAsInt()); | ||
} | ||
con.disconnect(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
JsonObject hotClusterSummary = | ||
hotShardClusterRca.get(hotClusterSummaryName).getAsJsonArray().get(0).getAsJsonObject(); | ||
Assert.assertEquals(1, hotClusterSummary.get("number_of_unhealthy_nodes").getAsInt()); | ||
} | ||
con.disconnect(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we trying to restore
oldBindHost
to some default value here? If so, should it be done insetUp()
?Same for others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah wait, this is for across tests. Got it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's take
oldBindHost
as an example. IfoldBindHost
is null then after this test class ran, we would previously keep the value that PerformanceAnalyzerWebServer changedWEBSERVICE_BIND_HOST_NAME
to. This could lead to other tests failing.The reason this runs as part of a tearDown is to make sure that everything is reset after the test class finishes running.