diff --git a/elasticsearch/x-pack/build.gradle b/elasticsearch/x-pack/build.gradle index 8e68915e7b0..c2584564d5b 100644 --- a/elasticsearch/x-pack/build.gradle +++ b/elasticsearch/x-pack/build.gradle @@ -1,6 +1,8 @@ import org.elasticsearch.gradle.MavenFilteringHack import org.elasticsearch.gradle.test.NodeInfo +group 'org.elasticsearch.plugin' + apply plugin: 'elasticsearch.esplugin' esplugin { name 'xpack' diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelSettings.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelSettings.java index 37cf6ee90d4..90dcf37dbde 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelSettings.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelSettings.java @@ -32,6 +32,10 @@ public class MarvelSettings extends AbstractComponent { public static final String LEGACY_DATA_INDEX_NAME = ".marvel-es-data"; public static final String HISTORY_DURATION_SETTING_NAME = "history.duration"; + /** + * The minimum amount of time allowed for the history duration. + */ + public static final TimeValue HISTORY_DURATION_MINIMUM = TimeValue.timeValueHours(24); public static final TimeValue MAX_LICENSE_GRACE_PERIOD = TimeValue.timeValueHours(7 * 24); /** @@ -101,10 +105,21 @@ public class MarvelSettings extends AbstractComponent { listSetting(key("agent.collectors"), Collections.emptyList(), Function.identity(), Property.NodeScope); /** - * The default retention duration of the monitoring history data + * The default retention duration of the monitoring history data. + *
+ * Expected values: + *
+ * This will ignore the global retention if the license does not allow retention updates. + * + * @return Never {@code null} + * @see MarvelLicensee#allowUpdateRetention() + */ + public TimeValue getRetention() { + // we only care about their value if they are allowed to set it + if (licensee.allowUpdateRetention() && globalRetention != null) { + return globalRetention; } - if ((retention.getMillis() <= 0) && (retention.getMillis() != -1)) { - throw new IllegalArgumentException("invalid history duration setting value"); - } - if (!licensee.allowUpdateRetention()) { - throw new IllegalArgumentException("license does not allow the history duration setting to be updated to value [" - + retention + "]"); + else { + return MarvelSettings.HISTORY_DURATION.getDefault(Settings.EMPTY); } } + /** + * Set the global retention. This is expected to be used by the cluster settings to dynamically control the global retention time. + *
+ * Even if the current license prevents retention updates, it will accept the change so that they do not need to re-set it if they
+ * upgrade their license (they can always unset it).
+ *
+ * @param globalRetention The global retention to use dynamically.
+ */
+ public void setGlobalRetention(TimeValue globalRetention) {
+ // notify the user that their setting will be ignored until they get the right license
+ if (licensee.allowUpdateRetention() == false) {
+ logger.warn("[{}] setting will be ignored until an appropriate license is applied", MarvelSettings.HISTORY_DURATION.getKey());
+ }
+
+ this.globalRetention = globalRetention;
+ }
+
+ /**
+ * Add a {@code listener} that is executed by the internal {@code IndicesCleaner} given the {@link #getRetention() retention} time.
+ *
+ * @param listener A listener used to control retention
+ */
public void add(Listener listener) {
listeners.add(listener);
}
+ /**
+ * Remove a {@code listener}.
+ *
+ * @param listener A listener used to control retention
+ * @see #add(Listener)
+ */
public void remove(Listener listener) {
listeners.remove(listener);
}
@@ -121,49 +147,56 @@ public class CleanerService extends AbstractLifecycleComponent
+ * This will kill any scheduled {@link #future} from running. It's possible that this will be executed concurrently with the
+ * {@link #onAfter() rescheduling code}, at which point it will be stopped during the next execution if the service is
+ * stopped.
+ */
public void cancel() {
FutureUtils.cancel(future);
}
@@ -179,8 +219,7 @@ public class CleanerService extends AbstractLifecycleComponent