Skip to content

Commit

Permalink
Introduce system index types including external (#69744)
Browse files Browse the repository at this point in the history
This commit introduces system index types that will be used to
differentiate behavior. Previously system indices were all treated the
same regardless of whether they belonged to Elasticsearch, a stack
component, or one of our solutions. Upon further discussion and
analysis this decision was not in the best interest of the various
teams and instead a new type of system index was needed. These system
indices will be referred to as external system indices. Within external
system indices, an option exists for these indices to be managed by
Elasticsearch or to be managed by the external product.

In order to represent this within Elasticsearch, each system index will
have a type and this type will be used to control behavior.

Closes #67383
Backport of #68919
  • Loading branch information
jaymode authored Mar 2, 2021
1 parent c67c223 commit 92c715d
Show file tree
Hide file tree
Showing 87 changed files with 1,006 additions and 710 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,45 @@ public static Iterable<Object[]> data() {
}

public void testCreateIndex() throws IOException {
Request request = new Request("PUT", "/_kibana/" + indexName);
Request request = request("PUT", "/" + indexName);
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
}

public void testAliases() throws IOException {
assumeFalse("In this test, .kibana is the alias name", ".kibana".equals(indexName));
Request request = new Request("PUT", "/_kibana/" + indexName);
Request request = request("PUT", "/" + indexName);
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

request = new Request("PUT", "/_kibana/" + indexName + "/_alias/.kibana");
request = request("PUT", "/" + indexName + "/_alias/.kibana");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

request = new Request("GET", "/_kibana/_aliases");
request = request("GET", "/_aliases");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(EntityUtils.toString(response.getEntity()), containsString(".kibana"));
}

public void testBulkToKibanaIndex() throws IOException {
Request request = new Request("POST", "/_kibana/_bulk");
Request request = request("POST", "/_bulk");
request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
}

public void testRefresh() throws IOException {
Request request = new Request("POST", "/_kibana/_bulk");
Request request = request("POST", "/_bulk");
request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

request = new Request("GET", "/_kibana/" + indexName + "/_refresh");
request = request("GET", "/" + indexName + "/_refresh");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

Request getRequest = new Request("GET", "/_kibana/" + indexName + "/_doc/1");
Request getRequest = request("GET", "/" + indexName + "/_doc/1");
Response getResponse = client().performRequest(getRequest);
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
String responseBody = EntityUtils.toString(getResponse.getEntity());
Expand All @@ -91,14 +91,14 @@ public void testRefresh() throws IOException {
}

public void testGetFromKibanaIndex() throws IOException {
Request request = new Request("POST", "/_kibana/_bulk");
Request request = request("POST", "/_bulk");
request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n");
request.addParameter("refresh", "true");

Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

Request getRequest = new Request("GET", "/_kibana/" + indexName + "/_doc/1");
Request getRequest = request("GET", "/" + indexName + "/_doc/1");
Response getResponse = client().performRequest(getRequest);
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
String responseBody = EntityUtils.toString(getResponse.getEntity());
Expand All @@ -107,7 +107,7 @@ public void testGetFromKibanaIndex() throws IOException {
}

public void testMultiGetFromKibanaIndex() throws IOException {
Request request = new Request("POST", "/_kibana/_bulk");
Request request = request("POST", "/_bulk");
request.setJsonEntity(
"{ \"index\" : { \"_index\" : \""
+ indexName
Expand All @@ -121,7 +121,7 @@ public void testMultiGetFromKibanaIndex() throws IOException {
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

Request getRequest = new Request("GET", "/_kibana/_mget");
Request getRequest = request("GET", "/_mget");
getRequest.setJsonEntity(
"{ \"docs\" : [ { \"_index\" : \""
+ indexName
Expand All @@ -140,7 +140,7 @@ public void testMultiGetFromKibanaIndex() throws IOException {
}

public void testSearchFromKibanaIndex() throws IOException {
Request request = new Request("POST", "/_kibana/_bulk");
Request request = request("POST", "/_bulk");
request.setJsonEntity(
"{ \"index\" : { \"_index\" : \""
+ indexName
Expand All @@ -154,7 +154,7 @@ public void testSearchFromKibanaIndex() throws IOException {
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

Request searchRequest = new Request("GET", "/_kibana/" + indexName + "/_search");
Request searchRequest = request("GET", "/" + indexName + "/_search");
searchRequest.setJsonEntity("{ \"query\" : { \"match_all\" : {} } }\n");
Response getResponse = client().performRequest(searchRequest);
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
Expand All @@ -166,7 +166,7 @@ public void testSearchFromKibanaIndex() throws IOException {
}

public void testDeleteFromKibanaIndex() throws IOException {
Request request = new Request("POST", "/_kibana/_bulk");
Request request = request("POST", "/_bulk");
request.setJsonEntity(
"{ \"index\" : { \"_index\" : \""
+ indexName
Expand All @@ -180,13 +180,13 @@ public void testDeleteFromKibanaIndex() throws IOException {
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

Request deleteRequest = new Request("DELETE", "/_kibana/" + indexName + "/_doc/1");
Request deleteRequest = request("DELETE", "/" + indexName + "/_doc/1");
Response deleteResponse = client().performRequest(deleteRequest);
assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200));
}

public void testDeleteByQueryFromKibanaIndex() throws IOException {
Request request = new Request("POST", "/_kibana/_bulk");
Request request = request("POST", "/_bulk");
request.setJsonEntity(
"{ \"index\" : { \"_index\" : \""
+ indexName
Expand All @@ -200,62 +200,62 @@ public void testDeleteByQueryFromKibanaIndex() throws IOException {
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

Request dbqRequest = new Request("POST", "/_kibana/" + indexName + "/_delete_by_query");
Request dbqRequest = request("POST", "/" + indexName + "/_delete_by_query");
dbqRequest.setJsonEntity("{ \"query\" : { \"match_all\" : {} } }\n");
Response dbqResponse = client().performRequest(dbqRequest);
assertThat(dbqResponse.getStatusLine().getStatusCode(), is(200));
}

public void testUpdateIndexSettings() throws IOException {
Request request = new Request("PUT", "/_kibana/" + indexName);
Request request = request("PUT", "/" + indexName);
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

request = new Request("PUT", "/_kibana/" + indexName + "/_settings");
request = request("PUT", "/" + indexName + "/_settings");
request.setJsonEntity("{ \"index.blocks.read_only\" : false }");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
}

public void testGetIndex() throws IOException {
Request request = new Request("PUT", "/_kibana/" + indexName);
Request request = request("PUT", "/" + indexName);
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

request = new Request("GET", "/_kibana/" + indexName);
request = request("GET", "/" + indexName);
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(EntityUtils.toString(response.getEntity()), containsString(indexName));
}

public void testIndexingAndUpdatingDocs() throws IOException {
Request request = new Request("PUT", "/_kibana/" + indexName + "/_doc/1");
Request request = request("PUT", "/" + indexName + "/_doc/1");
request.setJsonEntity("{ \"foo\" : \"bar\" }");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(201));

request = new Request("PUT", "/_kibana/" + indexName + "/_create/2");
request = request("PUT", "/" + indexName + "/_create/2");
request.setJsonEntity("{ \"foo\" : \"bar\" }");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(201));

request = new Request("POST", "/_kibana/" + indexName + "/_doc");
request = request("POST", "/" + indexName + "/_doc");
request.setJsonEntity("{ \"foo\" : \"bar\" }");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(201));

request = new Request("GET", "/_kibana/" + indexName + "/_refresh");
request = request("GET", "/" + indexName + "/_refresh");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

request = new Request("POST", "/_kibana/" + indexName + "/_update/1");
request = request("POST", "/" + indexName + "/_update/1");
request.setJsonEntity("{ \"doc\" : { \"foo\" : \"baz\" } }");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
}

public void testScrollingDocs() throws IOException {
Request request = new Request("POST", "/_kibana/_bulk");
Request request = request("POST", "/_bulk");
request.setJsonEntity(
"{ \"index\" : { \"_index\" : \""
+ indexName
Expand All @@ -271,7 +271,7 @@ public void testScrollingDocs() throws IOException {
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));

Request searchRequest = new Request("GET", "/_kibana/" + indexName + "/_search");
Request searchRequest = request("GET", "/" + indexName + "/_search");
searchRequest.setJsonEntity("{ \"size\" : 1,\n\"query\" : { \"match_all\" : {} } }\n");
searchRequest.addParameter("scroll", "1m");
response = client().performRequest(searchRequest);
Expand All @@ -280,7 +280,7 @@ public void testScrollingDocs() throws IOException {
assertNotNull(map.get("_scroll_id"));
String scrollId = (String) map.get("_scroll_id");

Request scrollRequest = new Request("POST", "/_kibana/_search/scroll");
Request scrollRequest = request("POST", "/_search/scroll");
scrollRequest.addParameter("scroll_id", scrollId);
scrollRequest.addParameter("scroll", "1m");
response = client().performRequest(scrollRequest);
Expand All @@ -289,9 +289,15 @@ public void testScrollingDocs() throws IOException {
assertNotNull(map.get("_scroll_id"));
scrollId = (String) map.get("_scroll_id");

Request clearScrollRequest = new Request("DELETE", "/_kibana/_search/scroll");
Request clearScrollRequest = request("DELETE", "/_search/scroll");
clearScrollRequest.addParameter("scroll_id", scrollId);
response = client().performRequest(clearScrollRequest);
assertThat(response.getStatusLine().getStatusCode(), is(200));
}

private Request request(String method, String endpoint) {
Request request = new Request(method, endpoint);
request.setOptions(request.getOptions().toBuilder().addHeader("X-elastic-product-origin", "kibana").build());
return request;
}
}
Loading

0 comments on commit 92c715d

Please sign in to comment.