Skip to content

Commit

Permalink
Test all Kibana indices, respond to PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
williamrandolph committed Apr 15, 2024
1 parent 6755242 commit c6f503d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.SystemIndexThreadPoolTestCase;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;

import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
Expand All @@ -31,23 +33,32 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
}

public void testKibanaThreadPool() {
List<String> kibanaSystemIndices = Stream.of(
KibanaPlugin.KIBANA_INDEX_DESCRIPTOR.getIndexPattern(),
KibanaPlugin.REPORTING_INDEX_DESCRIPTOR.getIndexPattern(),
KibanaPlugin.APM_AGENT_CONFIG_INDEX_DESCRIPTOR.getIndexPattern(),
KibanaPlugin.APM_CUSTOM_LINK_INDEX_DESCRIPTOR.getIndexPattern()
).map(s -> s.replace("*", randomAlphaOfLength(8).toLowerCase(Locale.ROOT))).toList();

runWithBlockedThreadPools(() -> {
// index documents
String idToDelete = ESIntegTestCase.client().prepareIndex(".kibana").setSource(Map.of("foo", "delete me!")).get().getId();
String idToUpdate = ESIntegTestCase.client().prepareIndex(".kibana").setSource(Map.of("foo", "update me!")).get().getId();

// bulk index, delete, and update
Client bulkClient = ESIntegTestCase.client();
BulkResponse response = bulkClient.prepareBulk(".kibana")
.add(bulkClient.prepareIndex(".kibana").setSource(Map.of("foo", "search me!")))
.add(bulkClient.prepareDelete(".kibana", idToDelete))
.add(bulkClient.prepareUpdate().setId(idToUpdate).setDoc(Map.of("foo", "I'm updated!")))
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();
assertNoFailures(response);

// match-all search
assertHitCount(ESIntegTestCase.client().prepareSearch(".kibana").setQuery(QueryBuilders.matchAllQuery()), 2);
for (String index : kibanaSystemIndices) {
// index documents
String idToDelete = client().prepareIndex(index).setSource(Map.of("foo", "delete me!")).get().getId();
String idToUpdate = client().prepareIndex(index).setSource(Map.of("foo", "update me!")).get().getId();

// bulk index, delete, and update
Client bulkClient = client();
BulkResponse response = bulkClient.prepareBulk(index)
.add(bulkClient.prepareIndex(index).setSource(Map.of("foo", "search me!")))
.add(bulkClient.prepareDelete(index, idToDelete))
.add(bulkClient.prepareUpdate().setId(idToUpdate).setDoc(Map.of("foo", "I'm updated!")))
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();
assertNoFailures(response);

// match-all search
assertHitCount(client().prepareSearch(index).setQuery(QueryBuilders.matchAllQuery()), 2);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ private void assertThreadPoolsBlocked() {
SearchPhaseExecutionException.class,
() -> client().prepareSearch(USER_INDEX)
.setQuery(QueryBuilders.matchAllQuery())
// Don't let the test framework set maxConcurrentShardRequests randomly, because the
// request times out if this is set to 1
.setMaxConcurrentShardRequests(SearchRequest.DEFAULT_MAX_CONCURRENT_SHARD_REQUESTS)
// Request times out if max concurrent shard requests is set to 1
.setMaxConcurrentShardRequests(usually() ? SearchRequest.DEFAULT_MAX_CONCURRENT_SHARD_REQUESTS : randomIntBetween(2, 10))
.get()
);
assertThat(e3.getMessage(), containsString("all shards failed"));
Expand Down

0 comments on commit c6f503d

Please sign in to comment.