|
@@ -12,17 +12,22 @@ import org.elasticsearch.cluster.NamedDiff;
|
|
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|
|
import org.elasticsearch.cluster.metadata.Metadata;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|
|
+import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|
|
import org.elasticsearch.common.settings.ClusterSettings;
|
|
|
import org.elasticsearch.common.settings.IndexScopedSettings;
|
|
|
import org.elasticsearch.common.settings.Setting;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.settings.SettingsFilter;
|
|
|
+import org.elasticsearch.common.unit.ByteSizeValue;
|
|
|
+import org.elasticsearch.common.unit.MemorySizeValue;
|
|
|
+import org.elasticsearch.core.Nullable;
|
|
|
import org.elasticsearch.core.TimeValue;
|
|
|
import org.elasticsearch.features.NodeFeature;
|
|
|
import org.elasticsearch.indices.SystemIndexDescriptor;
|
|
|
import org.elasticsearch.ingest.Processor;
|
|
|
import org.elasticsearch.license.XPackLicenseState;
|
|
|
+import org.elasticsearch.monitor.jvm.JvmInfo;
|
|
|
import org.elasticsearch.plugins.IngestPlugin;
|
|
|
import org.elasticsearch.plugins.Plugin;
|
|
|
import org.elasticsearch.plugins.SystemIndexPlugin;
|
|
@@ -121,14 +126,29 @@ public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu
|
|
|
return String.valueOf(maxConcurrentRequests * maxLookupsPerRequest);
|
|
|
}, val -> Setting.parseInt(val, 1, Integer.MAX_VALUE, QUEUE_CAPACITY_SETTING_NAME), Setting.Property.NodeScope);
|
|
|
|
|
|
- public static final Setting<Long> CACHE_SIZE = Setting.longSetting("enrich.cache_size", 1000, 0, Setting.Property.NodeScope);
|
|
|
+ public static final String CACHE_SIZE_SETTING_NAME = "enrich.cache.size";
|
|
|
+ public static final Setting<FlatNumberOrByteSizeValue> CACHE_SIZE = new Setting<>(
|
|
|
+ "enrich.cache.size",
|
|
|
+ (String) null,
|
|
|
+ (String s) -> FlatNumberOrByteSizeValue.parse(
|
|
|
+ s,
|
|
|
+ CACHE_SIZE_SETTING_NAME,
|
|
|
+ new FlatNumberOrByteSizeValue(ByteSizeValue.ofBytes((long) (0.01 * JvmInfo.jvmInfo().getConfiguredMaxHeapSize())))
|
|
|
+ ),
|
|
|
+ Setting.Property.NodeScope
|
|
|
+ );
|
|
|
|
|
|
private final Settings settings;
|
|
|
private final EnrichCache enrichCache;
|
|
|
|
|
|
public EnrichPlugin(final Settings settings) {
|
|
|
this.settings = settings;
|
|
|
- this.enrichCache = new EnrichCache(CACHE_SIZE.get(settings));
|
|
|
+ FlatNumberOrByteSizeValue maxSize = CACHE_SIZE.get(settings);
|
|
|
+ if (maxSize.byteSizeValue() != null) {
|
|
|
+ this.enrichCache = new EnrichCache(maxSize.byteSizeValue());
|
|
|
+ } else {
|
|
|
+ this.enrichCache = new EnrichCache(maxSize.flatNumber());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -265,4 +285,45 @@ public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu
|
|
|
public String getFeatureDescription() {
|
|
|
return "Manages data related to Enrich policies";
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A class that specifies either a flat (unit-less) number or a byte size value.
|
|
|
+ */
|
|
|
+ public static class FlatNumberOrByteSizeValue {
|
|
|
+
|
|
|
+ @Nullable
|
|
|
+ private final Long flatNumber;
|
|
|
+ @Nullable
|
|
|
+ private final ByteSizeValue byteSizeValue;
|
|
|
+
|
|
|
+ public FlatNumberOrByteSizeValue(ByteSizeValue byteSizeValue) {
|
|
|
+ this.byteSizeValue = byteSizeValue;
|
|
|
+ this.flatNumber = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FlatNumberOrByteSizeValue(Long flatNumber) {
|
|
|
+ this.flatNumber = flatNumber;
|
|
|
+ this.byteSizeValue = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static FlatNumberOrByteSizeValue parse(String value, String settingName, FlatNumberOrByteSizeValue defaultValue) {
|
|
|
+ if (Strings.hasText(value) == false) {
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
+ if (Character.isDigit(value.charAt(value.length() - 1)) == false) {
|
|
|
+ return new FlatNumberOrByteSizeValue(MemorySizeValue.parseBytesSizeValueOrHeapRatio(value, settingName));
|
|
|
+ }
|
|
|
+ return new FlatNumberOrByteSizeValue(Long.parseLong(value));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Nullable
|
|
|
+ public ByteSizeValue byteSizeValue() {
|
|
|
+ return byteSizeValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Nullable
|
|
|
+ public Long flatNumber() {
|
|
|
+ return flatNumber;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|