diff --git a/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerPlugin.java b/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerPlugin.java index 4b9d9a80..84a09648 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerPlugin.java +++ b/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerPlugin.java @@ -59,7 +59,6 @@ import org.opensearch.performanceanalyzer.collectors.telemetry.RTFDisksCollector; import org.opensearch.performanceanalyzer.collectors.telemetry.RTFHeapMetricsCollector; import org.opensearch.performanceanalyzer.collectors.telemetry.RTFNodeStatsAllShardsMetricsCollector; -import org.opensearch.performanceanalyzer.collectors.telemetry.RTFOSMetricsCollector; import org.opensearch.performanceanalyzer.collectors.telemetry.RTFThreadPoolMetricsCollector; import org.opensearch.performanceanalyzer.commons.OSMetricsGeneratorFactory; import org.opensearch.performanceanalyzer.commons.collectors.DisksCollector; @@ -240,8 +239,6 @@ private void scheduleTelemetryCollectors() { scheduledMetricCollectorsExecutor.addScheduledMetricCollector( new RTFCacheConfigMetricsCollector( performanceAnalyzerController, configOverridesWrapper)); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector( - new RTFOSMetricsCollector(performanceAnalyzerController, configOverridesWrapper)); } private void scheduleRcaCollectors() { diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFCacheConfigMetricsCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFCacheConfigMetricsCollector.java index 4e9b8201..8a5e3e5c 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFCacheConfigMetricsCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFCacheConfigMetricsCollector.java @@ -29,15 +29,12 @@ import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; import org.opensearch.performanceanalyzer.config.PerformanceAnalyzerController; -import org.opensearch.telemetry.metrics.Histogram; import org.opensearch.telemetry.metrics.MetricsRegistry; import org.opensearch.telemetry.metrics.tags.Tags; public class RTFCacheConfigMetricsCollector extends PerformanceAnalyzerMetricsCollector implements TelemetryCollector { private MetricsRegistry metricsRegistry; - private boolean metricsInitialised; - private Histogram cacheMaxSizeMetrics; private static final Logger LOG = LogManager.getLogger(RTFCacheConfigMetricsCollector.class); private PerformanceAnalyzerController performanceAnalyzerController; private ConfigOverridesWrapper configOverridesWrapper; @@ -51,7 +48,6 @@ public RTFCacheConfigMetricsCollector( "RTFCacheConfigMetricsCollector", StatMetrics.RTF_CACHE_CONFIG_METRICS_COLLECTOR_EXECUTION_TIME, StatExceptionCode.RTF_CACHE_CONFIG_METRICS_COLLECTOR_ERROR); - this.metricsInitialised = false; this.performanceAnalyzerController = performanceAnalyzerController; this.configOverridesWrapper = configOverridesWrapper; } @@ -77,7 +73,6 @@ configOverridesWrapper, getCollectorName())) { } LOG.debug("Executing collect metrics for RTFCacheConfigMetricsCollector"); - initialiseMetricsIfNeeded(); CacheMaxSizeStatus fieldDataCacheMaxSizeStatus = AccessController.doPrivileged( (PrivilegedAction) @@ -99,8 +94,7 @@ configOverridesWrapper, getCollectorName())) { LOG.debug( "Error occurred while fetching fieldDataCacheMaxSizeStatus: " + e.getMessage()); - return new CacheMaxSizeStatus( - FIELD_DATA_CACHE.toString(), -1L); + return null; } }); @@ -135,16 +129,12 @@ configOverridesWrapper, getCollectorName())) { LOG.debug( "Error occurred while fetching shardRequestCacheMaxSizeStatus: " + e.getMessage()); - return new CacheMaxSizeStatus( - SHARD_REQUEST_CACHE.toString(), -1L); + return null; } }); if (fieldDataCacheMaxSizeStatus != null && fieldDataCacheMaxSizeStatus.getCacheMaxSize() > 0) { - LOG.info( - "fieldDataCacheMaxSizeStatus.getCacheMaxSize() value : " - + fieldDataCacheMaxSizeStatus.getCacheMaxSize()); recordMetrics(fieldDataCacheMaxSizeStatus); } @@ -155,25 +145,17 @@ configOverridesWrapper, getCollectorName())) { } private void recordMetrics(CacheMaxSizeStatus cacheMaxSizeStatus) { - cacheMaxSizeMetrics.record( - cacheMaxSizeStatus.getCacheMaxSize(), + metricsRegistry.createGauge( + RTFMetrics.CacheConfigValue.Constants.CACHE_MAX_SIZE_VALUE, + "Cache Max Size metrics", + RTFMetrics.MetricUnits.BYTE.toString(), + () -> (double) cacheMaxSizeStatus.getCacheMaxSize(), Tags.create() .addTag( RTFMetrics.CacheConfigDimension.Constants.TYPE_VALUE, cacheMaxSizeStatus.getCacheType())); } - private void initialiseMetricsIfNeeded() { - if (metricsInitialised == false) { - cacheMaxSizeMetrics = - metricsRegistry.createHistogram( - RTFMetrics.CacheConfigValue.Constants.CACHE_MAX_SIZE_VALUE, - "CacheMaxSizeMetrics", - RTFMetrics.MetricUnits.BYTE.toString()); - metricsInitialised = true; - } - } - static class CacheMaxSizeStatus extends MetricStatus { private final String cacheType; diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFOSMetricsCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFOSMetricsCollector.java deleted file mode 100644 index 0b575cb5..00000000 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFOSMetricsCollector.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.performanceanalyzer.collectors.telemetry; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.OpenSearchResources; -import org.opensearch.performanceanalyzer.commons.OSMetricsGeneratorFactory; -import org.opensearch.performanceanalyzer.commons.collectors.PerformanceAnalyzerMetricsCollector; -import org.opensearch.performanceanalyzer.commons.collectors.TelemetryCollector; -import org.opensearch.performanceanalyzer.commons.config.overrides.ConfigOverridesWrapper; -import org.opensearch.performanceanalyzer.commons.jvm.ThreadList; -import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; -import org.opensearch.performanceanalyzer.commons.metrics.RTFMetrics; -import org.opensearch.performanceanalyzer.commons.metrics_generator.CPUPagingActivityGenerator; -import org.opensearch.performanceanalyzer.commons.metrics_generator.OSMetricsGenerator; -import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; -import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; -import org.opensearch.performanceanalyzer.config.PerformanceAnalyzerController; -import org.opensearch.telemetry.metrics.Histogram; -import org.opensearch.telemetry.metrics.MetricsRegistry; -import org.opensearch.telemetry.metrics.tags.Tags; - -public class RTFOSMetricsCollector extends PerformanceAnalyzerMetricsCollector - implements TelemetryCollector { - private MetricsRegistry metricsRegistry; - private boolean metricsInitialised; - private Histogram cpuUtilizationMetrics; - private static final Logger LOG = LogManager.getLogger(RTFOSMetricsCollector.class); - private PerformanceAnalyzerController performanceAnalyzerController; - private ConfigOverridesWrapper configOverridesWrapper; - private OSMetricsGenerator osMetricsGenerator; - - public RTFOSMetricsCollector( - PerformanceAnalyzerController performanceAnalyzerController, - ConfigOverridesWrapper configOverridesWrapper) { - super( - MetricsConfiguration.CONFIG_MAP.get(ThreadList.class).samplingInterval, - "RTFOSMetricsCollector", - StatMetrics.RTF_OS_METRICS_COLLECTOR_EXECUTION_TIME, - StatExceptionCode.RTF_OS_METRICS_COLLECTOR_ERROR); - this.metricsInitialised = false; - this.performanceAnalyzerController = performanceAnalyzerController; - this.configOverridesWrapper = configOverridesWrapper; - osMetricsGenerator = OSMetricsGeneratorFactory.getInstance(); - } - - @Override - public void collectMetrics(long l) { - if (performanceAnalyzerController.isCollectorDisabled( - configOverridesWrapper, getCollectorName())) { - LOG.info("RTFOSMetricsCollector is disabled. Skipping collection."); - return; - } - - osMetricsGenerator = OSMetricsGeneratorFactory.getInstance(); - if (osMetricsGenerator == null) { - LOG.error("could not get the instance of OSMetricsGeneratorFactory class"); - return; - } - - metricsRegistry = OpenSearchResources.INSTANCE.getMetricsRegistry(); - if (metricsRegistry == null) { - LOG.error("could not get the instance of MetricsRegistry class"); - return; - } - - LOG.debug("Executing collect metrics for RTFOSMetricsCollector"); - initialiseMetricsIfNeeded(); - CPUPagingActivityGenerator threadCPUPagingActivityGenerator = - osMetricsGenerator.getPagingActivityGenerator(); - threadCPUPagingActivityGenerator.addSample(); - - recordMetrics(threadCPUPagingActivityGenerator); - } - - public void recordMetrics(CPUPagingActivityGenerator threadCPUPagingActivityGenerator) { - for (String threadId : osMetricsGenerator.getAllThreadIds()) { - cpuUtilizationMetrics.record( - threadCPUPagingActivityGenerator.getCPUUtilization(threadId), - Tags.create().addTag("thread_id", threadId)); - } - } - - private void initialiseMetricsIfNeeded() { - if (metricsInitialised == false) { - cpuUtilizationMetrics = - metricsRegistry.createHistogram( - RTFMetrics.OSMetrics.CPU_UTILIZATION.toString(), - "CPUUtilizationMetrics", - RTFMetrics.MetricUnits.PERCENT.toString()); - metricsInitialised = true; - } - } -} diff --git a/src/main/java/org/opensearch/performanceanalyzer/util/Utils.java b/src/main/java/org/opensearch/performanceanalyzer/util/Utils.java index 1f2cbeee..8245c38b 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/util/Utils.java +++ b/src/main/java/org/opensearch/performanceanalyzer/util/Utils.java @@ -51,8 +51,9 @@ public static void configureMetrics() { MetricsConfiguration.CONFIG_MAP.put(RTFHeapMetricsCollector.class, cdefault); MetricsConfiguration.CONFIG_MAP.put(RTFNodeStatsAllShardsMetricsCollector.class, cdefault); MetricsConfiguration.CONFIG_MAP.put(RTFThreadPoolMetricsCollector.class, cdefault); - MetricsConfiguration.CONFIG_MAP.put(RTFOSMetricsCollector.class, cdefault); - MetricsConfiguration.CONFIG_MAP.put(RTFCacheConfigMetricsCollector.class, cdefault); + MetricsConfiguration.CONFIG_MAP.put( + RTFCacheConfigMetricsCollector.class, + new MetricsConfiguration.MetricConfig(60000, 0)); } // These methods are utility functions for the Node Stat Metrics Collectors. These methods are diff --git a/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFOSMetricsCollectorTests.java b/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFOSMetricsCollectorTests.java deleted file mode 100644 index 8186f0f9..00000000 --- a/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFOSMetricsCollectorTests.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.anyString; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import org.junit.Before; -import org.junit.Test; -import org.opensearch.performanceanalyzer.OpenSearchResources; -import org.opensearch.performanceanalyzer.collectors.CollectorTestBase; -import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; -import org.opensearch.telemetry.metrics.Histogram; -import org.opensearch.telemetry.metrics.MetricsRegistry; - -public class RTFOSMetricsCollectorTests extends CollectorTestBase { - private RTFOSMetricsCollector rtfosMetricsCollector; - private static MetricsRegistry metricsRegistry; - private static Histogram testHistogram; - - @Before - public void init() { - MetricsConfiguration.CONFIG_MAP.put( - RTFOSMetricsCollector.class, MetricsConfiguration.cdefault); - System.setProperty("os.name", "Linux"); - metricsRegistry = mock(MetricsRegistry.class); - testHistogram = mock(Histogram.class); - OpenSearchResources.INSTANCE.setMetricsRegistry(metricsRegistry); - when(metricsRegistry.createHistogram(anyString(), anyString(), anyString())) - .thenReturn(testHistogram); - rtfosMetricsCollector = spy(new RTFOSMetricsCollector(mockController, mockWrapper)); - } - - @Test - public void testCollectMetrics() throws IOException { - rtfosMetricsCollector.collectMetrics(System.currentTimeMillis()); - verify(rtfosMetricsCollector, atLeastOnce()).recordMetrics(any()); - } -}