Skip to content

Commit ec4444b

Browse files
authored
Fixing potential OOME in HistoryIntegrationTest.testThatHistoryIsTruncated() (#111556)
1 parent a0480ce commit ec4444b

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
1010
import org.elasticsearch.action.search.SearchRequestBuilder;
11+
import org.elasticsearch.common.settings.Settings;
1112
import org.elasticsearch.common.unit.ByteSizeValue;
1213
import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse;
1314
import org.elasticsearch.search.SearchHit;
@@ -53,6 +54,15 @@
5354

5455
public class HistoryIntegrationTests extends AbstractWatcherIntegrationTestCase {
5556

57+
@Override
58+
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
59+
60+
return Settings.builder()
61+
.put(super.nodeSettings(nodeOrdinal, otherSettings))
62+
.put("xpack.watcher.max.history.record.size", "100kb") // used for testThatHistoryIsTruncated()
63+
.build();
64+
}
65+
5666
// issue: https://github.com/elastic/x-plugins/issues/2338
5767
public void testThatHistoryIsWrittenWithChainedInput() throws Exception {
5868
XContentBuilder xContentBuilder = jsonBuilder().startObject()
@@ -232,13 +242,13 @@ public void testThatHistoryContainsStatus() throws Exception {
232242
public void testThatHistoryIsTruncated() throws Exception {
233243
{
234244
/*
235-
* The input for this watch is 1 MB, smaller than the 10 MB default of HistoryStore's MAX_HISTORY_SIZE_SETTING. So we do not
236-
* expect its history record to be truncated.
245+
* The input for this watch is 20 KB, smaller than the configured 100 KB of HistoryStore's MAX_HISTORY_SIZE_SETTING. So we do
246+
* not expect its history record to be truncated.
237247
*/
238248
new PutWatchRequestBuilder(client()).setId("test_watch_small")
239249
.setSource(
240250
watchBuilder().trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.HOURS)))
241-
.input(simpleInput("foo", randomAlphaOfLength((int) ByteSizeValue.ofMb(1).getBytes())))
251+
.input(simpleInput("foo", randomAlphaOfLength((int) ByteSizeValue.ofKb(20).getBytes())))
242252
.addAction("_logger", loggingAction("#### randomLogging"))
243253
)
244254
.get();
@@ -261,13 +271,13 @@ public void testThatHistoryIsTruncated() throws Exception {
261271
}
262272
{
263273
/*
264-
* The input for this watch is 20 MB, much bigger than the 10 MB default of HistoryStore's MAX_HISTORY_SIZE_SETTING. So we
274+
* The input for this watch is 500 KB, much bigger than the configured 100 KB of HistoryStore's MAX_HISTORY_SIZE_SETTING. So we
265275
* expect to see its history record truncated before being stored.
266276
*/
267277
new PutWatchRequestBuilder(client()).setId("test_watch_large")
268278
.setSource(
269279
watchBuilder().trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.HOURS)))
270-
.input(simpleInput("foo", randomAlphaOfLength((int) ByteSizeValue.ofMb(20).getBytes())))
280+
.input(simpleInput("foo", randomAlphaOfLength((int) ByteSizeValue.ofKb(500).getBytes())))
271281
.addAction("_logger", loggingAction("#### randomLogging"))
272282
)
273283
.get();

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ public List<Setting<?>> getSettings() {
613613
settings.add(SETTING_BULK_CONCURRENT_REQUESTS);
614614
settings.add(SETTING_BULK_FLUSH_INTERVAL);
615615
settings.add(SETTING_BULK_SIZE);
616+
settings.add(HistoryStore.MAX_HISTORY_SIZE_SETTING);
616617

617618
// notification services
618619
settings.addAll(SlackService.getSettings());

0 commit comments

Comments
 (0)