Skip to content

Commit

Permalink
Expose ?master_timeout in autoscaling APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner committed May 17, 2024
1 parent e769544 commit 5e32b6f
Show file tree
Hide file tree
Showing 37 changed files with 268 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ users can use this API.

This API deletes an autoscaling policy with the provided name.

[[autoscaling-delete-autoscaling-policy-params]]
==== {api-query-parms-title}

include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]

[[autoscaling-delete-autoscaling-policy-examples]]
==== {api-examples-title}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ and why autoscaling determined a certain capacity was required. This information
is provided for diagnosis only. Do not use this information to make autoscaling
decisions.

[[autoscaling-get-autoscaling-capacity-params]]
==== {api-query-parms-title}

include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]

[role="child_attributes"]
[[autoscaling-get-autoscaling-capacity-api-response-body]]
==== {api-response-body-title}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ GET /_autoscaling/policy/<name>

This API gets an autoscaling policy with the provided name.

[[autoscaling-get-autoscaling-policy-params]]
==== {api-query-parms-title}

include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]

[[autoscaling-get-autoscaling-policy-examples]]
==== {api-examples-title}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ users can use this API.
This API puts an autoscaling policy with the provided name.
See <<autoscaling-deciders,Autoscaling Deciders>> for available deciders.

[[autoscaling-put-autoscaling-policy-params]]
==== {api-query-parms-title}

include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]

[[autoscaling-put-autoscaling-policy-examples]]
==== {api-examples-title}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
}
}
]
},
"params":{
"master_timeout":{
"type":"time",
"description":"Timeout for processing on master node"
},
"timeout":{
"type":"time",
"description":"Timeout for acknowledgement of update from all nodes in cluster"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
]
}
]
},
"params":{
"master_timeout":{
"type":"time",
"description":"Timeout for processing on master node"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
}
}
]
},
"params":{
"master_timeout":{
"type":"time",
"description":"Timeout for processing on master node"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
}
]
},
"params":{
"master_timeout":{
"type":"time",
"description":"Timeout for processing on master node"
},
"timeout":{
"type":"time",
"description":"Timeout for acknowledgement of update from all nodes in cluster"
}
},
"body":{
"description":"the specification of the autoscaling policy",
"required":true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ static TransportVersion def(int id) {
public static final TransportVersion ML_INFERENCE_AZURE_AI_STUDIO = def(8_659_00_0);
public static final TransportVersion ML_INFERENCE_COHERE_COMPLETION_ADDED = def(8_660_00_0);
public static final TransportVersion ESQL_REMOVE_ES_SOURCE_OPTIONS = def(8_661_00_0);
public static final TransportVersion GET_AUTOSCALING_CAPACITY_UNUSED_TIMEOUT = def(8_662_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase;
import org.elasticsearch.snapshots.SnapshotInfo;
Expand Down Expand Up @@ -111,14 +112,16 @@ protected void createAndMountIndex() throws InterruptedException, java.util.conc
}

protected GetAutoscalingCapacityAction.Response capacity() {
GetAutoscalingCapacityAction.Request request = new GetAutoscalingCapacityAction.Request();
GetAutoscalingCapacityAction.Request request = new GetAutoscalingCapacityAction.Request(TimeValue.THIRTY_SECONDS);
return client().execute(GetAutoscalingCapacityAction.INSTANCE, request).actionGet();
}

private void putAutoscalingPolicy() {
// randomly set the setting to verify it can be set.
final Settings settings = randomBoolean() ? Settings.EMPTY : addDeciderSettings(Settings.builder()).build();
final PutAutoscalingPolicyAction.Request request = new PutAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
policyName,
new TreeSet<>(Set.of(DataTier.DATA_FROZEN)),
new TreeMap<>(Map.of(deciderName(), settings))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.cluster.metadata.ReservedStateMetadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.core.Strings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.reservedstate.service.FileSettingsService;
import org.elasticsearch.xcontent.XContentParserConfiguration;
Expand Down Expand Up @@ -222,7 +223,16 @@ private PutAutoscalingPolicyAction.Request sampleRestRequest(String name) throws
var bis = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
var parser = JSON.xContent().createParser(XContentParserConfiguration.EMPTY, bis)
) {
return PutAutoscalingPolicyAction.Request.parse(parser, name);
return PutAutoscalingPolicyAction.Request.parse(
parser,
(roles, deciders) -> new PutAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
name,
roles,
deciders
)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.xpack.autoscaling.action.DeleteAutoscalingPolicyAction;
Expand Down Expand Up @@ -45,6 +46,8 @@ protected Collection<Class<? extends Plugin>> getPlugins() {

public void testCanNotPutPolicyWithNonCompliantLicense() throws InterruptedException {
final PutAutoscalingPolicyAction.Request request = new PutAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
"",
Collections.emptySortedSet(),
Collections.emptySortedMap()
Expand Down Expand Up @@ -75,7 +78,7 @@ public void onFailure(final Exception e) {
}

public void testCanNotGetPolicyWithNonCompliantLicense() throws InterruptedException {
final GetAutoscalingPolicyAction.Request request = new GetAutoscalingPolicyAction.Request("");
final GetAutoscalingPolicyAction.Request request = new GetAutoscalingPolicyAction.Request(TimeValue.THIRTY_SECONDS, "");
final CountDownLatch latch = new CountDownLatch(1);
client().execute(GetAutoscalingPolicyAction.INSTANCE, request, new ActionListener<>() {

Expand All @@ -102,7 +105,7 @@ public void onFailure(final Exception e) {
}

public void testCanNonGetAutoscalingCapacityDecisionWithNonCompliantLicense() throws InterruptedException {
final GetAutoscalingCapacityAction.Request request = new GetAutoscalingCapacityAction.Request();
final GetAutoscalingCapacityAction.Request request = new GetAutoscalingCapacityAction.Request(TimeValue.THIRTY_SECONDS);
final CountDownLatch latch = new CountDownLatch(1);
client().execute(GetAutoscalingCapacityAction.INSTANCE, request, new ActionListener<>() {

Expand All @@ -129,7 +132,11 @@ public void onFailure(final Exception e) {
}

public void testCanDeleteAutoscalingPolicyEvenWithNonCompliantLicense() throws InterruptedException {
final DeleteAutoscalingPolicyAction.Request request = new DeleteAutoscalingPolicyAction.Request("*");
final DeleteAutoscalingPolicyAction.Request request = new DeleteAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
"*"
);
final CountDownLatch latch = new CountDownLatch(1);
client().execute(DeleteAutoscalingPolicyAction.INSTANCE, request, new ActionListener<>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.xpack.autoscaling.action.DeleteAutoscalingPolicyAction;
import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingPolicyAction;
Expand Down Expand Up @@ -55,7 +56,11 @@ public void testAutoscalingPolicyWillNotBeRestored() {

final boolean deletePolicy = randomBoolean();
if (deletePolicy) {
final DeleteAutoscalingPolicyAction.Request deleteRequest = new DeleteAutoscalingPolicyAction.Request(policy.name());
final DeleteAutoscalingPolicyAction.Request deleteRequest = new DeleteAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
policy.name()
);
assertAcked(client.execute(DeleteAutoscalingPolicyAction.INSTANCE, deleteRequest).actionGet());
} else {
// Update the policy
Expand Down Expand Up @@ -83,6 +88,8 @@ public void testAutoscalingPolicyWillNotBeRestored() {

private void putPolicy(AutoscalingPolicy policy) {
final PutAutoscalingPolicyAction.Request request = new PutAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
policy.name(),
policy.roles(),
policy.deciders()
Expand All @@ -91,13 +98,19 @@ private void putPolicy(AutoscalingPolicy policy) {
}

private void assertPolicy(AutoscalingPolicy policy) {
final GetAutoscalingPolicyAction.Request getRequest = new GetAutoscalingPolicyAction.Request(policy.name());
final GetAutoscalingPolicyAction.Request getRequest = new GetAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
policy.name()
);
final AutoscalingPolicy actualPolicy = client().execute(GetAutoscalingPolicyAction.INSTANCE, getRequest).actionGet().policy();
assertThat(actualPolicy, equalTo(policy));
}

private void assertPolicyNotFound(AutoscalingPolicy policy) {
final GetAutoscalingPolicyAction.Request getRequest = new GetAutoscalingPolicyAction.Request(policy.name());
final GetAutoscalingPolicyAction.Request getRequest = new GetAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
policy.name()
);
final ResourceNotFoundException e = expectThrows(
ResourceNotFoundException.class,
() -> client().execute(GetAutoscalingPolicyAction.INSTANCE, getRequest).actionGet().policy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.tasks.CancellableTask;
Expand All @@ -39,7 +40,6 @@
import java.util.TreeSet;
import java.util.concurrent.CancellationException;

import static junit.framework.TestCase.assertTrue;
import static org.elasticsearch.action.support.ActionTestUtils.wrapAsRestResponseListener;
import static org.elasticsearch.common.xcontent.XContentHelper.convertToMap;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
Expand Down Expand Up @@ -144,6 +144,8 @@ private Map<String, Object> responseAsMap(Response response) throws IOException

private void putAutoscalingPolicy(Map<String, Settings> settingsMap) {
final PutAutoscalingPolicyAction.Request request1 = new PutAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
"test",
new TreeSet<>(Set.of(DiscoveryNodeRole.DATA_ROLE.roleName())),
// test depends on using treemap's internally, i.e., count is evaluated before wait_for_cancel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xpack.autoscaling.AutoscalingIntegTestCase;
import org.elasticsearch.xpack.autoscaling.AutoscalingMetadata;
import org.elasticsearch.xpack.autoscaling.policy.AutoscalingPolicy;
Expand All @@ -25,22 +26,31 @@ public class TransportDeleteAutoscalingPolicyActionIT extends AutoscalingIntegTe
public void testDeletePolicy() {
final AutoscalingPolicy policy = randomAutoscalingPolicy();
final PutAutoscalingPolicyAction.Request putRequest = new PutAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
policy.name(),
policy.roles(),
policy.deciders()
);
assertAcked(client().execute(PutAutoscalingPolicyAction.INSTANCE, putRequest).actionGet());
// we trust that the policy is in the cluster state since we have tests for putting policies
String deleteName = randomFrom("*", policy.name(), policy.name().substring(0, between(0, policy.name().length())) + "*");
final DeleteAutoscalingPolicyAction.Request deleteRequest = new DeleteAutoscalingPolicyAction.Request(deleteName);
final DeleteAutoscalingPolicyAction.Request deleteRequest = new DeleteAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
deleteName
);
assertAcked(client().execute(DeleteAutoscalingPolicyAction.INSTANCE, deleteRequest).actionGet());
// now verify that the policy is not in the cluster state
final ClusterState state = clusterAdmin().prepareState().get().getState();
final AutoscalingMetadata metadata = state.metadata().custom(AutoscalingMetadata.NAME);
assertNotNull(metadata);
assertThat(metadata.policies(), not(hasKey(policy.name())));
// and verify that we can not obtain the policy via get
final GetAutoscalingPolicyAction.Request getRequest = new GetAutoscalingPolicyAction.Request(policy.name());
final GetAutoscalingPolicyAction.Request getRequest = new GetAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
policy.name()
);
final ResourceNotFoundException e = expectThrows(
ResourceNotFoundException.class,
client().execute(GetAutoscalingPolicyAction.INSTANCE, getRequest)
Expand All @@ -50,7 +60,11 @@ public void testDeletePolicy() {

public void testDeleteNonExistentPolicy() {
final String name = randomAlphaOfLength(8);
final DeleteAutoscalingPolicyAction.Request deleteRequest = new DeleteAutoscalingPolicyAction.Request(name);
final DeleteAutoscalingPolicyAction.Request deleteRequest = new DeleteAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
name
);
final ResourceNotFoundException e = expectThrows(
ResourceNotFoundException.class,
() -> client().execute(DeleteAutoscalingPolicyAction.INSTANCE, deleteRequest).actionGet()
Expand All @@ -60,7 +74,11 @@ public void testDeleteNonExistentPolicy() {

public void testDeleteNonExistentPolicyByWildcard() {
final String name = randomFrom("*", randomAlphaOfLength(8) + "*");
final DeleteAutoscalingPolicyAction.Request deleteRequest = new DeleteAutoscalingPolicyAction.Request(name);
final DeleteAutoscalingPolicyAction.Request deleteRequest = new DeleteAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
name
);
assertAcked(client().execute(DeleteAutoscalingPolicyAction.INSTANCE, deleteRequest).actionGet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.elasticsearch.xpack.autoscaling.action;

import org.apache.logging.log4j.Level;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.monitor.os.OsProbe;
import org.elasticsearch.test.ESIntegTestCase;
Expand Down Expand Up @@ -73,13 +74,15 @@ public void assertCurrentCapacity(long memory, long storage, int nodes) {
}

public GetAutoscalingCapacityAction.Response capacity() {
GetAutoscalingCapacityAction.Request request = new GetAutoscalingCapacityAction.Request();
GetAutoscalingCapacityAction.Request request = new GetAutoscalingCapacityAction.Request(TimeValue.THIRTY_SECONDS);
GetAutoscalingCapacityAction.Response response = client().execute(GetAutoscalingCapacityAction.INSTANCE, request).actionGet();
return response;
}

private void putAutoscalingPolicy(String policyName) {
final PutAutoscalingPolicyAction.Request request = new PutAutoscalingPolicyAction.Request(
TimeValue.THIRTY_SECONDS,
TimeValue.THIRTY_SECONDS,
policyName,
new TreeSet<>(Set.of("data")),
new TreeMap<>()
Expand Down

0 comments on commit 5e32b6f

Please sign in to comment.