Skip to content

Commit a31743e

Browse files
authored
Bugfix: Relax updatedAt validation for WLM workload group creation (opensearch-project#20486)
Signed-off-by: hyanggeun <songsogu@gmail.com>
1 parent e0e7f29 commit a31743e

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2020
- [segment replication] Fix segment replication infinite retry due to stale metadata checkpoint ([#20551](https://github.com/opensearch-project/OpenSearch/pull/20551))
2121
- Changing opensearch.cgroups.hierarchy.override causes java.lang.SecurityException exception ([#20565](https://github.com/opensearch-project/OpenSearch/pull/20565))
2222
- Fix CriteriaBasedCodec to work with delegate codec. ([20442](https://github.com/opensearch-project/OpenSearch/pull/20442))
23+
- Fix WLM workload group creation failing due to updated_at clock skew ([#20486](https://github.com/opensearch-project/OpenSearch/pull/20486))
2324

2425
### Dependencies
2526
- Bump `ch.qos.logback:logback-core` and `ch.qos.logback:logback-classic` from 1.5.24 to 1.5.27 ([#20525](https://github.com/opensearch-project/OpenSearch/pull/20525))

server/src/main/java/org/opensearch/cluster/metadata/WorkloadGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public WorkloadGroup(String name, String _id, MutableWorkloadGroupFragment mutab
6969
if (mutableWorkloadGroupFragment.getResourceLimits().isEmpty()) {
7070
throw new IllegalArgumentException("WorkloadGroup.resourceLimits should at least have 1 resource limit");
7171
}
72-
if (!isValid(updatedAt)) {
72+
if (updatedAt <= 0L) {
7373
throw new IllegalArgumentException("WorkloadGroup.updatedAtInMillis is not a valid epoch");
7474
}
7575

server/src/test/java/org/opensearch/cluster/metadata/WorkloadGroupTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,45 @@ public void testValidWorkloadGroup() {
179179
assertEquals(1717187289, workloadGroup.getUpdatedAtInMillis());
180180
}
181181

182+
public void testUpdatedAtAllowsCurrentTimestamp() {
183+
long currentTimestamp = Instant.now().getMillis();
184+
WorkloadGroup workloadGroup = new WorkloadGroup(
185+
"analytics",
186+
"_id",
187+
new MutableWorkloadGroupFragment(randomMode(), Map.of(ResourceType.MEMORY, randomDoubleBetween(0.01, 0.8, false))),
188+
currentTimestamp
189+
);
190+
191+
assertEquals(currentTimestamp, workloadGroup.getUpdatedAtInMillis());
192+
}
193+
194+
public void testUpdatedAtAllowsJitterAroundNow() {
195+
long now = Instant.now().getMillis();
196+
long[] timestamps = new long[] { Math.max(0L, now - 20L), now + 20L };
197+
198+
for (long timestamp : timestamps) {
199+
WorkloadGroup workloadGroup = new WorkloadGroup(
200+
"analytics",
201+
"_id",
202+
new MutableWorkloadGroupFragment(randomMode(), Map.of(ResourceType.MEMORY, randomDoubleBetween(0.01, 0.8, false))),
203+
timestamp
204+
);
205+
assertEquals(timestamp, workloadGroup.getUpdatedAtInMillis());
206+
}
207+
}
208+
209+
public void testUpdatedAtRejectsNegativeTimestamp() {
210+
assertThrows(
211+
IllegalArgumentException.class,
212+
() -> new WorkloadGroup(
213+
"analytics",
214+
"_id",
215+
new MutableWorkloadGroupFragment(randomMode(), Map.of(ResourceType.MEMORY, randomDoubleBetween(0.01, 0.8, false))),
216+
-1L
217+
)
218+
);
219+
}
220+
182221
public void testToXContent() throws IOException {
183222
long currentTimeInMillis = Instant.now().getMillis();
184223
String workloadGroupId = UUIDs.randomBase64UUID();

0 commit comments

Comments
 (0)