diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 586c02d8f..925ddefaf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -64,7 +64,7 @@ e.g. ### Adding your own tests - You can add a unit tests using the junit framework - There is also a mechanism to add integration tests for the RCA framework. For details, please - see [here](docs/rcait.md). + see [here](docs/gauntlet.md). Before submitting the PR, we request that you also run ```shell script diff --git a/docs/rcait.md b/docs/gauntlet.md similarity index 99% rename from docs/rcait.md rename to docs/gauntlet.md index 0e5713803..9a5724eec 100644 --- a/docs/rcait.md +++ b/docs/gauntlet.md @@ -1,4 +1,4 @@ -# Rca Integration test framework +# Gauntlet: Rca Integration test framework ## Scope To be able to test scenarios where multiple RCA Schedulers are running on different hosts of a diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/integTests/framework/api/TestApi.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/integTests/framework/api/TestApi.java index 6bb03e813..8b879a04b 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/integTests/framework/api/TestApi.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/integTests/framework/api/TestApi.java @@ -1,23 +1,27 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.integTests.framework.api; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.integTests.framework.Cluster; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.integTests.framework.annotations.AMetric; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.integTests.framework.configs.HostTag; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import java.util.Map; import java.util.Objects; import javax.annotation.Nonnull; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.jooq.Record; import org.jooq.Result; /** - * This is API class whose object is injected into each of the test methods in case test class - * declares a @{code setTestApi(final TestApi api)}. + * This is API class whose object is injected into each of the test methods in case test class declares a @{code setTestApi(final TestApi + * api)}. */ public class TestApi { + private static final Logger LOG = LogManager.getLogger(TestApi.class); + /** - * An instance of the cluster object to get access to the nodes to query various data to see - * that the tests have the desired results. + * An instance of the cluster object to get access to the nodes to query various data to see that the tests have the desired results. */ private final Cluster cluster; @@ -34,28 +38,44 @@ public Object constructObjectFromDBOnHost(HostTag hostTag, Class clz) thr } /** - * This let's you make a REST request to the REST endpoint of a particular host identified by - * the host tag. + * This let's you make a REST request to the REST endpoint of a particular host identified by the host tag. * * @param params the key value map that is passes as the request parameter. * @param hostByTag The host whose rest endpoint we will hit. * @return The response serialized as a String. */ public JsonElement getRestResponse(@Nonnull final String queryUrl, - @Nonnull final Map params, - HostTag hostByTag) { + @Nonnull final Map params, + HostTag hostByTag) { Objects.requireNonNull(params); JsonElement json = JsonParser.parseString(cluster.getRcaRestResponse(queryUrl, params, hostByTag)); return json; } /** - * This can be used to get all the records from all the tables in a host. This can be used for validation of - * what gets persisted in the rca.sqlite tables. + * This can be used to get all the records from all the tables in a host. This can be used for validation of what gets persisted in the + * rca.sqlite tables. + * * @param hostTag The host whose rca.sqlite will be queried. * @return A list of all the data stored in all the tables in the particular host. */ public Map> getRecordsForAllTablesOnHost(HostTag hostTag) { return cluster.getRecordsForAllTablesOnHost(hostTag); } + + /** + * This API let's a gauntlet test writer swap out the metricsDB for a new one. + * + * @param clz The class whose AMetric@ should be used to replace it + * @throws Exception Throws Exception + */ + public void updateMetrics(Class clz) throws Exception { + if (clz.isAnnotationPresent(AMetric.Metrics.class) || clz.isAnnotationPresent(AMetric.class)) { + cluster.updateMetricsDB(clz.getAnnotationsByType(AMetric.class)); + + // The scheduler needs to be restarted to pick this change up. + cluster.stopRcaScheduler(); + cluster.startRcaScheduler(); + } + } } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/integTests/tests/poc/RcaItPocSingleNode.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/integTests/tests/poc/RcaItPocSingleNode.java index 32cf092bb..d48c1c13a 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/integTests/tests/poc/RcaItPocSingleNode.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/integTests/tests/poc/RcaItPocSingleNode.java @@ -23,7 +23,6 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.integTests.framework.configs.ClusterType; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.integTests.framework.configs.HostTag; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.integTests.framework.runners.RcaItNotEncryptedRunner; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.integTests.framework.runners.RcaItRunnerBase; import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.integTests.tests.poc.validator.PocValidator; import java.util.Arrays; import java.util.Collections;