Skip to content

Commit 6315198

Browse files
authored
[8.16] Fix enrich cache size setting name (#117575) (#118286)
* Fix enrich cache size setting name (#117575) The enrich cache size setting accidentally got renamed from `enrich.cache_size` to `enrich.cache.size` in #111412. This commit updates the enrich plugin to accept both names and deprecates the wrong name. * Remove `UpdateForV10` annotation
1 parent ec59206 commit 6315198

File tree

3 files changed

+121
-3
lines changed

3 files changed

+121
-3
lines changed

docs/changelog/117575.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 117575
2+
summary: Fix enrich cache size setting name
3+
area: Ingest Node
4+
type: bug
5+
issues: []

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.elasticsearch.cluster.node.DiscoveryNodes;
1515
import org.elasticsearch.common.Strings;
1616
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
17+
import org.elasticsearch.common.logging.DeprecationCategory;
18+
import org.elasticsearch.common.logging.DeprecationLogger;
1719
import org.elasticsearch.common.settings.ClusterSettings;
1820
import org.elasticsearch.common.settings.IndexScopedSettings;
1921
import org.elasticsearch.common.settings.Setting;
@@ -74,6 +76,8 @@
7476

7577
public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlugin {
7678

79+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(EnrichPlugin.class);
80+
7781
static final Setting<Integer> ENRICH_FETCH_SIZE_SETTING = Setting.intSetting(
7882
"enrich.fetch_size",
7983
10000,
@@ -126,9 +130,9 @@ public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu
126130
return String.valueOf(maxConcurrentRequests * maxLookupsPerRequest);
127131
}, val -> Setting.parseInt(val, 1, Integer.MAX_VALUE, QUEUE_CAPACITY_SETTING_NAME), Setting.Property.NodeScope);
128132

129-
public static final String CACHE_SIZE_SETTING_NAME = "enrich.cache.size";
133+
public static final String CACHE_SIZE_SETTING_NAME = "enrich.cache_size";
130134
public static final Setting<FlatNumberOrByteSizeValue> CACHE_SIZE = new Setting<>(
131-
"enrich.cache.size",
135+
CACHE_SIZE_SETTING_NAME,
132136
(String) null,
133137
(String s) -> FlatNumberOrByteSizeValue.parse(
134138
s,
@@ -138,16 +142,58 @@ public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu
138142
Setting.Property.NodeScope
139143
);
140144

145+
/**
146+
* This setting solely exists because the original setting was accidentally renamed in
147+
* https://github.com/elastic/elasticsearch/pull/111412.
148+
*/
149+
public static final String CACHE_SIZE_SETTING_BWC_NAME = "enrich.cache.size";
150+
public static final Setting<FlatNumberOrByteSizeValue> CACHE_SIZE_BWC = new Setting<>(
151+
CACHE_SIZE_SETTING_BWC_NAME,
152+
(String) null,
153+
(String s) -> FlatNumberOrByteSizeValue.parse(
154+
s,
155+
CACHE_SIZE_SETTING_BWC_NAME,
156+
new FlatNumberOrByteSizeValue(ByteSizeValue.ofBytes((long) (0.01 * JvmInfo.jvmInfo().getConfiguredMaxHeapSize())))
157+
),
158+
Setting.Property.NodeScope,
159+
Setting.Property.Deprecated
160+
);
161+
141162
private final Settings settings;
142163
private final EnrichCache enrichCache;
164+
private final long maxCacheSize;
143165

144166
public EnrichPlugin(final Settings settings) {
145167
this.settings = settings;
146-
FlatNumberOrByteSizeValue maxSize = CACHE_SIZE.get(settings);
168+
FlatNumberOrByteSizeValue maxSize;
169+
if (settings.hasValue(CACHE_SIZE_SETTING_BWC_NAME)) {
170+
if (settings.hasValue(CACHE_SIZE_SETTING_NAME)) {
171+
throw new IllegalArgumentException(
172+
Strings.format(
173+
"Both [{}] and [{}] are set, please use [{}]",
174+
CACHE_SIZE_SETTING_NAME,
175+
CACHE_SIZE_SETTING_BWC_NAME,
176+
CACHE_SIZE_SETTING_NAME
177+
)
178+
);
179+
}
180+
deprecationLogger.warn(
181+
DeprecationCategory.SETTINGS,
182+
"enrich_cache_size_name",
183+
"The [{}] setting is deprecated and will be removed in a future version. Please use [{}] instead.",
184+
CACHE_SIZE_SETTING_BWC_NAME,
185+
CACHE_SIZE_SETTING_NAME
186+
);
187+
maxSize = CACHE_SIZE_BWC.get(settings);
188+
} else {
189+
maxSize = CACHE_SIZE.get(settings);
190+
}
147191
if (maxSize.byteSizeValue() != null) {
148192
this.enrichCache = new EnrichCache(maxSize.byteSizeValue());
193+
this.maxCacheSize = maxSize.byteSizeValue().getBytes();
149194
} else {
150195
this.enrichCache = new EnrichCache(maxSize.flatNumber());
196+
this.maxCacheSize = maxSize.flatNumber();
151197
}
152198
}
153199

@@ -286,6 +332,11 @@ public String getFeatureDescription() {
286332
return "Manages data related to Enrich policies";
287333
}
288334

335+
// Visible for testing
336+
long getMaxCacheSize() {
337+
return maxCacheSize;
338+
}
339+
289340
/**
290341
* A class that specifies either a flat (unit-less) number or a byte size value.
291342
*/
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.enrich;
9+
10+
import org.elasticsearch.common.settings.Settings;
11+
import org.elasticsearch.test.ESTestCase;
12+
13+
import java.util.List;
14+
15+
public class EnrichPluginTests extends ESTestCase {
16+
17+
public void testConstructWithByteSize() {
18+
final var size = randomNonNegativeInt();
19+
Settings settings = Settings.builder().put(EnrichPlugin.CACHE_SIZE_SETTING_NAME, size + "b").build();
20+
EnrichPlugin plugin = new EnrichPlugin(settings);
21+
assertEquals(size, plugin.getMaxCacheSize());
22+
}
23+
24+
public void testConstructWithFlatNumber() {
25+
final var size = randomNonNegativeInt();
26+
Settings settings = Settings.builder().put(EnrichPlugin.CACHE_SIZE_SETTING_NAME, size).build();
27+
EnrichPlugin plugin = new EnrichPlugin(settings);
28+
assertEquals(size, plugin.getMaxCacheSize());
29+
}
30+
31+
public void testConstructWithByteSizeBwc() {
32+
final var size = randomNonNegativeInt();
33+
Settings settings = Settings.builder().put(EnrichPlugin.CACHE_SIZE_SETTING_BWC_NAME, size + "b").build();
34+
EnrichPlugin plugin = new EnrichPlugin(settings);
35+
assertEquals(size, plugin.getMaxCacheSize());
36+
}
37+
38+
public void testConstructWithFlatNumberBwc() {
39+
final var size = randomNonNegativeInt();
40+
Settings settings = Settings.builder().put(EnrichPlugin.CACHE_SIZE_SETTING_BWC_NAME, size).build();
41+
EnrichPlugin plugin = new EnrichPlugin(settings);
42+
assertEquals(size, plugin.getMaxCacheSize());
43+
}
44+
45+
public void testConstructWithBothSettings() {
46+
Settings settings = Settings.builder()
47+
.put(EnrichPlugin.CACHE_SIZE_SETTING_NAME, randomNonNegativeInt())
48+
.put(EnrichPlugin.CACHE_SIZE_SETTING_BWC_NAME, randomNonNegativeInt())
49+
.build();
50+
assertThrows(IllegalArgumentException.class, () -> new EnrichPlugin(settings));
51+
}
52+
53+
@Override
54+
protected List<String> filteredWarnings() {
55+
final var warnings = super.filteredWarnings();
56+
warnings.add("[enrich.cache.size] setting was deprecated in Elasticsearch and will be removed in a future release.");
57+
warnings.add(
58+
"The [enrich.cache.size] setting is deprecated and will be removed in a future version. Please use [enrich.cache_size] instead."
59+
);
60+
return warnings;
61+
}
62+
}

0 commit comments

Comments
 (0)