|
@@ -33,18 +33,19 @@ public final class MonitoringTemplateUtils {
|
|
|
|
|
|
/**
|
|
|
* Current version of templates used in their name to differentiate from breaking changes (separate from product version).
|
|
|
+ * Version 7 has the same structure as version 6, but uses the `_doc` type.
|
|
|
*/
|
|
|
- public static final String TEMPLATE_VERSION = "6";
|
|
|
+ public static final String TEMPLATE_VERSION = "7";
|
|
|
/**
|
|
|
* The previous version of templates, which we still support via the REST /_monitoring/bulk endpoint because
|
|
|
* nothing changed for those documents.
|
|
|
*/
|
|
|
- public static final String OLD_TEMPLATE_VERSION = "2";
|
|
|
+ public static final String OLD_TEMPLATE_VERSION = "6";
|
|
|
|
|
|
/**
|
|
|
* IDs of templates that can be used with {@linkplain #loadTemplate(String) loadTemplate}.
|
|
|
*/
|
|
|
- public static final String[] TEMPLATE_IDS = { "alerts", "es", "kibana", "logstash", "beats" };
|
|
|
+ public static final String[] TEMPLATE_IDS = { "alerts-7", "es", "kibana", "logstash", "beats" };
|
|
|
|
|
|
/**
|
|
|
* IDs of templates that can be used with {@linkplain #createEmptyTemplate(String) createEmptyTemplate} that are not managed by a
|
|
@@ -54,7 +55,7 @@ public final class MonitoringTemplateUtils {
|
|
|
* instances will attempt to create a named template based on the templates that they expect (e.g., ".monitoring-es-2") and not the
|
|
|
* ones that we are creating.
|
|
|
*/
|
|
|
- public static final String[] OLD_TEMPLATE_IDS = { "data", "es", "kibana", "logstash", "alerts" };
|
|
|
+ public static final String[] OLD_TEMPLATE_IDS = { "data", "es", "kibana", "logstash" }; //excluding alerts since 6.x watches use it
|
|
|
|
|
|
/**
|
|
|
* IDs of pipelines that can be used with
|
|
@@ -99,7 +100,7 @@ public final class MonitoringTemplateUtils {
|
|
|
* @see #OLD_TEMPLATE_VERSION
|
|
|
*/
|
|
|
public static String createEmptyTemplate(final String id) {
|
|
|
- // e.g., { "index_patterns": [ ".monitoring-data-2*" ], "version": 6000002 }
|
|
|
+ // e.g., { "index_patterns": [ ".monitoring-data-6*" ], "version": 6000002 }
|
|
|
return "{\"index_patterns\":[\".monitoring-" + id + "-" + OLD_TEMPLATE_VERSION + "*\"],\"version\":" + LAST_UPDATED_VERSION + "}";
|
|
|
}
|
|
|
|
|
@@ -120,7 +121,7 @@ public final class MonitoringTemplateUtils {
|
|
|
* The expectation is that you will call either {@link Strings#toString(XContentBuilder)} or
|
|
|
* {@link BytesReference#bytes(XContentBuilder)}}.
|
|
|
*
|
|
|
- * @param id The API version (e.g., "2") to use
|
|
|
+ * @param id The API version (e.g., "6") to use
|
|
|
* @param type The type of data you want to format for the request
|
|
|
* @return Never {@code null}. Always an ended-object.
|
|
|
* @throws IllegalArgumentException if {@code apiVersion} is unrecognized
|
|
@@ -131,7 +132,7 @@ public final class MonitoringTemplateUtils {
|
|
|
case TEMPLATE_VERSION:
|
|
|
return emptyPipeline(type);
|
|
|
case OLD_TEMPLATE_VERSION:
|
|
|
- return pipelineForApiVersion2(type);
|
|
|
+ return pipelineForApiVersion6(type);
|
|
|
}
|
|
|
|
|
|
throw new IllegalArgumentException("unrecognized pipeline API version [" + id + "]");
|
|
@@ -139,13 +140,6 @@ public final class MonitoringTemplateUtils {
|
|
|
|
|
|
/**
|
|
|
* Create a pipeline to upgrade documents from {@link MonitoringTemplateUtils#OLD_TEMPLATE_VERSION}
|
|
|
- * <pre><code>
|
|
|
- * {
|
|
|
- * "description" : "This pipeline upgrades documents ...",
|
|
|
- * "version": 6000001,
|
|
|
- * "processors": [ ]
|
|
|
- * }
|
|
|
- * </code></pre>
|
|
|
* The expectation is that you will call either {@link Strings#toString(XContentBuilder)} or
|
|
|
* {@link BytesReference#bytes(XContentBuilder)}}.
|
|
|
*
|
|
@@ -153,81 +147,39 @@ public final class MonitoringTemplateUtils {
|
|
|
* @return Never {@code null}. Always an ended-object.
|
|
|
* @see #LAST_UPDATED_VERSION
|
|
|
*/
|
|
|
- static XContentBuilder pipelineForApiVersion2(final XContentType type) {
|
|
|
+ static XContentBuilder pipelineForApiVersion6(final XContentType type) {
|
|
|
try {
|
|
|
- // For now: We prepend the API version to the string so that it's easy to parse in the future; if we ever add metadata
|
|
|
- // to pipelines, then it would better serve this use case
|
|
|
return XContentBuilder.builder(type.xContent()).startObject()
|
|
|
.field("description", "This pipeline upgrades documents from the older version of the Monitoring API to " +
|
|
|
- "the newer version (" + TEMPLATE_VERSION + ") by fixing breaking " +
|
|
|
- "changes in those older documents before they are indexed from the older version (" +
|
|
|
- OLD_TEMPLATE_VERSION + ").")
|
|
|
+ "the newer version (" + TEMPLATE_VERSION + ") by fixing breaking " +
|
|
|
+ "changes in those older documents before they are indexed from the older version (" +
|
|
|
+ OLD_TEMPLATE_VERSION + ").")
|
|
|
.field("version", LAST_UPDATED_VERSION)
|
|
|
.startArray("processors")
|
|
|
.startObject()
|
|
|
- // Drop the .monitoring-data-2 index and effectively drop unnecessary data (duplicate or simply unused)
|
|
|
+ // remove the type
|
|
|
.startObject("script")
|
|
|
- .field("source",
|
|
|
- "boolean legacyIndex = ctx._index == '.monitoring-data-2';" +
|
|
|
- "if (legacyIndex || ctx._index.startsWith('.monitoring-es-2')) {" +
|
|
|
- "if (ctx._type == 'cluster_info') {" +
|
|
|
- "ctx._type = 'cluster_stats';" +
|
|
|
- "ctx._id = null;" +
|
|
|
- "} else if (legacyIndex || ctx._type == 'cluster_stats' || ctx._type == 'node') {" +
|
|
|
- "String index = ctx._index;" +
|
|
|
- "Object clusterUuid = ctx.cluster_uuid;" +
|
|
|
- "Object timestamp = ctx.timestamp;" +
|
|
|
-
|
|
|
- "ctx.clear();" +
|
|
|
-
|
|
|
- "ctx._id = 'xpack_monitoring_2_drop_bucket';" +
|
|
|
- "ctx._index = index;" +
|
|
|
- "ctx._type = 'legacy_data';" +
|
|
|
- "ctx.timestamp = timestamp;" +
|
|
|
- "ctx.cluster_uuid = clusterUuid;" +
|
|
|
- "}" +
|
|
|
- "if (legacyIndex) {" +
|
|
|
- "ctx._index = '<.monitoring-es-" + TEMPLATE_VERSION + "-{now}>';" +
|
|
|
- "}" +
|
|
|
- "}")
|
|
|
- .endObject()
|
|
|
- .endObject()
|
|
|
- .startObject()
|
|
|
- .startObject("rename")
|
|
|
- .field("field", "_type")
|
|
|
- .field("target_field", "type")
|
|
|
- .endObject()
|
|
|
- .endObject()
|
|
|
- .startObject()
|
|
|
- .startObject("set")
|
|
|
- .field("field", "_type")
|
|
|
- .field("value", "doc")
|
|
|
+ .field("source","ctx._type = null" )
|
|
|
.endObject()
|
|
|
.endObject()
|
|
|
.startObject()
|
|
|
+ // ensure the data lands in the correct index
|
|
|
.startObject("gsub")
|
|
|
.field("field", "_index")
|
|
|
- .field("pattern", "(.monitoring-\\w+-)2(-.+)")
|
|
|
+ .field("pattern", "(.monitoring-\\w+-)6(-.+)")
|
|
|
.field("replacement", "$1" + TEMPLATE_VERSION + "$2")
|
|
|
.endObject()
|
|
|
.endObject()
|
|
|
.endArray()
|
|
|
- .endObject();
|
|
|
+ .endObject();
|
|
|
} catch (final IOException e) {
|
|
|
throw new RuntimeException("Failed to create pipeline to upgrade from older version [" + OLD_TEMPLATE_VERSION +
|
|
|
- "] to the newer version [" + TEMPLATE_VERSION + "].", e);
|
|
|
+ "] to the newer version [" + TEMPLATE_VERSION + "].", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Create an empty pipeline.
|
|
|
- * <pre><code>
|
|
|
- * {
|
|
|
- * "description" : "This is a placeholder pipeline ...",
|
|
|
- * "version": 6000001,
|
|
|
- * "processors": [ ]
|
|
|
- * }
|
|
|
- * </code></pre>
|
|
|
* The expectation is that you will call either {@link Strings#toString(XContentBuilder)} or
|
|
|
* {@link BytesReference#bytes(XContentBuilder)}}.
|
|
|
*
|