Skip to content

Commit be1bb0e

Browse files
authored
Remove types from Monitoring plugin "backend" code (#37745)
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.
1 parent ab11503 commit be1bb0e

File tree

12 files changed

+14
-22
lines changed

12 files changed

+14
-22
lines changed

x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExportBulk.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ private byte[] toBulkBytes(final MonitoringDoc doc) throws IOException {
143143
builder.startObject("index");
144144
{
145145
builder.field("_index", index);
146-
builder.field("_type", "doc");
147146
if (id != null) {
148147
builder.field("_id", id);
149148
}
@@ -163,7 +162,10 @@ private byte[] toBulkBytes(final MonitoringDoc doc) throws IOException {
163162
// Adds final bulk separator
164163
out.write(xContent.streamSeparator());
165164

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

168170
return BytesReference.toBytes(out.bytes());
169171
} catch (Exception e) {

x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalBulk.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void doAdd(Collection<MonitoringDoc> docs) throws ExportException {
6666
try {
6767
final String index = MonitoringTemplateUtils.indexName(formatter, doc.getSystem(), doc.getTimestamp());
6868

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

8484
if (logger.isTraceEnabled()) {
85-
logger.trace("local exporter [{}] - added index request [index={}, type={}, id={}, pipeline={}]",
86-
name, request.index(), request.type(), request.id(), request.getPipeline());
85+
logger.trace("local exporter [{}] - added index request [index={}, id={}, pipeline={}, monitoring data type={}]",
86+
name, request.index(), request.id(), request.getPipeline(), doc.getType());
8787
}
8888
} catch (Exception e) {
8989
if (exception == null) {

x-pack/plugin/monitoring/src/main/resources/monitoring/watches/elasticsearch_cluster_status.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
"add_to_alerts_index": {
153153
"index": {
154154
"index": ".monitoring-alerts-6",
155-
"doc_type": "doc",
156155
"doc_id": "${monitoring.watch.unique_id}"
157156
}
158157
},

x-pack/plugin/monitoring/src/main/resources/monitoring/watches/elasticsearch_nodes.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@
157157
"actions": {
158158
"add_to_alerts_index": {
159159
"index": {
160-
"index": ".monitoring-alerts-6",
161-
"doc_type": "doc"
160+
"index": ".monitoring-alerts-6"
162161
}
163162
},
164163
"send_email_to_admin": {

x-pack/plugin/monitoring/src/main/resources/monitoring/watches/elasticsearch_version_mismatch.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
"add_to_alerts_index": {
149149
"index": {
150150
"index": ".monitoring-alerts-6",
151-
"doc_type": "doc",
152151
"doc_id": "${monitoring.watch.unique_id}"
153152
}
154153
},

x-pack/plugin/monitoring/src/main/resources/monitoring/watches/kibana_version_mismatch.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@
168168
"add_to_alerts_index": {
169169
"index": {
170170
"index": ".monitoring-alerts-6",
171-
"doc_type": "doc",
172171
"doc_id": "${monitoring.watch.unique_id}"
173172
}
174173
},

x-pack/plugin/monitoring/src/main/resources/monitoring/watches/logstash_version_mismatch.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@
168168
"add_to_alerts_index": {
169169
"index": {
170170
"index": ".monitoring-alerts-6",
171-
"doc_type": "doc",
172171
"doc_id": "${monitoring.watch.unique_id}"
173172
}
174173
},

x-pack/plugin/monitoring/src/main/resources/monitoring/watches/xpack_license_expiration.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
"add_to_alerts_index": {
142142
"index": {
143143
"index": ".monitoring-alerts-6",
144-
"doc_type": "doc",
145144
"doc_id": "${monitoring.watch.unique_id}"
146145
}
147146
},

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkRequestTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ public void testAddRequestContentWithUnrecognizedIndexName() throws IOException
232232
assertThat(e.getMessage(), containsString("unrecognized index name [" + indexName + "]"));
233233
//This test's JSON contains outdated references to types
234234
assertWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE);
235-
236235
}
237236

238237
public void testSerialization() throws IOException {

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ private void checkMonitoringDocs() {
275275
assertTrue("document is missing cluster_uuid field", Strings.hasText((String) source.get("cluster_uuid")));
276276
assertTrue("document is missing timestamp field", Strings.hasText(timestamp));
277277
assertTrue("document is missing type field", Strings.hasText(type));
278-
assertEquals("document _type is 'doc'", "doc", hit.getType());
279278

280279
@SuppressWarnings("unchecked")
281280
Map<String, Object> docSource = (Map<String, Object>) source.get("doc");

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterResourceIntegTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private static BytesReference generateTemplateSource(final String name, final In
8181
.field("index.number_of_replicas", 0)
8282
.endObject()
8383
.startObject("mappings")
84+
// Still need use type, RestPutIndexTemplateAction#prepareRequestSource has logic that adds type if missing
8485
.startObject("doc")
8586
.startObject("_meta")
8687
.field("test", true)

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/integration/MonitoringIT.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.license.License;
2828
import org.elasticsearch.plugins.Plugin;
2929
import org.elasticsearch.rest.RestStatus;
30-
import org.elasticsearch.rest.action.document.RestBulkAction;
3130
import org.elasticsearch.search.SearchHit;
3231
import org.elasticsearch.search.SearchHits;
3332
import org.elasticsearch.search.collapse.CollapseBuilder;
@@ -105,11 +104,11 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
105104
}
106105

107106
private String createBulkEntity() {
108-
return "{\"index\":{\"_type\":\"test\"}}\n" +
107+
return "{\"index\":{}}\n" +
109108
"{\"foo\":{\"bar\":0}}\n" +
110-
"{\"index\":{\"_type\":\"test\"}}\n" +
109+
"{\"index\":{}}\n" +
111110
"{\"foo\":{\"bar\":1}}\n" +
112-
"{\"index\":{\"_type\":\"test\"}}\n" +
111+
"{\"index\":{}}\n" +
113112
"{\"foo\":{\"bar\":2}}\n" +
114113
"\n";
115114
}
@@ -128,7 +127,7 @@ public void testMonitoringBulk() throws Exception {
128127

129128
final MonitoringBulkResponse bulkResponse =
130129
new MonitoringBulkRequestBuilder(client())
131-
.add(system, null, new BytesArray(createBulkEntity().getBytes("UTF-8")), XContentType.JSON,
130+
.add(system, "monitoring_data_type", new BytesArray(createBulkEntity().getBytes("UTF-8")), XContentType.JSON,
132131
System.currentTimeMillis(), interval.millis())
133132
.get();
134133

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

181180
for (final SearchHit hit : hits.getHits()) {
182-
assertMonitoringDoc(toMap(hit), system, "test", interval);
181+
assertMonitoringDoc(toMap(hit), system, "monitoring_data_type", interval);
183182
}
184183
});
185-
assertWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE);
186184
}
187185

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

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

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

0 commit comments

Comments
 (0)