Skip to content

Commit 1391c72

Browse files
Change default half-life to 5mins (also set reasonably upper and lower bounds)
1 parent 15db2c8 commit 1391c72

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

server/src/main/java/org/elasticsearch/index/shard/IndexingStatsSettings.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
import org.elasticsearch.common.settings.Settings;
1515
import org.elasticsearch.core.TimeValue;
1616

17-
import java.util.concurrent.TimeUnit;
1817
import java.util.concurrent.atomic.AtomicReference;
1918

2019
/**
2120
* Container for cluster settings related to {@link IndexingStats}.
2221
*/
2322
public class IndexingStatsSettings {
2423

25-
// TODO: Change this default to something sensible:
26-
static final TimeValue RECENT_WRITE_LOAD_HALF_LIFE_DEFAULT = new TimeValue(10000, TimeUnit.DAYS);
24+
static final TimeValue RECENT_WRITE_LOAD_HALF_LIFE_DEFAULT = TimeValue.timeValueMinutes(5); // Aligns with the interval between DSL runs
25+
static final TimeValue RECENT_WRITE_LOAD_HALF_LIFE_MIN = TimeValue.timeValueSeconds(1); // A sub-second half-life makes no sense
26+
static final TimeValue RECENT_WRITE_LOAD_HALF_LIFE_MAX = TimeValue.timeValueDays(100_000); // Long.MAX_VALUE nanos, rounded down
2727

2828
/**
2929
* A cluster setting giving the half-life, in seconds, to use for the Exponentially Weighted Moving Rate calculation used for the
@@ -34,7 +34,8 @@ public class IndexingStatsSettings {
3434
public static final Setting<TimeValue> RECENT_WRITE_LOAD_HALF_LIFE_SETTING = Setting.timeSetting(
3535
"indices.stats.recent_write_load.half_life",
3636
RECENT_WRITE_LOAD_HALF_LIFE_DEFAULT,
37-
TimeValue.ZERO,
37+
RECENT_WRITE_LOAD_HALF_LIFE_MIN,
38+
RECENT_WRITE_LOAD_HALF_LIFE_MAX,
3839
Setting.Property.Dynamic,
3940
Setting.Property.NodeScope
4041
);

server/src/test/java/org/elasticsearch/index/shard/IndexingStatsSettingsTests.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
import org.elasticsearch.core.TimeValue;
1515
import org.elasticsearch.test.ESTestCase;
1616

17+
import java.math.BigDecimal;
18+
import java.math.RoundingMode;
19+
1720
import static org.hamcrest.Matchers.equalTo;
1821

1922
public class IndexingStatsSettingsTests extends ESTestCase {
@@ -40,4 +43,60 @@ public void testRecentWriteLoadHalfLife_updateValue() {
4043
);
4144
assertThat(settings.getRecentWriteLoadHalfLifeForNewShards(), equalTo(TimeValue.timeValueMinutes(90)));
4245
}
46+
47+
public void testRecentWriteLoadHalfLife_minValue() {
48+
IndexingStatsSettings settings = new IndexingStatsSettings(
49+
ClusterSettings.createBuiltInClusterSettings(
50+
Settings.builder()
51+
.put(
52+
IndexingStatsSettings.RECENT_WRITE_LOAD_HALF_LIFE_SETTING.getKey(),
53+
IndexingStatsSettings.RECENT_WRITE_LOAD_HALF_LIFE_MIN.toString()
54+
)
55+
.build()
56+
)
57+
);
58+
assertThat(settings.getRecentWriteLoadHalfLifeForNewShards(), equalTo(IndexingStatsSettings.RECENT_WRITE_LOAD_HALF_LIFE_MIN));
59+
}
60+
61+
public void testRecentWriteLoadHalfLife_valueTooSmall() {
62+
long tooFewMillis = IndexingStatsSettings.RECENT_WRITE_LOAD_HALF_LIFE_MIN.getMillis() / 2;
63+
assertThrows(
64+
IllegalArgumentException.class,
65+
() -> new IndexingStatsSettings(
66+
ClusterSettings.createBuiltInClusterSettings(
67+
Settings.builder().put(IndexingStatsSettings.RECENT_WRITE_LOAD_HALF_LIFE_SETTING.getKey(), tooFewMillis + "ms").build()
68+
)
69+
)
70+
);
71+
}
72+
73+
public void testRecentWriteLoadHalfLife_maxValue() {
74+
IndexingStatsSettings settings = new IndexingStatsSettings(
75+
ClusterSettings.createBuiltInClusterSettings(
76+
Settings.builder()
77+
.put(
78+
IndexingStatsSettings.RECENT_WRITE_LOAD_HALF_LIFE_SETTING.getKey(),
79+
IndexingStatsSettings.RECENT_WRITE_LOAD_HALF_LIFE_MAX.toString()
80+
)
81+
.build()
82+
)
83+
);
84+
assertThat(settings.getRecentWriteLoadHalfLifeForNewShards(), equalTo(IndexingStatsSettings.RECENT_WRITE_LOAD_HALF_LIFE_MAX));
85+
}
86+
87+
public void testRecentWriteLoadHalfLife_valueTooLarge() {
88+
int tooManyDays = BigDecimal.valueOf(Long.MAX_VALUE)
89+
.add(BigDecimal.ONE)
90+
.divide(BigDecimal.valueOf(24 * 60 * 60 * 1_000_000_000L), RoundingMode.UP)
91+
.setScale(0, RoundingMode.UP)
92+
.intValueExact();
93+
assertThrows(
94+
IllegalArgumentException.class,
95+
() -> new IndexingStatsSettings(
96+
ClusterSettings.createBuiltInClusterSettings(
97+
Settings.builder().put(IndexingStatsSettings.RECENT_WRITE_LOAD_HALF_LIFE_SETTING.getKey(), tooManyDays + "d").build()
98+
)
99+
)
100+
);
101+
}
43102
}

0 commit comments

Comments
 (0)