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"}'