Skip to content

Commit

Permalink
Remove types from Monitoring plugin "backend" code (#37745)
Browse files Browse the repository at this point in the history
This PR removes the use of document types from the monitoring exporters and template + watches setup code.

It does not remove the notion of types from the monitoring bulk API endpoint "front end" code as that code will eventually just go away in 8.0 and be replaced with Beats as collectors/shippers directly to the monitoring cluster.
  • Loading branch information
ycombinator authored Feb 4, 2019
1 parent ab11503 commit be1bb0e
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ private byte[] toBulkBytes(final MonitoringDoc doc) throws IOException {
builder.startObject("index");
{
builder.field("_index", index);
builder.field("_type", "doc");
if (id != null) {
builder.field("_id", id);
}
Expand All @@ -163,7 +162,10 @@ private byte[] toBulkBytes(final MonitoringDoc doc) throws IOException {
// Adds final bulk separator
out.write(xContent.streamSeparator());

logger.trace("added index request [index={}, type={}, id={}]", index, doc.getType(), id);
logger.trace(
"http exporter [{}] - added index request [index={}, id={}, monitoring data type={}]",
name, index, id, doc.getType()
);

return BytesReference.toBytes(out.bytes());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void doAdd(Collection<MonitoringDoc> docs) throws ExportException {
try {
final String index = MonitoringTemplateUtils.indexName(formatter, doc.getSystem(), doc.getTimestamp());

final IndexRequest request = new IndexRequest(index, "doc");
final IndexRequest request = new IndexRequest(index);
if (Strings.hasText(doc.getId())) {
request.id(doc.getId());
}
Expand All @@ -82,8 +82,8 @@ public void doAdd(Collection<MonitoringDoc> docs) throws ExportException {
requestBuilder.add(request);

if (logger.isTraceEnabled()) {
logger.trace("local exporter [{}] - added index request [index={}, type={}, id={}, pipeline={}]",
name, request.index(), request.type(), request.id(), request.getPipeline());
logger.trace("local exporter [{}] - added index request [index={}, id={}, pipeline={}, monitoring data type={}]",
name, request.index(), request.id(), request.getPipeline(), doc.getType());
}
} catch (Exception e) {
if (exception == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
"add_to_alerts_index": {
"index": {
"index": ".monitoring-alerts-6",
"doc_type": "doc",
"doc_id": "${monitoring.watch.unique_id}"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@
"actions": {
"add_to_alerts_index": {
"index": {
"index": ".monitoring-alerts-6",
"doc_type": "doc"
"index": ".monitoring-alerts-6"
}
},
"send_email_to_admin": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
"add_to_alerts_index": {
"index": {
"index": ".monitoring-alerts-6",
"doc_type": "doc",
"doc_id": "${monitoring.watch.unique_id}"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
"add_to_alerts_index": {
"index": {
"index": ".monitoring-alerts-6",
"doc_type": "doc",
"doc_id": "${monitoring.watch.unique_id}"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
"add_to_alerts_index": {
"index": {
"index": ".monitoring-alerts-6",
"doc_type": "doc",
"doc_id": "${monitoring.watch.unique_id}"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
"add_to_alerts_index": {
"index": {
"index": ".monitoring-alerts-6",
"doc_type": "doc",
"doc_id": "${monitoring.watch.unique_id}"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ public void testAddRequestContentWithUnrecognizedIndexName() throws IOException
assertThat(e.getMessage(), containsString("unrecognized index name [" + indexName + "]"));
//This test's JSON contains outdated references to types
assertWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE);

}

public void testSerialization() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ private void checkMonitoringDocs() {
assertTrue("document is missing cluster_uuid field", Strings.hasText((String) source.get("cluster_uuid")));
assertTrue("document is missing timestamp field", Strings.hasText(timestamp));
assertTrue("document is missing type field", Strings.hasText(type));
assertEquals("document _type is 'doc'", "doc", hit.getType());

@SuppressWarnings("unchecked")
Map<String, Object> docSource = (Map<String, Object>) source.get("doc");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private static BytesReference generateTemplateSource(final String name, final In
.field("index.number_of_replicas", 0)
.endObject()
.startObject("mappings")
// Still need use type, RestPutIndexTemplateAction#prepareRequestSource has logic that adds type if missing
.startObject("doc")
.startObject("_meta")
.field("test", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.elasticsearch.license.License;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.action.document.RestBulkAction;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.collapse.CollapseBuilder;
Expand Down Expand Up @@ -105,11 +104,11 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
}

private String createBulkEntity() {
return "{\"index\":{\"_type\":\"test\"}}\n" +
return "{\"index\":{}}\n" +
"{\"foo\":{\"bar\":0}}\n" +
"{\"index\":{\"_type\":\"test\"}}\n" +
"{\"index\":{}}\n" +
"{\"foo\":{\"bar\":1}}\n" +
"{\"index\":{\"_type\":\"test\"}}\n" +
"{\"index\":{}}\n" +
"{\"foo\":{\"bar\":2}}\n" +
"\n";
}
Expand All @@ -128,7 +127,7 @@ public void testMonitoringBulk() throws Exception {

final MonitoringBulkResponse bulkResponse =
new MonitoringBulkRequestBuilder(client())
.add(system, null, new BytesArray(createBulkEntity().getBytes("UTF-8")), XContentType.JSON,
.add(system, "monitoring_data_type", new BytesArray(createBulkEntity().getBytes("UTF-8")), XContentType.JSON,
System.currentTimeMillis(), interval.millis())
.get();

Expand Down Expand Up @@ -179,10 +178,9 @@ public void testMonitoringBulk() throws Exception {
equalTo(1L));

for (final SearchHit hit : hits.getHits()) {
assertMonitoringDoc(toMap(hit), system, "test", interval);
assertMonitoringDoc(toMap(hit), system, "monitoring_data_type", interval);
}
});
assertWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE);
}

/**
Expand Down Expand Up @@ -265,7 +263,6 @@ private void assertMonitoringDoc(final Map<String, Object> document,

final String index = (String) document.get("_index");
assertThat(index, containsString(".monitoring-" + expectedSystem.getSystem() + "-" + TEMPLATE_VERSION + "-"));
assertThat(document.get("_type"), equalTo("doc"));
assertThat((String) document.get("_id"), not(isEmptyOrNullString()));

final Map<String, Object> source = (Map<String, Object>) document.get("_source");
Expand Down

0 comments on commit be1bb0e

Please sign in to comment.