Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA: Check rollup job creation safety #31036

Merged
merged 1 commit into from
Jun 4, 2018
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
import org.junit.Before;
import org.elasticsearch.Version;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.ResponseException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assume.assumeThat;
Expand All @@ -42,6 +45,11 @@
* cluster is the on the "zip" distribution.
*/
public class XPackIT extends AbstractRollingTestCase {
private static final Version UPGRADE_FROM_VERSION =
Version.fromString(System.getProperty("tests.upgrade_from_version"));
private static final boolean UPGRADE_FROM_VERSION_HAS_XPACK =
UPGRADE_FROM_VERSION.onOrAfter(Version.V_6_3_0);

@Before
public void skipIfNotZip() {
assumeThat("test is only supported if the distribution contains xpack",
Expand All @@ -68,11 +76,8 @@ public void skipIfNotZip() {
* system.
*/
public void testIndexTemplatesCreated() throws Exception {
Version upgradeFromVersion =
Version.fromString(System.getProperty("tests.upgrade_from_version"));
boolean upgradeFromVersionHasXPack = upgradeFromVersion.onOrAfter(Version.V_6_3_0);
assumeFalse("this test doesn't really prove anything if the starting version has xpack and it is *much* more complex to maintain",
upgradeFromVersionHasXPack);
UPGRADE_FROM_VERSION_HAS_XPACK);
assumeFalse("since we're upgrading from a version without x-pack it won't have any templates",
CLUSTER_TYPE == ClusterType.OLD);

Expand Down Expand Up @@ -193,6 +198,68 @@ public void testTrialLicense() throws IOException {
client().performRequest(createJob);
}

/**
* Attempts to create a rollup job and validates that the right
* thing happens. If all nodes don't have xpack then it should
* fail, either with a "I don't support this API" message or a
* "the following nodes aren't ready". If all the nodes has xpack
* then it should just work. This would catch issues where rollup
* would pollute the cluster state with its job that the non-xpack
* nodes couldn't understand.
*/
public void testCreateRollup() throws IOException {
// Rollup validates its input on job creation so lets make an index for it
Request indexInputDoc = new Request("POST", "/rollup_test_input_1/doc/");
indexInputDoc.setJsonEntity(
"{\n"
+ " \"timestamp\":\"2018-01-01T00:00:00\",\n"
+ " \"node\": \"node1\",\n"
+ " \"voltage\": 12.6\n"
+ "}");
client().performRequest(indexInputDoc);

// Actually attempt the rollup and catch the errors if there should be any
Request createJob = new Request("PUT", "/_xpack/rollup/job/" + System.nanoTime());
createJob.setJsonEntity(
"{\n"
+ " \"index_pattern\" : \"rollup_test_input_*\",\n"
+ " \"rollup_index\": \"rollup_test_output\",\n"
+ " \"cron\": \"*/30 * * * * ?\",\n"
+ " \"page_size\": 1000,\n"
+ " \"groups\": {\n"
+ " \"date_histogram\": {\n"
+ " \"field\": \"timestamp\",\n"
+ " \"interval\": \"1h\",\n"
+ " \"delay\": \"7d\"\n"
+ " },\n"
+ " \"terms\": {\n"
+ " \"fields\": [\"node.keyword\"]\n"
+ " }\n"
+ " },\n"
+ " \"metrics\": [\n"
+ " {\"field\": \"voltage\", \"metrics\": [\"avg\"]}\n"
+ " ]\n"
+ "}\n");
if (UPGRADE_FROM_VERSION_HAS_XPACK || CLUSTER_TYPE == ClusterType.UPGRADED) {
client().performRequest(createJob);
} else {
ResponseException e = expectThrows(ResponseException.class, () ->
client().performRequest(createJob));
assertThat(e.getMessage(), anyOf(
// Request landed on a node without xpack
containsString("No handler found for uri"),
// Request landed on a node *with* xpack but the master doesn't have it
containsString("No handler for action"),
// Request landed on a node *with* xpack and the master has it but other nodes do not
containsString("The following nodes are not ready yet for enabling x-pack custom metadata")));
}

// Whether or not there are errors we should be able to modify the cluster state
Request createIndex = new Request("PUT", "/test_index" + System.nanoTime());
client().performRequest(createIndex);
client().performRequest(new Request("DELETE", createIndex.getEndpoint()));
}

/**
* Has the master been upgraded to the new version?
*/
Expand Down