-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enables/disables thread contention monitoring based on setting
Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
- Loading branch information
Showing
9 changed files
with
291 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
true |
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 @@ | ||
true |
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
57 changes: 57 additions & 0 deletions
57
...opensearch/performanceanalyzer/rca/samplers/ThreadContentionMonitoringEnabledSampler.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 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
/* | ||
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package org.opensearch.performanceanalyzer.rca.samplers; | ||
|
||
|
||
import java.util.Objects; | ||
import org.opensearch.performanceanalyzer.AppContext; | ||
import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; | ||
import org.opensearch.performanceanalyzer.rca.framework.util.InstanceDetails; | ||
import org.opensearch.performanceanalyzer.rca.stats.collectors.SampleAggregator; | ||
import org.opensearch.performanceanalyzer.rca.stats.emitters.ISampler; | ||
import org.opensearch.performanceanalyzer.reader.ReaderMetricsProcessor; | ||
|
||
public class ThreadContentionMonitoringEnabledSampler implements ISampler { | ||
private final AppContext appContext; | ||
|
||
public ThreadContentionMonitoringEnabledSampler(final AppContext appContext) { | ||
Objects.requireNonNull(appContext); | ||
this.appContext = appContext; | ||
} | ||
|
||
@Override | ||
public void sample(SampleAggregator sampleCollector) { | ||
sampleCollector.updateStat( | ||
ReaderMetrics.THREAD_CONTENTION_MONITORING_ENABLED, | ||
"", | ||
isThreadContentionMonitoringEnabled() ? 1 : 0); | ||
} | ||
|
||
boolean isThreadContentionMonitoringEnabled() { | ||
return ReaderMetricsProcessor.getInstance().getThreadContentionMonitoringEnabled(); | ||
} | ||
} |
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
139 changes: 139 additions & 0 deletions
139
...search/performanceanalyzer/rca/samplers/ThreadContentionMonitoringEnabledSamplerTest.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,139 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
/* | ||
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package org.opensearch.performanceanalyzer.rca.samplers; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.opensearch.performanceanalyzer.AppContext; | ||
import org.opensearch.performanceanalyzer.core.Util; | ||
import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; | ||
import org.opensearch.performanceanalyzer.rca.stats.collectors.SampleAggregator; | ||
import org.opensearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; | ||
import org.opensearch.performanceanalyzer.reader.ClusterDetailsEventProcessorTestHelper; | ||
import org.opensearch.performanceanalyzer.reader.ReaderMetricsProcessor; | ||
|
||
public class ThreadContentionMonitoringEnabledSamplerTest { | ||
private static Path threadContentionMonitoringEnabledConfFile; | ||
private static String rootLocation; | ||
private static ReaderMetricsProcessor mp; | ||
private static AppContext appContext; | ||
private static ThreadContentionMonitoringEnabledSampler uut; | ||
|
||
@Mock private SampleAggregator sampleAggregator; | ||
|
||
@BeforeClass | ||
public static void setUpClass() throws Exception { | ||
Files.createDirectories(Paths.get(Util.DATA_DIR)); | ||
threadContentionMonitoringEnabledConfFile = | ||
Paths.get( | ||
Util.DATA_DIR, | ||
ReaderMetricsProcessor.THREAD_CONTENTION_MONITORING_ENABLED_CONF_FILE); | ||
Files.deleteIfExists(threadContentionMonitoringEnabledConfFile); | ||
|
||
rootLocation = "build/resources/test/reader/"; | ||
mp = new ReaderMetricsProcessor(rootLocation); | ||
ReaderMetricsProcessor.setCurrentInstance(mp); | ||
|
||
appContext = new AppContext(); | ||
uut = new ThreadContentionMonitoringEnabledSampler(appContext); | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
private void writeThreadContentionMonitoringEnabled(boolean enabled) throws IOException { | ||
Files.write( | ||
threadContentionMonitoringEnabledConfFile, Boolean.toString(enabled).getBytes()); | ||
} | ||
|
||
private void clearThreadContentionMonitoringEnabled() throws IOException { | ||
Files.deleteIfExists(threadContentionMonitoringEnabledConfFile); | ||
} | ||
|
||
@Test | ||
public void testIsThreadContentionMonitoringEnabled_notMaster() { | ||
appContext.setClusterDetailsEventProcessor(null); | ||
assertFalse(uut.isThreadContentionMonitoringEnabled()); | ||
} | ||
|
||
@Test | ||
public void testIsThreadContentionMonitoringEnabled() throws IOException { | ||
ClusterDetailsEventProcessor clusterDetailsEventProcessor = | ||
new ClusterDetailsEventProcessor(); | ||
ClusterDetailsEventProcessor.NodeDetails details = | ||
ClusterDetailsEventProcessorTestHelper.newNodeDetails("nodex", "127.0.0.1", true); | ||
clusterDetailsEventProcessor.setNodesDetails(Collections.singletonList(details)); | ||
appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); | ||
|
||
// No thread contention monitoring enabled file | ||
clearThreadContentionMonitoringEnabled(); | ||
mp.readThreadContentionMonitoringEnabledFromConfShim(); | ||
assertFalse(uut.isThreadContentionMonitoringEnabled()); | ||
|
||
// thread contention monitoring disabled | ||
writeThreadContentionMonitoringEnabled(false); | ||
mp.readThreadContentionMonitoringEnabledFromConfShim(); | ||
assertFalse(uut.isThreadContentionMonitoringEnabled()); | ||
|
||
// thread contention monitoring disabled | ||
writeThreadContentionMonitoringEnabled(true); | ||
mp.readThreadContentionMonitoringEnabledFromConfShim(); | ||
assertTrue(uut.isThreadContentionMonitoringEnabled()); | ||
} | ||
|
||
@Test | ||
public void testSample() { | ||
ClusterDetailsEventProcessor clusterDetailsEventProcessor = | ||
new ClusterDetailsEventProcessor(); | ||
ClusterDetailsEventProcessor.NodeDetails details = | ||
ClusterDetailsEventProcessorTestHelper.newNodeDetails("nodex", "127.0.0.1", true); | ||
clusterDetailsEventProcessor.setNodesDetails(Collections.singletonList(details)); | ||
appContext.setClusterDetailsEventProcessor(clusterDetailsEventProcessor); | ||
|
||
uut.sample(sampleAggregator); | ||
verify(sampleAggregator, times(1)) | ||
.updateStat( | ||
ReaderMetrics.THREAD_CONTENTION_MONITORING_ENABLED, | ||
"", | ||
mp.getThreadContentionMonitoringEnabled() ? 1 : 0); | ||
} | ||
} |
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