-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG FIX] Fix updating plugins.ml_commons.jvm_heap_memory_threshold t…
…akes no effect (#1943) * fix plugins.ml_commons.jvm_heap_memory_threshold settings ineffective Signed-off-by: zhichao-aws <[email protected]> * add integ test Signed-off-by: zhichao-aws <[email protected]> * add license header Signed-off-by: zhichao-aws <[email protected]> * fix the bug by override getThreshold Signed-off-by: zhichao-aws <[email protected]> --------- Signed-off-by: zhichao-aws <[email protected]>
- Loading branch information
1 parent
1a436fe
commit 126ed3a
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
plugin/src/test/java/org/opensearch/ml/rest/RestMLMemoryCircuitBreakerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.ml.rest; | ||
|
||
import static org.hamcrest.Matchers.allOf; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.hc.core5.http.HttpHeaders; | ||
import org.apache.hc.core5.http.message.BasicHeader; | ||
import org.junit.After; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.ResponseException; | ||
import org.opensearch.ml.breaker.MemoryCircuitBreaker; | ||
import org.opensearch.ml.utils.TestHelper; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
public class RestMLMemoryCircuitBreakerIT extends MLCommonsRestTestCase { | ||
@After | ||
public void tearDown() throws Exception { | ||
super.tearDown(); | ||
// restore the threshold to default value | ||
Response response1 = TestHelper | ||
.makeRequest( | ||
client(), | ||
"PUT", | ||
"_cluster/settings", | ||
null, | ||
"{\"persistent\":{\"plugins.ml_commons.jvm_heap_memory_threshold\":" | ||
+ MemoryCircuitBreaker.DEFAULT_JVM_HEAP_USAGE_THRESHOLD | ||
+ "}}", | ||
ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) | ||
); | ||
assertEquals(200, response1.getStatusLine().getStatusCode()); | ||
} | ||
|
||
public void testRunWithMemoryCircuitBreaker() throws IOException { | ||
// set a low threshold | ||
Response response1 = TestHelper | ||
.makeRequest( | ||
client(), | ||
"PUT", | ||
"_cluster/settings", | ||
null, | ||
"{\"persistent\":{\"plugins.ml_commons.jvm_heap_memory_threshold\":1}}", | ||
ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) | ||
); | ||
assertEquals(200, response1.getStatusLine().getStatusCode()); | ||
|
||
// expect task fail due to memory limit | ||
Exception exception = assertThrows(ResponseException.class, () -> ingestModelData()); | ||
org.hamcrest.MatcherAssert | ||
.assertThat( | ||
exception.getMessage(), | ||
allOf( | ||
containsString("Memory Circuit Breaker is open, please check your resources!"), | ||
containsString("m_l_limit_exceeded_exception") | ||
) | ||
); | ||
|
||
// set a higher threshold | ||
Response response2 = TestHelper | ||
.makeRequest( | ||
client(), | ||
"PUT", | ||
"_cluster/settings", | ||
null, | ||
"{\"persistent\":{\"plugins.ml_commons.jvm_heap_memory_threshold\":100}}", | ||
ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) | ||
); | ||
assertEquals(200, response2.getStatusLine().getStatusCode()); | ||
|
||
// expect task success | ||
ingestModelData(); | ||
} | ||
} |