forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ILM for Watcher history deletion
This commit adds an index lifecycle policy for the `.watch-history-*` indices. This policy is automatically used for all new watch history indices. This does not yet remove the automatic cleanup that the monitoring plugin does for the .watch-history indices, and it does not touch the `xpack.watcher.history.cleaner_service.enabled` setting. Relates to elastic#32041
- Loading branch information
Showing
11 changed files
with
265 additions
and
10 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
.../core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.indexlifecycle; | ||
|
||
import org.elasticsearch.ElasticsearchParseException; | ||
import org.elasticsearch.common.bytes.BytesArray; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.compress.NotXContentException; | ||
import org.elasticsearch.common.io.Streams; | ||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.common.xcontent.XContentHelper; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* A utility class used for loading index lifecycle policies from the resource classpath | ||
*/ | ||
public class LifecyclePolicyUtils { | ||
|
||
private LifecyclePolicyUtils() {}; | ||
|
||
/** | ||
* Loads a built-in index lifecycle policy and returns its source. | ||
*/ | ||
public static LifecyclePolicy loadPolicy(String name, String resource, NamedXContentRegistry xContentRegistry) { | ||
try { | ||
BytesReference source = load(resource); | ||
validate(source); | ||
|
||
try (XContentParser parser = XContentType.JSON.xContent() | ||
.createParser(xContentRegistry, LoggingDeprecationHandler.THROW_UNSUPPORTED_OPERATION, source.utf8ToString())) { | ||
return LifecyclePolicy.parse(parser, name); | ||
} | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("unable to load policy [" + name + "] from [" + resource + "]", e); | ||
} | ||
} | ||
|
||
/** | ||
* Loads a resource from the classpath and returns it as a {@link BytesReference} | ||
*/ | ||
private static BytesReference load(String name) throws IOException { | ||
try (InputStream is = LifecyclePolicyUtils.class.getResourceAsStream(name)) { | ||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { | ||
Streams.copy(is, out); | ||
return new BytesArray(out.toByteArray()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Parses and validates that the source is not empty. | ||
*/ | ||
private static void validate(BytesReference source) { | ||
if (source == null) { | ||
throw new ElasticsearchParseException("policy must not be null"); | ||
} | ||
|
||
try { | ||
XContentHelper.convertToMap(source, false, XContentType.JSON).v2(); | ||
} catch (NotXContentException e) { | ||
throw new ElasticsearchParseException("policy must not be empty"); | ||
} catch (Exception e) { | ||
throw new ElasticsearchParseException("invalid policy", e); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
x-pack/plugin/core/src/main/resources/watch-history-policy.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"phases": { | ||
"delete": { | ||
"min_age": "30d", | ||
"actions": { | ||
"delete": {} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.