Skip to content

Commit a9111ce

Browse files
authored
Add node setting for disabling SLM (#46794) (#46797)
This adds the `xpack.slm.enabled` setting to allow disabling of SLM functionality as well as its HTTP API endpoints. Relates to #38461
1 parent 85ce1c7 commit a9111ce

File tree

4 files changed

+63
-28
lines changed

4 files changed

+63
-28
lines changed

docs/reference/ilm/apis/slm-api.asciidoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ policies, a way to retrieve policies, and a way to delete unwanted policies, as
1414
well as a separate API for immediately invoking a snapshot based on a policy.
1515

1616
Since SLM falls under the same category as ILM, it is stopped and started by
17-
using the <<start-stop-ilm,start and stop>> ILM APIs.
17+
using the <<start-stop-ilm,start and stop>> ILM APIs. It is, however, managed
18+
by a different enable setting. To disable SLM's functionality, set the cluster
19+
setting `xpack.slm.enabled` to `false` in elasticsearch.yml.
1820

1921
[[slm-api-put]]
2022
=== Put Snapshot Lifecycle Policy API

docs/reference/settings/ilm-settings.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
[[ilm-settings]]
33
=== {ilm-cap} settings
44

5+
These are the settings available for configuring Index Lifecycle Management
6+
7+
==== Cluster level settings
8+
9+
`xpack.ilm.enabled`::
10+
Whether ILM is enabled or disabled, setting this to `false` disables any
11+
ILM REST API endpoints and functionality. Defaults to `true`.
12+
13+
==== Index level settings
514
These index-level {ilm-init} settings are typically configured through index
615
templates. For more information, see <<ilm-gs-create-policy>>.
716

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ private XPackSettings() {
9292
public static final Setting<Boolean> INDEX_LIFECYCLE_ENABLED = Setting.boolSetting("xpack.ilm.enabled", true,
9393
Setting.Property.NodeScope);
9494

95+
/**
96+
* Setting for enabling or disabling the snapshot lifecycle extension. Defaults to true.
97+
*/
98+
public static final Setting<Boolean> SNAPSHOT_LIFECYCLE_ENABLED = Setting.boolSetting("xpack.slm.enabled", true,
99+
Setting.Property.NodeScope);
100+
95101
/** Setting for enabling or disabling TLS. Defaults to false. */
96102
public static final Setting<Boolean> TRANSPORT_SSL_ENABLED = Setting.boolSetting("xpack.security.transport.ssl.enabled", false,
97103
Property.NodeScope);
@@ -255,6 +261,7 @@ public static List<Setting<?>> getAllSettings() {
255261
settings.add(ROLLUP_ENABLED);
256262
settings.add(PASSWORD_HASHING_ALGORITHM);
257263
settings.add(INDEX_LIFECYCLE_ENABLED);
264+
settings.add(SNAPSHOT_LIFECYCLE_ENABLED);
258265
settings.add(DATA_FRAME_ENABLED);
259266
settings.add(FLATTENED_ENABLED);
260267
settings.add(VECTORS_ENABLED);

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,21 @@
108108
import java.util.List;
109109
import java.util.function.Supplier;
110110

111-
import static java.util.Collections.emptyList;
112111
import static org.elasticsearch.xpack.core.ClientHelper.INDEX_LIFECYCLE_ORIGIN;
113112

114113
public class IndexLifecycle extends Plugin implements ActionPlugin {
115114
private final SetOnce<IndexLifecycleService> indexLifecycleInitialisationService = new SetOnce<>();
116115
private final SetOnce<SnapshotLifecycleService> snapshotLifecycleService = new SetOnce<>();
117116
private final SetOnce<SnapshotHistoryStore> snapshotHistoryStore = new SetOnce<>();
118117
private Settings settings;
119-
private boolean enabled;
118+
private boolean ilmEnabled;
119+
private boolean slmEnabled;
120120
private boolean transportClientMode;
121121

122122
public IndexLifecycle(Settings settings) {
123123
this.settings = settings;
124-
this.enabled = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings);
124+
this.ilmEnabled = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings);
125+
this.slmEnabled = XPackSettings.SNAPSHOT_LIFECYCLE_ENABLED.get(settings);
125126
this.transportClientMode = XPackPlugin.transportClientMode(settings);
126127
}
127128

@@ -157,18 +158,25 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
157158
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
158159
NamedXContentRegistry xContentRegistry, Environment environment,
159160
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) {
160-
if (enabled == false || transportClientMode) {
161-
return emptyList();
161+
if (transportClientMode) {
162+
return Collections.emptyList();
162163
}
163-
indexLifecycleInitialisationService.set(new IndexLifecycleService(settings, client, clusterService, threadPool,
164+
final List<Object> components = new ArrayList<>();
165+
if (ilmEnabled) {
166+
indexLifecycleInitialisationService.set(new IndexLifecycleService(settings, client, clusterService, threadPool,
164167
getClock(), System::currentTimeMillis, xContentRegistry));
165-
SnapshotLifecycleTemplateRegistry templateRegistry = new SnapshotLifecycleTemplateRegistry(settings, clusterService, threadPool,
166-
client, xContentRegistry);
167-
snapshotHistoryStore.set(new SnapshotHistoryStore(settings, new OriginSettingClient(client, INDEX_LIFECYCLE_ORIGIN), clusterService
168-
));
169-
snapshotLifecycleService.set(new SnapshotLifecycleService(settings,
170-
() -> new SnapshotLifecycleTask(client, clusterService, snapshotHistoryStore.get()), clusterService, getClock()));
171-
return Arrays.asList(indexLifecycleInitialisationService.get(), snapshotLifecycleService.get(), snapshotHistoryStore.get());
168+
components.add(indexLifecycleInitialisationService.get());
169+
}
170+
if (slmEnabled) {
171+
SnapshotLifecycleTemplateRegistry templateRegistry = new SnapshotLifecycleTemplateRegistry(settings, clusterService, threadPool,
172+
client, xContentRegistry);
173+
snapshotHistoryStore.set(new SnapshotHistoryStore(settings, new OriginSettingClient(client, INDEX_LIFECYCLE_ORIGIN),
174+
clusterService));
175+
snapshotLifecycleService.set(new SnapshotLifecycleService(settings,
176+
() -> new SnapshotLifecycleTask(client, clusterService, snapshotHistoryStore.get()), clusterService, getClock()));
177+
components.addAll(Arrays.asList(snapshotLifecycleService.get(), snapshotHistoryStore.get()));
178+
}
179+
return components;
172180
}
173181

174182
@Override
@@ -204,10 +212,9 @@ public List<org.elasticsearch.common.xcontent.NamedXContentRegistry.Entry> getNa
204212
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
205213
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
206214
Supplier<DiscoveryNodes> nodesInCluster) {
207-
if (enabled == false) {
208-
return emptyList();
209-
}
210-
return Arrays.asList(
215+
List<RestHandler> handlers = new ArrayList<>();
216+
if (ilmEnabled) {
217+
handlers.addAll(Arrays.asList(
211218
new RestPutLifecycleAction(restController),
212219
new RestGetLifecycleAction(restController),
213220
new RestDeleteLifecycleAction(restController),
@@ -217,21 +224,25 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
217224
new RestRetryAction(restController),
218225
new RestStopAction(restController),
219226
new RestStartILMAction(restController),
220-
new RestGetStatusAction(restController),
221-
// Snapshot lifecycle actions
227+
new RestGetStatusAction(restController)
228+
));
229+
}
230+
if (slmEnabled) {
231+
handlers.addAll(Arrays.asList(
222232
new RestPutSnapshotLifecycleAction(restController),
223233
new RestDeleteSnapshotLifecycleAction(restController),
224234
new RestGetSnapshotLifecycleAction(restController),
225235
new RestExecuteSnapshotLifecycleAction(restController)
226-
);
236+
));
237+
}
238+
return handlers;
227239
}
228240

229241
@Override
230242
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
231-
if (enabled == false) {
232-
return emptyList();
233-
}
234-
return Arrays.asList(
243+
List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> actions = new ArrayList<>();
244+
if (ilmEnabled) {
245+
actions.addAll(Arrays.asList(
235246
new ActionHandler<>(PutLifecycleAction.INSTANCE, TransportPutLifecycleAction.class),
236247
new ActionHandler<>(GetLifecycleAction.INSTANCE, TransportGetLifecycleAction.class),
237248
new ActionHandler<>(DeleteLifecycleAction.INSTANCE, TransportDeleteLifecycleAction.class),
@@ -241,12 +252,18 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
241252
new ActionHandler<>(RetryAction.INSTANCE, TransportRetryAction.class),
242253
new ActionHandler<>(StartILMAction.INSTANCE, TransportStartILMAction.class),
243254
new ActionHandler<>(StopILMAction.INSTANCE, TransportStopILMAction.class),
244-
new ActionHandler<>(GetStatusAction.INSTANCE, TransportGetStatusAction.class),
245-
// Snapshot lifecycle actions
255+
new ActionHandler<>(GetStatusAction.INSTANCE, TransportGetStatusAction.class)
256+
));
257+
}
258+
if (slmEnabled) {
259+
actions.addAll(Arrays.asList(
246260
new ActionHandler<>(PutSnapshotLifecycleAction.INSTANCE, TransportPutSnapshotLifecycleAction.class),
247261
new ActionHandler<>(DeleteSnapshotLifecycleAction.INSTANCE, TransportDeleteSnapshotLifecycleAction.class),
248262
new ActionHandler<>(GetSnapshotLifecycleAction.INSTANCE, TransportGetSnapshotLifecycleAction.class),
249-
new ActionHandler<>(ExecuteSnapshotLifecycleAction.INSTANCE, TransportExecuteSnapshotLifecycleAction.class));
263+
new ActionHandler<>(ExecuteSnapshotLifecycleAction.INSTANCE, TransportExecuteSnapshotLifecycleAction.class)
264+
));
265+
}
266+
return actions;
250267
}
251268

252269
@Override

0 commit comments

Comments
 (0)