Skip to content

Commit

Permalink
Autoscaling capacity API and structure (#63905)
Browse files Browse the repository at this point in the history
Renamed decision API to capacity. Responses now prefer objects/maps over
arrays. Removed mention of tier, using policies as the outer map and
total for the policy-wide total capacity.
  • Loading branch information
henningandersen committed Oct 21, 2020
1 parent 81b3349 commit d573fde
Show file tree
Hide file tree
Showing 34 changed files with 328 additions and 337 deletions.
4 changes: 2 additions & 2 deletions docs/reference/autoscaling/apis/autoscaling-apis.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ You can use the following APIs to perform autoscaling operations.
[[autoscaling-api-top-level]]
=== Top-Level

* <<autoscaling-get-autoscaling-decision,Get autoscaling decision>>
* <<autoscaling-get-autoscaling-capacity,Get autoscaling capacity>>
* <<autoscaling-delete-autoscaling-policy,Delete autoscaling policy>>
* <<autoscaling-get-autoscaling-policy,Get autoscaling policy>>
* <<autoscaling-put-autoscaling-policy,Put autoscaling policy>>

// top-level
include::get-autoscaling-decision.asciidoc[]
include::get-autoscaling-capacity.asciidoc[]
include::delete-autoscaling-policy.asciidoc[]
include::get-autoscaling-policy.asciidoc[]
include::put-autoscaling-policy.asciidoc[]
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
[role="xpack"]
[testenv="platinum"]
[[autoscaling-get-autoscaling-decision]]
=== Get autoscaling decision API
[[autoscaling-get-autoscaling-capacity]]
=== Get autoscaling capacity API
++++
<titleabbrev>Get autoscaling decision</titleabbrev>
<titleabbrev>Get autoscaling capacity</titleabbrev>
++++

Get autoscaling decision.
Get autoscaling capacity.

[[autoscaling-get-autoscaling-decision-request]]
[[autoscaling-get-autoscaling-capacity-request]]
==== {api-request-title}

[source,console]
--------------------------------------------------
GET /_autoscaling/decision/
GET /_autoscaling/capacity/
--------------------------------------------------
// TEST

[[autoscaling-get-autoscaling-decision-prereqs]]
[[autoscaling-get-autoscaling-capacity-prereqs]]
==== {api-prereq-title}

* If the {es} {security-features} are enabled, you must have
`manage_autoscaling` cluster privileges. For more information, see
<<security-privileges>>.

[[autoscaling-get-autoscaling-decision-desc]]
[[autoscaling-get-autoscaling-capacity-desc]]
==== {api-description-title}

This API gets the current autoscaling decision based on the configured
autoscaling policy. This API will return whether or not autoscaling is
needed.
This API gets the current autoscaling capacity based on the configured
autoscaling policy. This API will return information to size the cluster
appropriately to the current workload.

[[autoscaling-get-autoscaling-decision-examples]]
[[autoscaling-get-autoscaling-capacity-examples]]
==== {api-examples-title}

This example retrieves the current autoscaling decision.
This example retrieves the current autoscaling capacity.

[source,console]
--------------------------------------------------
GET /_autoscaling/decision
GET /_autoscaling/capacity
--------------------------------------------------
// TEST

Expand All @@ -47,6 +47,6 @@ The API returns the following result:
[source,console-result]
--------------------------------------------------
{
decisions: []
policies: {}
}
--------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This API puts an autoscaling policy with the provided name.
==== {api-examples-title}

This example puts an autoscaling policy named `my_autoscaling_policy` using the
always autoscaling decider.
fixed autoscaling decider.

[source,console]
--------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/redirects.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1225,3 +1225,9 @@ See <<size-your-shards>>.
=== elasticsearch-croneval parameters

See <<elasticsearch-croneval-parameters>>.

[role="exclude",id="autoscaling-get-autoscaling-decision"]
=== Autoscaling decision API

The autoscaling decision API has been renamed to capacity,
see <<autoscaling-get-autoscaling-capacity>>.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
"Test get empty autoscaling capacity":
- do:
autoscaling.get_autoscaling_capacity: {}

- match: { "policies": {} }

---
"Test get fixed autoscaling capacity":
- do:
autoscaling.put_autoscaling_policy:
name: my_autoscaling_policy
body:
policy:
deciders:
fixed:
storage: 1337b
memory: 7331b
nodes: 10

- match: { "acknowledged": true }

- 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.deciders.fixed.reason_summary: "fixed storage [1.3kb] memory [7.1kb] nodes [10]" }

# test cleanup
- do:
autoscaling.delete_autoscaling_policy:
name: my_autoscaling_policy

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xpack.autoscaling.action.DeleteAutoscalingPolicyAction;
import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingDecisionAction;
import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingCapacityAction;
import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingPolicyAction;
import org.elasticsearch.xpack.autoscaling.action.PutAutoscalingPolicyAction;
import org.elasticsearch.xpack.autoscaling.action.TransportDeleteAutoscalingPolicyAction;
import org.elasticsearch.xpack.autoscaling.action.TransportGetAutoscalingDecisionAction;
import org.elasticsearch.xpack.autoscaling.action.TransportGetAutoscalingCapacityAction;
import org.elasticsearch.xpack.autoscaling.action.TransportGetAutoscalingPolicyAction;
import org.elasticsearch.xpack.autoscaling.action.TransportPutAutoscalingPolicyAction;
import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecision;
import org.elasticsearch.xpack.autoscaling.decision.FixedAutoscalingDeciderConfiguration;
import org.elasticsearch.xpack.autoscaling.decision.FixedAutoscalingDeciderService;
import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDeciderConfiguration;
import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDeciderService;
import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecisionService;
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResult;
import org.elasticsearch.xpack.autoscaling.capacity.FixedAutoscalingDeciderConfiguration;
import org.elasticsearch.xpack.autoscaling.capacity.FixedAutoscalingDeciderService;
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderConfiguration;
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderService;
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingCalculateCapacityService;
import org.elasticsearch.xpack.autoscaling.rest.RestDeleteAutoscalingPolicyHandler;
import org.elasticsearch.xpack.autoscaling.rest.RestGetAutoscalingDecisionHandler;
import org.elasticsearch.xpack.autoscaling.rest.RestGetAutoscalingCapacityHandler;
import org.elasticsearch.xpack.autoscaling.rest.RestGetAutoscalingPolicyHandler;
import org.elasticsearch.xpack.autoscaling.rest.RestPutAutoscalingPolicyHandler;
import org.elasticsearch.xpack.core.XPackPlugin;
Expand Down Expand Up @@ -136,14 +136,14 @@ public Collection<Object> createComponents(
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<RepositoriesService> repositoriesServiceSupplier
) {
return List.of(new AutoscalingDecisionService.Holder(this));
return List.of(new AutoscalingCalculateCapacityService.Holder(this));
}

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
if (enabled) {
return List.of(
new ActionHandler<>(GetAutoscalingDecisionAction.INSTANCE, TransportGetAutoscalingDecisionAction.class),
new ActionHandler<>(GetAutoscalingCapacityAction.INSTANCE, TransportGetAutoscalingCapacityAction.class),
new ActionHandler<>(DeleteAutoscalingPolicyAction.INSTANCE, TransportDeleteAutoscalingPolicyAction.class),
new ActionHandler<>(GetAutoscalingPolicyAction.INSTANCE, TransportGetAutoscalingPolicyAction.class),
new ActionHandler<>(PutAutoscalingPolicyAction.INSTANCE, TransportPutAutoscalingPolicyAction.class)
Expand All @@ -165,7 +165,7 @@ public List<RestHandler> getRestHandlers(
) {
if (enabled) {
return List.of(
new RestGetAutoscalingDecisionHandler(),
new RestGetAutoscalingCapacityHandler(),
new RestDeleteAutoscalingPolicyHandler(),
new RestGetAutoscalingPolicyHandler(),
new RestPutAutoscalingPolicyHandler()
Expand All @@ -186,7 +186,7 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
FixedAutoscalingDeciderConfiguration::new
),
new NamedWriteableRegistry.Entry(
AutoscalingDecision.Reason.class,
AutoscalingDeciderResult.Reason.class,
FixedAutoscalingDeciderConfiguration.NAME,
FixedAutoscalingDeciderService.FixedReason::new
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

package org.elasticsearch.xpack.autoscaling;

import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDeciderConfiguration;
import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDeciderService;
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderConfiguration;
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderService;

import java.util.Collection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecisions;
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResults;

import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import java.util.SortedMap;
import java.util.TreeMap;

public class GetAutoscalingDecisionAction extends ActionType<GetAutoscalingDecisionAction.Response> {
public class GetAutoscalingCapacityAction extends ActionType<GetAutoscalingCapacityAction.Response> {

public static final GetAutoscalingDecisionAction INSTANCE = new GetAutoscalingDecisionAction();
public static final String NAME = "cluster:admin/autoscaling/get_autoscaling_decision";
public static final GetAutoscalingCapacityAction INSTANCE = new GetAutoscalingCapacityAction();
public static final String NAME = "cluster:admin/autoscaling/get_autoscaling_capacity";

private GetAutoscalingDecisionAction() {
private GetAutoscalingCapacityAction() {
super(NAME, Response::new);
}

public static class Request extends AcknowledgedRequest<GetAutoscalingDecisionAction.Request> {
public static class Request extends AcknowledgedRequest<GetAutoscalingCapacityAction.Request> {

public Request() {

Expand Down Expand Up @@ -66,33 +67,33 @@ public int hashCode() {

public static class Response extends ActionResponse implements ToXContentObject {

private final SortedMap<String, AutoscalingDecisions> decisions;
private final SortedMap<String, AutoscalingDeciderResults> results;

public Response(final SortedMap<String, AutoscalingDecisions> decisions) {
this.decisions = Objects.requireNonNull(decisions);
public Response(final SortedMap<String, AutoscalingDeciderResults> results) {
this.results = Objects.requireNonNull(results);
}

public Response(final StreamInput in) throws IOException {
super(in);
decisions = new TreeMap<>(in.readMap(StreamInput::readString, AutoscalingDecisions::new));
results = new TreeMap<>(in.readMap(StreamInput::readString, AutoscalingDeciderResults::new));
}

@Override
public void writeTo(final StreamOutput out) throws IOException {
out.writeMap(decisions, StreamOutput::writeString, (o, decision) -> decision.writeTo(o));
out.writeMap(results, StreamOutput::writeString, (o, decision) -> decision.writeTo(o));
}

@Override
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
builder.startObject();
{
builder.startArray("decisions");
builder.startObject("policies");
{
for (final AutoscalingDecisions decision : decisions.values()) {
decision.toXContent(builder, params);
for (Map.Entry<String, AutoscalingDeciderResults> entry : results.entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
}
builder.endArray();
builder.endObject();
}
builder.endObject();
return builder;
Expand All @@ -103,12 +104,12 @@ public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Response response = (Response) o;
return decisions.equals(response.decisions);
return results.equals(response.results);
}

@Override
public int hashCode() {
return Objects.hash(decisions);
return Objects.hash(results);
}

}
Expand Down

0 comments on commit d573fde

Please sign in to comment.