From a94c27d3ded487f82d9e66dc01922ae0232e9e27 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Tue, 13 Sep 2016 20:48:37 -0400 Subject: [PATCH] [Monitoring] Future-proof Monitoring Bulk API with "interval" param This adds an "interval" placeholder parameter that is required to the Monitoring Bulk API, and adds it to the Kibana side of the plumbing. Having this will allow us to add it to all incoming documents and start to report against it with the Insights, as well as to detect the _lack_ of incoming documents. By adding it now, we can avoid having a non-BWC API change for Kibana in 5.1. We'll just pickup new data in our documents. Original commit: elastic/x-pack-elasticsearch@5ba8aafe03c69f0fd6873b435066e5b111cd968b --- .../rest/action/RestMonitoringBulkAction.java | 15 ++++--- .../api/xpack.monitoring.bulk.json | 4 ++ .../test/monitoring/bulk/10_basic.yaml | 39 ++++++++++++++++++- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java index 17784ec8639..9ff72fb2852 100644 --- a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java +++ b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.monitoring.rest.action; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -30,6 +29,7 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler { public static final String MONITORING_ID = "system_id"; public static final String MONITORING_VERSION = "system_api_version"; + public static final String INTERVAL = "interval"; @Inject public RestMonitoringBulkAction(Settings settings, RestController controller) { @@ -45,12 +45,17 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler { String defaultType = request.param("type"); String id = request.param(MONITORING_ID); - if (Strings.hasLength(id) == false) { - throw new IllegalArgumentException("no monitoring id for monitoring bulk request"); + if (Strings.isEmpty(id)) { + throw new IllegalArgumentException("no [" + MONITORING_ID + "] for monitoring bulk request"); } String version = request.param(MONITORING_VERSION); - if (Strings.hasLength(version) == false) { - throw new IllegalArgumentException("no monitoring version for monitoring bulk request"); + if (Strings.isEmpty(version)) { + throw new IllegalArgumentException("no [" + MONITORING_VERSION + "] for monitoring bulk request"); + } + // we don't currently use the interval, but in future releases we can incorporate it without breaking BWC since it was here from + // the beginning + if (Strings.isEmpty(request.param(INTERVAL))) { + throw new IllegalArgumentException("no [" + INTERVAL + "] for monitoring bulk request"); } if (!RestActions.hasBodyContent(request)) { diff --git a/elasticsearch/x-pack/monitoring/src/test/resources/rest-api-spec/api/xpack.monitoring.bulk.json b/elasticsearch/x-pack/monitoring/src/test/resources/rest-api-spec/api/xpack.monitoring.bulk.json index 42d7ae43d55..71f1b1fc13b 100644 --- a/elasticsearch/x-pack/monitoring/src/test/resources/rest-api-spec/api/xpack.monitoring.bulk.json +++ b/elasticsearch/x-pack/monitoring/src/test/resources/rest-api-spec/api/xpack.monitoring.bulk.json @@ -19,6 +19,10 @@ "system_api_version" : { "type" : "string", "description" : "API Version of the monitored system" + }, + "interval": { + "type" : "string", + "description" : "Collection interval (e.g., '10s' or '10000ms') of the payload" } } }, diff --git a/elasticsearch/x-pack/monitoring/src/test/resources/rest-api-spec/test/monitoring/bulk/10_basic.yaml b/elasticsearch/x-pack/monitoring/src/test/resources/rest-api-spec/test/monitoring/bulk/10_basic.yaml index 6dad7415668..5432cc5e3a4 100644 --- a/elasticsearch/x-pack/monitoring/src/test/resources/rest-api-spec/test/monitoring/bulk/10_basic.yaml +++ b/elasticsearch/x-pack/monitoring/src/test/resources/rest-api-spec/test/monitoring/bulk/10_basic.yaml @@ -17,8 +17,9 @@ setup: - do: xpack.monitoring.bulk: - system_id: "kibana" + system_id: "kibana" system_api_version: "2" + interval: "10s" body: - index: _type: test_type @@ -51,8 +52,9 @@ setup: - do: xpack.monitoring.bulk: - system_id: "kibana" + system_id: "kibana" system_api_version: "2" + interval: "10000ms" type: "default_type" body: - '{"index": {}}' @@ -89,3 +91,36 @@ setup: type: kibana - match: { hits.total: 1 } + + # Missing a system_id causes it to fail + - do: + catch: request + xpack.monitoring.bulk: + system_api_version: "2" + interval: "10s" + type: "default_type" + body: + - '{"index": {}}' + - '{"field_1": "value_1"}' + + # Missing a system_api_version causes it to fail + - do: + catch: request + xpack.monitoring.bulk: + system_id: "kibana" + interval: "10s" + type: "default_type" + body: + - '{"index": {}}' + - '{"field_1": "value_1"}' + + # Missing an interval causes it to fail + - do: + catch: request + xpack.monitoring.bulk: + system_id: "kibana" + system_api_version: "2" + type: "default_type" + body: + - '{"index": {}}' + - '{"field_1": "value_1"}'