-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make jvm heap usage a dynamic setting #1212
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
57 changes: 57 additions & 0 deletions
57
src/main/java/org/opensearch/timeseries/breaker/MemoryCircuitBreakerNumericSetting.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,57 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.timeseries.breaker; | ||
|
||
import static java.util.Collections.unmodifiableMap; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.timeseries.settings.DynamicNumericSetting; | ||
|
||
public class MemoryCircuitBreakerNumericSetting extends DynamicNumericSetting { | ||
|
||
/** | ||
* Singleton instance | ||
*/ | ||
private static MemoryCircuitBreakerNumericSetting INSTANCE; | ||
|
||
/** | ||
* Setting name | ||
*/ | ||
public static final String JVM_HEAP_USAGE_THRESHOLD = "plugins.ad.jvm_heap_usage.threshold"; | ||
|
||
public MemoryCircuitBreakerNumericSetting(Map<String, Setting<?>> settings) { | ||
super(settings); | ||
} | ||
|
||
public static synchronized MemoryCircuitBreakerNumericSetting getInstance() { | ||
if (INSTANCE == null) { | ||
INSTANCE = new MemoryCircuitBreakerNumericSetting(settings); | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
/** | ||
* Get the jvm_heap_usage threshold setting value | ||
* @return jvm_heap_usage threshold setting value | ||
*/ | ||
public static int getJVMHeapUsageThreshold() { | ||
return MemoryCircuitBreakerNumericSetting | ||
.getInstance() | ||
.getSettingValue(MemoryCircuitBreakerNumericSetting.JVM_HEAP_USAGE_THRESHOLD); | ||
} | ||
|
||
private static final Map<String, Setting<?>> settings = unmodifiableMap(new HashMap<String, Setting<?>>() { | ||
{ | ||
put( | ||
JVM_HEAP_USAGE_THRESHOLD, | ||
Setting.intSetting(JVM_HEAP_USAGE_THRESHOLD, 95, 0, 98, Setting.Property.NodeScope, Setting.Property.Dynamic) | ||
); | ||
} | ||
}); | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/org/opensearch/ad/breaker/MemoryCircuitBreakerNumericSettingTests.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,55 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ad.breaker; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.timeseries.breaker.MemoryCircuitBreakerNumericSetting; | ||
|
||
public class MemoryCircuitBreakerNumericSettingTests extends OpenSearchTestCase { | ||
private MemoryCircuitBreakerNumericSetting memoryCircuitBreakerNumericSetting; | ||
|
||
@Override | ||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
memoryCircuitBreakerNumericSetting = MemoryCircuitBreakerNumericSetting.getInstance(); | ||
} | ||
|
||
@Test | ||
public void testGetThresholdValue_shouldReturnThresholdValue() { | ||
memoryCircuitBreakerNumericSetting.setSettingValue(MemoryCircuitBreakerNumericSetting.JVM_HEAP_USAGE_THRESHOLD, 96); | ||
int value = MemoryCircuitBreakerNumericSetting.getJVMHeapUsageThreshold(); | ||
assertEquals(96, value); | ||
} | ||
|
||
@Test | ||
public void testGetSettingValue_shouldReturnSettingValue() { | ||
Map<String, Setting<?>> settingsMap = new HashMap<>(); | ||
Setting<Integer> testSetting = Setting.intSetting("test.setting", 1, Setting.Property.NodeScope); | ||
settingsMap.put("test.setting", testSetting); | ||
memoryCircuitBreakerNumericSetting = new MemoryCircuitBreakerNumericSetting(settingsMap); | ||
|
||
memoryCircuitBreakerNumericSetting.setSettingValue("test.setting", 2); | ||
Integer value = memoryCircuitBreakerNumericSetting.getSettingValue("test.setting"); | ||
assertEquals(2, value.intValue()); | ||
} | ||
|
||
@Test | ||
public void testGetSettingValue_withNonexistent_shouldThrowException() { | ||
try { | ||
memoryCircuitBreakerNumericSetting.getSettingValue("nonexistent.key"); | ||
fail("Expected an IllegalArgumentException to be thrown"); | ||
} catch (IllegalArgumentException e) { | ||
assertEquals("Cannot find setting by key [nonexistent.key]", e.getMessage()); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move your code to ADNumericSetting ? We don't need to create a new class for each setting. Also, we covered setting init in TimeSeriesAnalyticsPlugin. Once you moved your code to ADNumericSetting, we don't need another call to initialize memory circuit breaker setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved the logic to
ADNumericSetting
file in the latest revision