-
Notifications
You must be signed in to change notification settings - Fork 133
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
change disk circuit breaker to cluster settings #2634
Merged
zane-neo
merged 6 commits into
opensearch-project:main
from
zane-neo:make-disk-circuit-breaker-cluster-setting
Jul 12, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ca0628
change disk circuit breaker to cluster settings
zane-neo e65c49a
Fix IT failure
zane-neo f775ee4
format code
zane-neo 33576c8
fix failure UT
zane-neo 49788fa
fix failure IT
zane-neo 607de1b
Address comments
zane-neo 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
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
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
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
78 changes: 78 additions & 0 deletions
78
plugin/src/test/java/org/opensearch/ml/breaker/DiskCircuitBreakerTests.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,78 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the license header seems not with right format
|
||
|
||
package org.opensearch.ml.breaker; | ||
|
||
import static org.mockito.Mockito.when; | ||
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_DISK_FREE_SPACE_THRESHOLD; | ||
|
||
import java.io.File; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.core.common.unit.ByteSizeUnit; | ||
import org.opensearch.core.common.unit.ByteSizeValue; | ||
|
||
public class DiskCircuitBreakerTests { | ||
@Mock | ||
ClusterService clusterService; | ||
|
||
@Mock | ||
File file; | ||
|
||
@Before | ||
public void setup() { | ||
MockitoAnnotations.openMocks(this); | ||
when(clusterService.getClusterSettings()) | ||
.thenReturn(new ClusterSettings(Settings.EMPTY, new HashSet<>(List.of(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD)))); | ||
} | ||
|
||
@Test | ||
public void test_isOpen_whenDiskFreeSpaceIsHigherThanMinValue_breakerIsNotOpen() { | ||
CircuitBreaker breaker = new DiskCircuitBreaker( | ||
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD.getKey(), new ByteSizeValue(4L, ByteSizeUnit.GB)).build(), | ||
clusterService, | ||
file | ||
); | ||
when(file.getFreeSpace()).thenReturn(5 * 1024 * 1024 * 1024L); | ||
Assert.assertFalse(breaker.isOpen()); | ||
} | ||
|
||
@Test | ||
public void test_isOpen_whenDiskFreeSpaceIsLessThanMinValue_breakerIsOpen() { | ||
CircuitBreaker breaker = new DiskCircuitBreaker( | ||
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD.getKey(), new ByteSizeValue(5L, ByteSizeUnit.GB)).build(), | ||
clusterService, | ||
file | ||
); | ||
when(file.getFreeSpace()).thenReturn(4 * 1024 * 1024 * 1024L); | ||
Assert.assertTrue(breaker.isOpen()); | ||
} | ||
|
||
@Test | ||
public void test_isOpen_whenDiskFreeSpaceConfiguredToZero_breakerIsNotOpen() { | ||
CircuitBreaker breaker = new DiskCircuitBreaker( | ||
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD.getKey(), new ByteSizeValue(0L, ByteSizeUnit.KB)).build(), | ||
clusterService, | ||
file | ||
); | ||
when(file.getFreeSpace()).thenReturn((long) (Math.random() * 1024 * 1024 * 1024 * 1024L)); | ||
Assert.assertFalse(breaker.isOpen()); | ||
} | ||
|
||
@Test | ||
public void test_getName() { | ||
CircuitBreaker breaker = new DiskCircuitBreaker(Settings.EMPTY, clusterService, file); | ||
Assert.assertEquals("Disk Circuit Breaker", breaker.getName()); | ||
} | ||
} |
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
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.
nit: another alternative could be
ByteSizeValue
instead of int. it has more fine-grained control.