Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Changing metricsDB provider while executing an integTest #523

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/rcait.md → docs/gauntlet.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -34,28 +38,44 @@ public <T> Object constructObjectFromDBOnHost(HostTag hostTag, Class<T> 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<String, String> params,
HostTag hostByTag) {
@Nonnull final Map<String, String> 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<String, Result<Record>> 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down