From 053eedcfc768ec5a0b0975fda227bcc1c462486c Mon Sep 17 00:00:00 2001 From: Henning Andersen <33268011+henningandersen@users.noreply.github.com> Date: Tue, 15 Dec 2020 16:22:35 +0100 Subject: [PATCH] Autoscaling capacity should be in bytes (#66351) The autoscaling storage and memory capacities returned were inadvertently returned as capacities with units. This imposes a burden on the caller to be able to parse ES byte-size units. Fixed this to just return the bytes as numbers. --- .../autoscaling/get_autoscaling_capacity.yml | 16 ++++++++-------- .../capacity/AutoscalingCapacity.java | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_capacity.yml b/x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_capacity.yml index 0a3621fcc8ccd..982437fafed13 100644 --- a/x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_capacity.yml +++ b/x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_capacity.yml @@ -24,14 +24,14 @@ - do: autoscaling.get_autoscaling_capacity: {} - - match: { policies.my_autoscaling_policy.required_capacity.total.storage: 13370b } - - match: { policies.my_autoscaling_policy.required_capacity.total.memory: 73310b } - - match: { policies.my_autoscaling_policy.required_capacity.node.storage: 1337b } - - match: { policies.my_autoscaling_policy.required_capacity.node.memory: 7331b } - - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.total.storage: 13370b } - - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.total.memory: 73310b } - - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.node.storage: 1337b } - - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.node.memory: 7331b } + - match: { policies.my_autoscaling_policy.required_capacity.total.storage: 13370 } + - match: { policies.my_autoscaling_policy.required_capacity.total.memory: 73310 } + - match: { policies.my_autoscaling_policy.required_capacity.node.storage: 1337 } + - match: { policies.my_autoscaling_policy.required_capacity.node.memory: 7331 } + - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.total.storage: 13370 } + - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.total.memory: 73310 } + - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.node.storage: 1337 } + - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.node.memory: 7331 } - match: { policies.my_autoscaling_policy.deciders.fixed.reason_summary: "fixed storage [1.3kb] memory [7.1kb] nodes [10]" } - length: { policies.my_autoscaling_policy.current_nodes: 0 } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCapacity.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCapacity.java index a5123297bc917..f788c304024ca 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCapacity.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCapacity.java @@ -54,10 +54,10 @@ public ByteSizeValue memory() { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (storage != null) { - builder.field("storage", storage.getStringRep()); + builder.field("storage", storage.getBytes()); } if (memory != null) { - builder.field("memory", memory.getStringRep()); + builder.field("memory", memory.getBytes()); } builder.endObject(); return builder;