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

TSDB: CCR tests #78034

Merged
merged 1 commit into from
Oct 1, 2021
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 @@ -15,6 +15,8 @@
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.repositories.fs.FsRepository;
import org.elasticsearch.rest.RestStatus;

Expand All @@ -23,6 +25,8 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static io.github.nik9000.mapmatcher.MapMatcher.assertMap;
import static io.github.nik9000.mapmatcher.MapMatcher.matchesMap;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyOrNullString;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -235,6 +239,140 @@ public void testFollowSearchableSnapshotsFails() throws Exception {
}
}

public void testFollowTsdbIndex() throws Exception {
final int numDocs = 128;
final String leaderIndexName = "tsdb_leader";
long basetime = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parseMillis("2021-01-01T00:00:00Z");
if ("leader".equals(targetCluster)) {
logger.info("Running against leader cluster");
createIndex(
leaderIndexName,
Settings.builder().put(IndexSettings.MODE.getKey(), "time_series").build(),
"\"properties\": {\"@timestamp\": {\"type\": \"date\"}, \"dim\": {\"type\": \"keyword\", \"time_series_dimension\": true}}"
);
for (int i = 0; i < numDocs; i++) {
logger.info("Indexing doc [{}]", i);
index(
client(),
leaderIndexName,
Integer.toString(i),
"@timestamp",
basetime + TimeUnit.SECONDS.toMillis(i * 10),
"dim",
"foobar"
);
}
refresh(leaderIndexName);
verifyDocuments(client(), leaderIndexName, numDocs);
} else if ("follow".equals(targetCluster)) {
logger.info("Running against follow cluster");
final String followIndexName = "tsdb_follower";
final boolean overrideNumberOfReplicas = randomBoolean();
if (overrideNumberOfReplicas) {
followIndex(
client(),
"leader_cluster",
leaderIndexName,
followIndexName,
Settings.builder().put("index.number_of_replicas", 0).build()
);
} else {
followIndex(leaderIndexName, followIndexName);
}
assertBusy(() -> {
verifyDocuments(client(), followIndexName, numDocs);
if (overrideNumberOfReplicas) {
assertMap(
getIndexSettingsAsMap(followIndexName),
matchesMap().extraOk().entry("index.mode", "time_series").entry("index.number_of_replicas", "0")
);
} else {
assertMap(
getIndexSettingsAsMap(followIndexName),
matchesMap().extraOk().entry("index.mode", "time_series").entry("index.number_of_replicas", "1")
);
}
});
// unfollow and then follow and then index a few docs in leader index:
pauseFollow(followIndexName);
resumeFollow(followIndexName);
try (RestClient leaderClient = buildLeaderClient()) {
int id = numDocs;
index(
leaderClient,
leaderIndexName,
Integer.toString(id),
"@timestamp",
basetime + TimeUnit.SECONDS.toMillis(id * 10),
"dim",
"foobar"
);
index(
leaderClient,
leaderIndexName,
Integer.toString(id + 1),
"@timestamp",
basetime + TimeUnit.SECONDS.toMillis(id * 10 + 10),
"dim",
"foobar"
);
index(
leaderClient,
leaderIndexName,
Integer.toString(id + 2),
"@timestamp",
basetime + TimeUnit.SECONDS.toMillis(id * 10 + 20),
"dim",
"foobar"
);
}
assertBusy(() -> verifyDocuments(client(), followIndexName, numDocs + 3));
assertBusy(() -> verifyCcrMonitoring(leaderIndexName, followIndexName), 30, TimeUnit.SECONDS);

pauseFollow(followIndexName);
closeIndex(followIndexName);
assertOK(client().performRequest(new Request("POST", "/" + followIndexName + "/_ccr/unfollow")));
Exception e = expectThrows(ResponseException.class, () -> resumeFollow(followIndexName));
assertThat(e.getMessage(), containsString("follow index [" + followIndexName + "] does not have ccr metadata"));
}
}

public void testFollowTsdbIndexCanNotOverrideMode() throws Exception {
if (false == "follow".equals(targetCluster)) {
return;
}
logger.info("Running against follow cluster");
Exception e = expectThrows(ResponseException.class, () -> followIndex(
client(),
"leader_cluster",
"tsdb_leader",
"tsdb_follower_bad",
Settings.builder().put("index.mode", "standard").build()
));
assertThat(
e.getMessage(),
containsString("can not put follower index that could override leader settings {\\\"index.mode\\\":\\\"standard\\\"}")
);
}

public void testFollowStandardIndexCanNotOverrideMode() throws Exception {
if (false == "follow".equals(targetCluster)) {
return;
}
logger.info("Running against follow cluster");
Exception e = expectThrows(ResponseException.class, () -> followIndex(
client(),
"leader_cluster",
"test_index1",
"tsdb_follower_bad",
Settings.builder().put("index.mode", "time_series").build()
));
assertThat(
e.getMessage(),
containsString("can not put follower index that could override leader settings {\\\"index.mode\\\":\\\"time_series\\\"}")
);
}

@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
Expand Down