-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Atharva Sharma <[email protected]>
- Loading branch information
1 parent
e9b5d57
commit 538d682
Showing
3 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
.../java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFDisksCollectorTests.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,71 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.performanceanalyzer.collectors.telemetry; | ||
|
||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.*; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
import java.io.IOException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.opensearch.performanceanalyzer.OpenSearchResources; | ||
import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; | ||
import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; | ||
import org.opensearch.telemetry.metrics.Histogram; | ||
import org.opensearch.telemetry.metrics.MetricsRegistry; | ||
|
||
public class RTFDisksCollectorTests { | ||
private RTFDisksCollector rtfDisksCollector; | ||
private static MetricsRegistry metricsRegistry; | ||
private static Histogram diskWaitTimeHistogram; | ||
private static Histogram diskServiceRateHistogram; | ||
private static Histogram diskUtilizationHistogram; | ||
|
||
private static final String OS_TYPE = System.getProperty("os.name"); | ||
|
||
@Before | ||
public void init() { | ||
initMocks(this); | ||
System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); | ||
MetricsConfiguration.CONFIG_MAP.put(RTFDisksCollector.class, MetricsConfiguration.cdefault); | ||
|
||
metricsRegistry = mock(MetricsRegistry.class); | ||
diskWaitTimeHistogram = mock(Histogram.class); | ||
diskServiceRateHistogram = mock(Histogram.class); | ||
diskUtilizationHistogram = mock(Histogram.class); | ||
OpenSearchResources.INSTANCE.setMetricsRegistry(metricsRegistry); | ||
|
||
when(metricsRegistry.createHistogram(anyString(), anyString(), anyString())) | ||
.thenAnswer( | ||
invocationOnMock -> { | ||
String histogramName = (String) invocationOnMock.getArguments()[0]; | ||
if (histogramName.contains(AllMetrics.DiskValue.Constants.WAIT_VALUE)) { | ||
return diskWaitTimeHistogram; | ||
} else if (histogramName.contains( | ||
AllMetrics.DiskValue.Constants.SRATE_VALUE)) { | ||
return diskServiceRateHistogram; | ||
} | ||
return diskUtilizationHistogram; | ||
}); | ||
|
||
rtfDisksCollector = new RTFDisksCollector(); | ||
} | ||
|
||
@Test | ||
public void testCollectMetrics() throws IOException { | ||
if (isLinux()) { | ||
rtfDisksCollector.collectMetrics(System.currentTimeMillis()); | ||
verify(diskUtilizationHistogram, atLeastOnce()).record(anyDouble(), any()); | ||
verify(diskServiceRateHistogram, atLeastOnce()).record(anyDouble(), any()); | ||
verify(diskWaitTimeHistogram, atLeastOnce()).record(anyDouble(), any()); | ||
} | ||
} | ||
|
||
private static boolean isLinux() { | ||
return OS_TYPE.toLowerCase().contains("linux"); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...org/opensearch/performanceanalyzer/collectors/telemetry/RTFHeapMetricsCollectorTests.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,70 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.performanceanalyzer.collectors.telemetry; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyDouble; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.*; | ||
import static org.mockito.Mockito.atLeastOnce; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
import java.io.IOException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.opensearch.performanceanalyzer.OpenSearchResources; | ||
import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; | ||
import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; | ||
import org.opensearch.telemetry.metrics.Histogram; | ||
import org.opensearch.telemetry.metrics.MetricsRegistry; | ||
|
||
public class RTFHeapMetricsCollectorTests { | ||
private RTFHeapMetricsCollector rtfHeapMetricsCollector; | ||
|
||
private static MetricsRegistry metricsRegistry; | ||
private static Histogram gcCollectionEventHistogram; | ||
private static Histogram gcCollectionTimeHistogram; | ||
private static Histogram heapUsedHistogram; | ||
|
||
@Before | ||
public void init() { | ||
initMocks(this); | ||
System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); | ||
MetricsConfiguration.CONFIG_MAP.put( | ||
RTFHeapMetricsCollector.class, MetricsConfiguration.cdefault); | ||
|
||
metricsRegistry = mock(MetricsRegistry.class); | ||
gcCollectionEventHistogram = mock(Histogram.class); | ||
gcCollectionTimeHistogram = mock(Histogram.class); | ||
heapUsedHistogram = mock(Histogram.class); | ||
OpenSearchResources.INSTANCE.setMetricsRegistry(metricsRegistry); | ||
|
||
when(metricsRegistry.createHistogram(anyString(), anyString(), anyString())) | ||
.thenAnswer( | ||
invocationOnMock -> { | ||
String histogramName = (String) invocationOnMock.getArguments()[0]; | ||
if (histogramName.contains( | ||
AllMetrics.HeapValue.Constants.COLLECTION_COUNT_VALUE)) { | ||
return gcCollectionEventHistogram; | ||
} else if (histogramName.contains( | ||
AllMetrics.HeapValue.Constants.COLLECTION_TIME_VALUE)) { | ||
return gcCollectionTimeHistogram; | ||
} | ||
return heapUsedHistogram; | ||
}); | ||
rtfHeapMetricsCollector = new RTFHeapMetricsCollector(); | ||
} | ||
|
||
@Test | ||
public void testCollectMetrics() throws IOException { | ||
rtfHeapMetricsCollector.collectMetrics(System.currentTimeMillis()); | ||
verify(heapUsedHistogram, atLeastOnce()).record(anyDouble(), any()); | ||
verify(gcCollectionTimeHistogram, atLeastOnce()).record(anyDouble(), any()); | ||
verify(gcCollectionEventHistogram, atLeastOnce()).record(anyDouble(), any()); | ||
verify(metricsRegistry, atLeastOnce()) | ||
.createGauge(anyString(), anyString(), anyString(), any(), any()); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
...ensearch/performanceanalyzer/collectors/telemetry/RTFThreadPoolMetricsCollectorTests.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,92 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.performanceanalyzer.collectors.telemetry; | ||
|
||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.*; | ||
import static org.mockito.Mockito.atLeastOnce; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.opensearch.performanceanalyzer.OpenSearchResources; | ||
import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; | ||
import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; | ||
import org.opensearch.telemetry.metrics.Histogram; | ||
import org.opensearch.telemetry.metrics.MetricsRegistry; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.threadpool.ThreadPoolStats; | ||
|
||
public class RTFThreadPoolMetricsCollectorTests { | ||
private RTFThreadPoolMetricsCollector rtfThreadPoolMetricsCollector; | ||
private static MetricsRegistry metricsRegistry; | ||
private static Histogram threadPoolQueueSizeHistogram; | ||
private static Histogram threadPoolRejectedReqsHistogram; | ||
private static Histogram threadPoolTotalThreadsHistogram; | ||
private static Histogram threadPoolActiveThreadsHistogram; | ||
private static Histogram threadPoolQueueCapacityHistogram; | ||
@Mock private ThreadPool mockThreadPool; | ||
|
||
@Before | ||
public void init() { | ||
initMocks(this); | ||
System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); | ||
MetricsConfiguration.CONFIG_MAP.put( | ||
RTFThreadPoolMetricsCollector.class, MetricsConfiguration.cdefault); | ||
metricsRegistry = mock(MetricsRegistry.class); | ||
threadPoolQueueSizeHistogram = mock(Histogram.class); | ||
threadPoolRejectedReqsHistogram = mock(Histogram.class); | ||
threadPoolActiveThreadsHistogram = mock(Histogram.class); | ||
threadPoolTotalThreadsHistogram = mock(Histogram.class); | ||
threadPoolQueueCapacityHistogram = mock(Histogram.class); | ||
|
||
OpenSearchResources.INSTANCE.setMetricsRegistry(metricsRegistry); | ||
OpenSearchResources.INSTANCE.setThreadPool(mockThreadPool); | ||
|
||
when(metricsRegistry.createHistogram(anyString(), anyString(), anyString())) | ||
.thenAnswer( | ||
invocationOnMock -> { | ||
String histogramName = (String) invocationOnMock.getArguments()[0]; | ||
if (histogramName.contains( | ||
AllMetrics.ThreadPoolValue.Constants.QUEUE_SIZE_VALUE)) { | ||
return threadPoolQueueSizeHistogram; | ||
} else if (histogramName.contains( | ||
AllMetrics.ThreadPoolValue.Constants.REJECTED_VALUE)) { | ||
return threadPoolRejectedReqsHistogram; | ||
} else if (histogramName.contains( | ||
AllMetrics.ThreadPoolValue.Constants.THREADS_ACTIVE_VALUE)) { | ||
return threadPoolActiveThreadsHistogram; | ||
} else if (histogramName.contains( | ||
AllMetrics.ThreadPoolValue.Constants.QUEUE_CAPACITY_VALUE)) { | ||
return threadPoolQueueCapacityHistogram; | ||
} | ||
return threadPoolTotalThreadsHistogram; | ||
}); | ||
|
||
rtfThreadPoolMetricsCollector = new RTFThreadPoolMetricsCollector(); | ||
} | ||
|
||
@Test | ||
public void testCollectMetrics() throws IOException { | ||
when(mockThreadPool.stats()).thenReturn(generateThreadPoolStat()); | ||
rtfThreadPoolMetricsCollector.collectMetrics(System.currentTimeMillis()); | ||
verify(mockThreadPool, atLeastOnce()).stats(); | ||
verify(threadPoolQueueSizeHistogram, atLeastOnce()).record(anyDouble(), any()); | ||
verify(threadPoolRejectedReqsHistogram, atLeastOnce()).record(anyDouble(), any()); | ||
verify(threadPoolActiveThreadsHistogram, atLeastOnce()).record(anyDouble(), any()); | ||
verify(threadPoolTotalThreadsHistogram, atLeastOnce()).record(anyDouble(), any()); | ||
} | ||
|
||
private ThreadPoolStats generateThreadPoolStat() { | ||
List<ThreadPoolStats.Stats> stats = new ArrayList<>(); | ||
stats.add(new ThreadPoolStats.Stats("write", 0, 0, 0, 2, 0, 0L, 20L)); | ||
return new ThreadPoolStats(stats); | ||
} | ||
} |