diff --git a/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerApp.java b/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerApp.java index 1bdfc61c2..44026d0bc 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerApp.java +++ b/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerApp.java @@ -9,30 +9,24 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.sun.net.httpserver.HttpServer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; +import java.util.*; +import java.util.concurrent.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.collectors.*; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.config.ConfigStatus; import org.opensearch.performanceanalyzer.commons.config.PluginSettings; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; -import org.opensearch.performanceanalyzer.commons.stats.IListener; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; -import org.opensearch.performanceanalyzer.commons.util.Util; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.collectors.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.emitters.ISampler; +import org.opensearch.performanceanalyzer.commons.stats.emitters.PeriodicSamplers; +import org.opensearch.performanceanalyzer.commons.stats.listeners.IListener; +import org.opensearch.performanceanalyzer.commons.stats.measurements.MeasurementSet; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.config.TroubleshootingConfig; +import org.opensearch.performanceanalyzer.core.Util; import org.opensearch.performanceanalyzer.jvm.GCMetrics; import org.opensearch.performanceanalyzer.jvm.HeapMetrics; import org.opensearch.performanceanalyzer.jvm.ThreadList; @@ -54,8 +48,6 @@ import org.opensearch.performanceanalyzer.rca.samplers.BatchMetricsEnabledSampler; import org.opensearch.performanceanalyzer.rca.samplers.MetricsDBFileSampler; import org.opensearch.performanceanalyzer.rca.samplers.RcaStateSamplers; -import org.opensearch.performanceanalyzer.rca.stats.emitters.ISampler; -import org.opensearch.performanceanalyzer.rca.stats.emitters.PeriodicSamplers; import org.opensearch.performanceanalyzer.reader.ReaderMetricsProcessor; import org.opensearch.performanceanalyzer.rest.QueryBatchRequestHandler; import org.opensearch.performanceanalyzer.rest.QueryMetricsRequestHandler; @@ -64,8 +56,9 @@ public class PerformanceAnalyzerApp { - private static final int EXCEPTION_QUEUE_LENGTH = 1; private static final Logger LOG = LogManager.getLogger(PerformanceAnalyzerApp.class); + + private static final int EXCEPTION_QUEUE_LENGTH = 1; private static final ScheduledMetricCollectorsExecutor METRIC_COLLECTOR_EXECUTOR = new ScheduledMetricCollectorsExecutor(1, false); private static final ScheduledExecutorService netOperationsExecutor = @@ -75,33 +68,29 @@ public class PerformanceAnalyzerApp { private static RcaController rcaController = null; private static final ThreadProvider THREAD_PROVIDER = new ThreadProvider(); - public static IListener MISBEHAVING_NODES_LISTENER = - new MisbehavingGraphOperateMethodListener(); - public static void initAggregators() { - if (CommonStats.RCA_STATS_REPORTER != null) { - return; - } - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR = new SampleAggregator(RcaGraphMetrics.values()); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR = + ServiceMetrics.READER_METRICS_AGGREGATOR = new SampleAggregator(ReaderMetrics.values()); + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR = + new SampleAggregator(RcaGraphMetrics.values()); + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR = new SampleAggregator(RcaRuntimeMetrics.values()); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR = + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR = new SampleAggregator(RcaVerticesMetrics.values()); - CommonStats.READER_METRICS_AGGREGATOR = new SampleAggregator(ReaderMetrics.values()); - - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR = + final IListener MISBEHAVING_NODES_LISTENER = new MisbehavingGraphOperateMethodListener(); + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR = new SampleAggregator( MISBEHAVING_NODES_LISTENER.getMeasurementsListenedTo(), MISBEHAVING_NODES_LISTENER, ExceptionsAndErrors.values()); - - CommonStats.PERIODIC_SAMPLE_AGGREGATOR = new SampleAggregator(getPeriodicMeasurementSets()); - - CommonStats.initStatsReporter(); + ServiceMetrics.PERIODIC_SAMPLE_AGGREGATOR = + new SampleAggregator(getPeriodicMeasurementSets()); + ServiceMetrics.initStatsReporter(); } static { initAggregators(); + Objects.requireNonNull( + ServiceMetrics.STATS_REPORTER, "Service Metrics(Stat) Reporter should not be null"); } public static PeriodicSamplers PERIODIC_SAMPLERS; @@ -143,7 +132,7 @@ public static void main(String[] args) { AppContext appContext = new AppContext(); PERIODIC_SAMPLERS = new PeriodicSamplers( - CommonStats.PERIODIC_SAMPLE_AGGREGATOR, + ServiceMetrics.PERIODIC_SAMPLE_AGGREGATOR, getAllSamplers(appContext), (MetricsConfiguration.CONFIG_MAP.get(StatsCollector.class) .samplingInterval) @@ -166,8 +155,8 @@ public static void main(String[] args) { startRcaTopLevelThread(clientServers, connectionManager, appContext, THREAD_PROVIDER); } else { LOG.error("Performance analyzer app stopped due to invalid config status."); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.INVALID_CONFIG_RCA_AGENT_STOPPED, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.INVALID_CONFIG_RCA_AGENT_STOPPED); } } @@ -219,12 +208,13 @@ public static Thread startErrorHandlingThread( final PAThreadException exception = errorQueue.take(); handle(exception); } catch (InterruptedException e) { - CommonStats.READER_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.ERROR_HANDLER_THREAD_STOPPED, "", 1); LOG.error( "Exception handling thread interrupted. Reason: {}", e.getMessage(), e); + StatsCollector.instance() + .logException( + StatExceptionCode.ERROR_HANDLER_THREAD_STOPPED); break; } } @@ -241,17 +231,17 @@ public static Thread startErrorHandlingThread( * @param exception The exception thrown from the thread. */ private static void handle(PAThreadException exception) { - // Currently this will only log an exception and increment a metric indicating that the + // Currently, this will only log an exception and increment a metric indicating that the // thread has died. // As an improvement to this functionality, once we know what exceptions are retryable, we // can have each thread also register an error handler for itself. This handler will know // what to do when the thread has stopped due to an unexpected exception. - CommonStats.READER_METRICS_AGGREGATOR.updateStat(ReaderMetrics.OTHER, "", 1); LOG.error( "Thread: {} ran into an uncaught exception: {}", exception.getPaThreadName(), exception.getInnerThrowable(), exception); + StatsCollector.instance().logException(StatExceptionCode.READER_METRICS_PROCESSOR_ERROR); } public static Thread startWebServerThread( diff --git a/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerThreads.java b/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerThreads.java index 91cf8e5f4..f536a9902 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerThreads.java +++ b/src/main/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerThreads.java @@ -6,8 +6,7 @@ package org.opensearch.performanceanalyzer; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; /** * Enum of threads that are spawned by Performance Analyzer agent. Each enum value encapsulates two @@ -15,17 +14,17 @@ * need to be recorded when the thread runs into an unhandled exception. */ public enum PerformanceAnalyzerThreads { - PA_READER("pa-reader", ReaderMetrics.READER_THREAD_STOPPED), - PA_ERROR_HANDLER("pa-error-handler", ReaderMetrics.ERROR_HANDLER_THREAD_STOPPED), - GRPC_SERVER("grpc-server", ReaderMetrics.GRPC_SERVER_THREAD_STOPPED), - WEB_SERVER("web-server", ReaderMetrics.WEB_SERVER_THREAD_STOPPED), - RCA_CONTROLLER("rca-controller", ReaderMetrics.RCA_CONTROLLER_THREAD_STOPPED), - RCA_SCHEDULER("rca-scheduler", ReaderMetrics.RCA_SCHEDULER_THREAD_STOPPED); + PA_READER("pa-reader", StatExceptionCode.READER_THREAD_STOPPED), + PA_ERROR_HANDLER("pa-error-handler", StatExceptionCode.ERROR_HANDLER_THREAD_STOPPED), + GRPC_SERVER("grpc-server", StatExceptionCode.GRPC_SERVER_THREAD_STOPPED), + WEB_SERVER("web-server", StatExceptionCode.WEB_SERVER_THREAD_STOPPED), + RCA_CONTROLLER("rca-controller", StatExceptionCode.RCA_CONTROLLER_THREAD_STOPPED), + RCA_SCHEDULER("rca-scheduler", StatExceptionCode.RCA_SCHEDULER_THREAD_STOPPED); private final String value; - private final MeasurementSet threadExceptionCode; + private final StatExceptionCode threadExceptionCode; - PerformanceAnalyzerThreads(final String value, final MeasurementSet threadExceptionCode) { + PerformanceAnalyzerThreads(final String value, final StatExceptionCode threadExceptionCode) { this.value = value; this.threadExceptionCode = threadExceptionCode; } @@ -47,7 +46,7 @@ public String toString() { * * @return the name of the counter. */ - public MeasurementSet getThreadExceptionCode() { + public StatExceptionCode getThreadExceptionCode() { return threadExceptionCode; } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/DisksCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/DisksCollector.java index 92363dd05..d8446e2c1 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/DisksCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/DisksCollector.java @@ -13,8 +13,8 @@ import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.commons.metrics.MetricsProcessor; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.WriterMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; import org.opensearch.performanceanalyzer.metrics_generator.DiskMetricsGenerator; import org.opensearch.performanceanalyzer.metrics_generator.OSMetricsGenerator; @@ -25,7 +25,11 @@ public class DisksCollector extends PerformanceAnalyzerMetricsCollector MetricsConfiguration.CONFIG_MAP.get(DisksCollector.class).samplingInterval; public DisksCollector() { - super(sTimeInterval, "DisksCollector"); + super( + sTimeInterval, + "DisksCollector", + StatMetrics.DISKS_COLLECTOR_EXECUTION_TIME, + StatExceptionCode.DISK_METRICS_COLLECTOR_ERROR); } @Override @@ -45,15 +49,10 @@ public void collectMetrics(long startTime) { if (generator == null) { return; } - long mCurrT = System.currentTimeMillis(); DiskMetricsGenerator diskMetricsGenerator = generator.getDiskMetricsGenerator(); diskMetricsGenerator.addSample(); saveMetricValues(getMetrics(diskMetricsGenerator), startTime); - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - WriterMetrics.DISKS_COLLECTOR_EXECUTION_TIME, - "", - System.currentTimeMillis() - mCurrT); } private Map getMetricsMap(DiskMetricsGenerator diskMetricsGenerator) { diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/GCInfoCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/GCInfoCollector.java index 1dac40d00..ac2cd98fc 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/GCInfoCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/GCInfoCollector.java @@ -14,8 +14,8 @@ import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.commons.metrics.MetricsProcessor; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.WriterMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; import org.opensearch.performanceanalyzer.jvm.GarbageCollectorInfo; /** @@ -30,12 +30,15 @@ public class GCInfoCollector extends PerformanceAnalyzerMetricsCollector private static final int EXPECTED_KEYS_PATH_LENGTH = 0; public GCInfoCollector() { - super(SAMPLING_TIME_INTERVAL, "GCInfo"); + super( + SAMPLING_TIME_INTERVAL, + "GCInfo", + StatMetrics.GC_INFO_COLLECTOR_EXECUTION_TIME, + StatExceptionCode.GC_INFO_COLLECTOR_ERROR); } @Override public void collectMetrics(long startTime) { - long mCurrT = System.currentTimeMillis(); // Zero the string builder value.setLength(0); @@ -50,10 +53,6 @@ public void collectMetrics(long startTime) { } saveMetricValues(value.toString(), startTime); - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - WriterMetrics.GC_INFO_COLLECTOR_EXECUTION_TIME, - "", - System.currentTimeMillis() - mCurrT); } @Override diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/HeapMetricsCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/HeapMetricsCollector.java index f0a8a9545..867c36fdb 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/HeapMetricsCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/HeapMetricsCollector.java @@ -20,8 +20,8 @@ import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.commons.metrics.MetricsProcessor; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.WriterMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; import org.opensearch.performanceanalyzer.jvm.GCMetrics; import org.opensearch.performanceanalyzer.jvm.HeapMetrics; @@ -33,12 +33,15 @@ public class HeapMetricsCollector extends PerformanceAnalyzerMetricsCollector private static final int KEYS_PATH_LENGTH = 0; public HeapMetricsCollector() { - super(SAMPLING_TIME_INTERVAL, "HeapMetrics"); + super( + SAMPLING_TIME_INTERVAL, + "HeapMetrics", + StatMetrics.HEAP_METRICS_COLLECTOR_EXECUTION_TIME, + StatExceptionCode.HEAP_METRICS_COLLECTOR_ERROR); } @Override public void collectMetrics(long startTime) { - long mCurrT = System.currentTimeMillis(); GCMetrics.runGCMetrics(); value.setLength(0); @@ -76,10 +79,6 @@ public void collectMetrics(long startTime) { } saveMetricValues(value.toString(), startTime); - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - WriterMetrics.HEAP_METRICS_COLLECTOR_EXECUTION_TIME, - "", - System.currentTimeMillis() - mCurrT); } @Override diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/MountedPartitionMetricsCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/MountedPartitionMetricsCollector.java index 9b2c8ede0..5308ebed4 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/MountedPartitionMetricsCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/MountedPartitionMetricsCollector.java @@ -12,6 +12,8 @@ import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.commons.metrics.MetricsProcessor; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; import org.opensearch.performanceanalyzer.metrics_generator.MountedPartitionMetricsGenerator; import org.opensearch.performanceanalyzer.metrics_generator.OSMetricsGenerator; @@ -24,7 +26,11 @@ public class MountedPartitionMetricsCollector extends PerformanceAnalyzerMetrics private static final int EXPECTED_KEYS_PATH_LENGTH = 0; public MountedPartitionMetricsCollector() { - super(SAMPLING_TIME_INTERVAL, "MountedPartition"); + super( + SAMPLING_TIME_INTERVAL, + "MountedPartition", + StatMetrics.MOUNTED_PARTITION_METRICS_COLLECTOR_EXECUTION_TIME, + StatExceptionCode.MOUNTED_PARTITION_METRICS_COLLECTOR_ERROR); } @Override diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/NetworkE2ECollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/NetworkE2ECollector.java index 84ba8231e..032055ffc 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/NetworkE2ECollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/NetworkE2ECollector.java @@ -13,6 +13,8 @@ import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.commons.metrics.MetricsProcessor; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; import org.opensearch.performanceanalyzer.metrics_generator.OSMetricsGenerator; import org.opensearch.performanceanalyzer.metrics_generator.TCPMetricsGenerator; @@ -22,7 +24,11 @@ public class NetworkE2ECollector extends PerformanceAnalyzerMetricsCollector MetricsConfiguration.CONFIG_MAP.get(NetworkE2ECollector.class).samplingInterval; public NetworkE2ECollector() { - super(sTimeInterval, "NetworkE2ECollector"); + super( + sTimeInterval, + "NetworkE2ECollector", + StatMetrics.NETWORK_E2E_COLLECTOR_EXECUTION_TIME, + StatExceptionCode.NETWORK_COLLECTION_ERROR); } @Override diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/NetworkInterfaceCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/NetworkInterfaceCollector.java index 67f4ff2c4..4dadbe372 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/NetworkInterfaceCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/NetworkInterfaceCollector.java @@ -10,13 +10,12 @@ import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.OSMetricsGeneratorFactory; import org.opensearch.performanceanalyzer.commons.collectors.PerformanceAnalyzerMetricsCollector; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.commons.metrics.MetricsProcessor; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.WriterMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; import org.opensearch.performanceanalyzer.metrics_generator.IPMetricsGenerator; import org.opensearch.performanceanalyzer.metrics_generator.OSMetricsGenerator; @@ -27,7 +26,11 @@ public class NetworkInterfaceCollector extends PerformanceAnalyzerMetricsCollect private static final Logger LOG = LogManager.getLogger(NetworkInterfaceCollector.class); public NetworkInterfaceCollector() { - super(sTimeInterval, "NetworkInterfaceCollector"); + super( + sTimeInterval, + "NetworkInterfaceCollector", + StatMetrics.NETWORK_INTERFACE_COLLECTOR_EXECUTION_TIME, + StatExceptionCode.NETWORK_COLLECTION_ERROR); } @Override @@ -37,16 +40,11 @@ public void collectMetrics(long startTime) { return; } - long mCurrT = System.currentTimeMillis(); IPMetricsGenerator IPMetricsGenerator = generator.getIPMetricsGenerator(); IPMetricsGenerator.addSample(); saveMetricValues( getMetrics(IPMetricsGenerator) + PerformanceAnalyzerMetrics.sMetricNewLineDelimitor, startTime); - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - WriterMetrics.NETWORK_INTERFACE_COLLECTOR_EXECUTION_TIME, - "", - System.currentTimeMillis() - mCurrT); } @Override diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/OSMetricsCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/OSMetricsCollector.java index 6aedf3227..8b1e15ef1 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/OSMetricsCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/OSMetricsCollector.java @@ -13,8 +13,8 @@ import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.commons.metrics.MetricsProcessor; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.WriterMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; import org.opensearch.performanceanalyzer.jvm.ThreadList; import org.opensearch.performanceanalyzer.metrics_generator.CPUPagingActivityGenerator; import org.opensearch.performanceanalyzer.metrics_generator.DiskIOMetricsGenerator; @@ -34,14 +34,17 @@ public enum MetaDataFields { } public OSMetricsCollector() { - super(SAMPLING_TIME_INTERVAL, "OSMetrics"); + super( + SAMPLING_TIME_INTERVAL, + "OSMetrics", + StatMetrics.OS_METRICS_COLLECTOR_EXECUTION_TIME, + StatExceptionCode.OS_METRICS_COLLECTOR_ERROR); value = new StringBuilder(); osMetricsGenerator = OSMetricsGeneratorFactory.getInstance(); } @Override public void collectMetrics(long startTime) { - long mCurrT = System.currentTimeMillis(); CPUPagingActivityGenerator threadCPUPagingActivityGenerator = osMetricsGenerator.getPagingActivityGenerator(); threadCPUPagingActivityGenerator.addSample(); @@ -150,10 +153,6 @@ public void collectMetrics(long startTime) { } saveMetricValues(value.toString(), startTime, threadId); - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - WriterMetrics.OS_METRICS_COLLECTOR_EXECUTION_TIME, - "", - System.currentTimeMillis() - mCurrT); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/ScheduledMetricCollectorsExecutor.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/ScheduledMetricCollectorsExecutor.java index 4c189aac7..ade3ff4c6 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/ScheduledMetricCollectorsExecutor.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/ScheduledMetricCollectorsExecutor.java @@ -17,8 +17,8 @@ import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.commons.collectors.PerformanceAnalyzerMetricsCollector; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; -import org.opensearch.performanceanalyzer.commons.metrics.WriterMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; public class ScheduledMetricCollectorsExecutor extends Thread { private static final Logger LOG = LogManager.getLogger(ScheduledMetricCollectorsExecutor.class); @@ -116,10 +116,8 @@ public void run() { PerformanceAnalyzerMetricsCollector collector = entry.getKey(); if (collector.getState() == PerformanceAnalyzerMetricsCollector.State.MUTED) { - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - WriterMetrics.COLLECTORS_MUTED, - collector.getCollectorName(), - 1); + ServiceMetrics.COMMONS_STAT_METRICS_AGGREGATOR.updateStat( + StatMetrics.COLLECTORS_MUTED, collector.getCollectorName(), 1); continue; } metricsCollectors.put( @@ -143,8 +141,8 @@ public void run() { if (collector.getState() == PerformanceAnalyzerMetricsCollector.State.HEALTHY) { collector.setState(PerformanceAnalyzerMetricsCollector.State.SLOW); - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - WriterMetrics.COLLECTORS_SLOW, + ServiceMetrics.COMMONS_STAT_METRICS_AGGREGATOR.updateStat( + StatMetrics.COLLECTORS_SLOW, collector.getCollectorName(), 1); } else if (collector.getState() @@ -154,8 +152,8 @@ public void run() { LOG.info( "Collector {} is still in progress, so skipping this Interval", collector.getCollectorName()); - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - WriterMetrics.COLLECTORS_SKIPPED, + ServiceMetrics.COMMONS_STAT_METRICS_AGGREGATOR.updateStat( + StatMetrics.COLLECTORS_SKIPPED, collector.getCollectorName(), 1); } diff --git a/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/CacheHealthDecider.java b/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/CacheHealthDecider.java index 787a23660..8b245f270 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/CacheHealthDecider.java +++ b/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/CacheHealthDecider.java @@ -13,7 +13,7 @@ import java.util.Set; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.decisionmaker.actions.Action; import org.opensearch.performanceanalyzer.decisionmaker.actions.ModifyCacheMaxSizeAction; import org.opensearch.performanceanalyzer.grpc.ResourceEnum; @@ -134,7 +134,7 @@ private Action computeBestAction(final NodeKey nodeKey, final ResourceEnum cache if (canUseMoreHeap(nodeKey)) { action = getAction(ModifyCacheMaxSizeAction.NAME, nodeKey, cacheType, true); } else { - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( RcaRuntimeMetrics.NO_INCREASE_ACTION_SUGGESTED, NAME + ":" + nodeKey.getHostAddress(), 1); diff --git a/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/Decider.java b/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/Decider.java index a754a950f..f61dabd8e 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/Decider.java +++ b/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/Decider.java @@ -8,10 +8,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.rca.framework.core.NonLeafNode; import org.opensearch.performanceanalyzer.rca.framework.core.RcaConf; +import org.opensearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; import org.opensearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; @@ -54,13 +54,13 @@ public void generateFlowUnitListFromLocal(FlowUnitOperationArgWrapper args) { decision = this.operate(); } catch (Exception ex) { LOG.error("decider: Exception in operate", ex); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_OPERATE, name(), 1); decision = new Decision(System.currentTimeMillis(), this.name()); } long duration = System.currentTimeMillis() - startTime; - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.GRAPH_NODE_OPERATE_CALL, this.name(), duration); setLocalFlowUnit(decision); diff --git a/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/Publisher.java b/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/Publisher.java index 45d56bc00..76644cd93 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/Publisher.java +++ b/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/Publisher.java @@ -13,14 +13,14 @@ import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.decisionmaker.actions.Action; import org.opensearch.performanceanalyzer.decisionmaker.actions.ActionListener; import org.opensearch.performanceanalyzer.decisionmaker.actions.FlipFlopDetector; import org.opensearch.performanceanalyzer.decisionmaker.actions.TimedFlipFlopDetector; import org.opensearch.performanceanalyzer.decisionmaker.deciders.collator.Collator; import org.opensearch.performanceanalyzer.rca.framework.core.NonLeafNode; +import org.opensearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; import org.opensearch.performanceanalyzer.rca.persistence.PublisherEventsPersistor; import org.opensearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; @@ -77,12 +77,12 @@ public void generateFlowUnitListFromLocal(FlowUnitOperationArgWrapper args) { this.compute(args); } catch (Exception ex) { LOG.error("Publisher: Exception in compute", ex); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_COMPUTE, name(), 1); } long duration = System.currentTimeMillis() - startTime; - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.GRAPH_NODE_OPERATE_CALL, this.name(), duration); } diff --git a/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDecider.java b/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDecider.java index 0963b982b..c61bcaf90 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDecider.java +++ b/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDecider.java @@ -10,7 +10,7 @@ import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.decisionmaker.actions.Action; import org.opensearch.performanceanalyzer.decisionmaker.actions.ModifyQueueCapacityAction; import org.opensearch.performanceanalyzer.grpc.ResourceEnum; @@ -99,7 +99,7 @@ private Action computeBestAction(NodeKey nodeKey, ResourceEnum threadPool) { } } } else { - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( RcaRuntimeMetrics.NO_INCREASE_ACTION_SUGGESTED, NAME + ":" + nodeKey.getHostAddress(), 1); diff --git a/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/jvm/sizing/HeapSizeIncreasePolicy.java b/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/jvm/sizing/HeapSizeIncreasePolicy.java index e7f4a69f8..dae7e5377 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/jvm/sizing/HeapSizeIncreasePolicy.java +++ b/src/main/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/jvm/sizing/HeapSizeIncreasePolicy.java @@ -14,7 +14,7 @@ import java.util.Map; import javax.annotation.Nonnull; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.decisionmaker.actions.Action; import org.opensearch.performanceanalyzer.decisionmaker.actions.HeapSizeIncreaseAction; import org.opensearch.performanceanalyzer.decisionmaker.deciders.AlarmMonitor; @@ -52,8 +52,8 @@ public List evaluate() { if (!heapSizeIncreaseClusterMonitor.isHealthy()) { Action heapSizeIncreaseAction = new HeapSizeIncreaseAction(appContext); if (heapSizeIncreaseAction.isActionable()) { - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - RcaRuntimeMetrics.HEAP_SIZE_INCREASE_ACTION_SUGGESTED, "", 1); + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + RcaRuntimeMetrics.HEAP_SIZE_INCREASE_ACTION_SUGGESTED, 1); actions.add(heapSizeIncreaseAction); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/hwnet/NetworkE2E.java b/src/main/java/org/opensearch/performanceanalyzer/hwnet/NetworkE2E.java index 4fef8be21..886b8e681 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/hwnet/NetworkE2E.java +++ b/src/main/java/org/opensearch/performanceanalyzer/hwnet/NetworkE2E.java @@ -19,8 +19,8 @@ import java.util.Set; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.metrics_generator.linux.LinuxTCPMetricsGenerator; import org.opensearch.performanceanalyzer.os.OSGlobals; diff --git a/src/main/java/org/opensearch/performanceanalyzer/hwnet/NetworkInterface.java b/src/main/java/org/opensearch/performanceanalyzer/hwnet/NetworkInterface.java index 67e333d1c..d321eba23 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/hwnet/NetworkInterface.java +++ b/src/main/java/org/opensearch/performanceanalyzer/hwnet/NetworkInterface.java @@ -18,8 +18,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.collectors.NetInterfaceSummary; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.metrics_generator.linux.LinuxIPMetricsGenerator; public class NetworkInterface { diff --git a/src/main/java/org/opensearch/performanceanalyzer/jvm/ThreadList.java b/src/main/java/org/opensearch/performanceanalyzer/jvm/ThreadList.java index 764ff20a1..6a198ebef 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/jvm/ThreadList.java +++ b/src/main/java/org/opensearch/performanceanalyzer/jvm/ThreadList.java @@ -26,11 +26,12 @@ import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.OSMetricsGeneratorFactory; import org.opensearch.performanceanalyzer.collectors.ScheduledMetricCollectorsExecutor; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; +import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; -import org.opensearch.performanceanalyzer.commons.metrics.WriterMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; -import org.opensearch.performanceanalyzer.commons.util.Util; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics; +import org.opensearch.performanceanalyzer.core.Util; import sun.tools.attach.HotSpotVirtualMachine; /** Traverses and prints the stack traces for all Java threads in the remote VM */ @@ -136,8 +137,8 @@ public static Map getNativeTidMap( vmAttachLock.unlock(); } } else { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.JVM_ATTACH_LOCK_ACQUISITION_FAILED, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.JVM_ATTACH_LOCK_ACQUISITION_FAILED); } // - sending a copy so that if runThreadDump next iteration clears it; caller still has the @@ -162,8 +163,7 @@ public static Map getNativeTidMap( public static ThreadState getThreadState(long threadId) { ThreadState retVal = jTidMap.get(threadId); if (retVal == null) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.NO_THREAD_STATE_INFO, "", 1); + StatsCollector.instance().logException(StatExceptionCode.NO_THREAD_STATE_INFO); } return retVal; } @@ -176,11 +176,10 @@ private static void runAttachDump(String pid, String[] args) { vm = VirtualMachine.attach(pid); } catch (Exception ex) { if (ex.getMessage().contains("java_pid")) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.JVM_ATTACH_ERROR_JAVA_PID_FILE_MISSING, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.JVM_ATTACH_ERROR_JAVA_PID_FILE_MISSING); } else { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.JVM_ATTACH_ERROR, "", 1); + StatsCollector.instance().logException(StatExceptionCode.JVM_ATTACH_ERROR); } // If the thread dump failed then we clean up the old map. So, next time when the // collection @@ -192,18 +191,16 @@ private static void runAttachDump(String pid, String[] args) { try (InputStream in = ((HotSpotVirtualMachine) vm).remoteDataDump(args); ) { createMap(in); } catch (Exception ex) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.JVM_ATTACH_ERROR, "", 1); + StatsCollector.instance().logException(StatExceptionCode.JVM_ATTACH_ERROR); oldNativeTidMap.clear(); } try { vm.detach(); - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - WriterMetrics.JVM_THREAD_DUMP_SUCCESSFUL, "", 1); + ServiceMetrics.COMMONS_STAT_METRICS_AGGREGATOR.updateStat( + StatMetrics.JVM_THREAD_DUMP_SUCCESSFUL, 1); } catch (Exception ex) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.JVM_ATTACH_ERROR, "", 1); + StatsCollector.instance().logException(StatExceptionCode.JVM_ATTACH_ERROR); } } @@ -215,8 +212,8 @@ public static void parseAllThreadInfos(ThreadInfo[] infos) { // If the ids provided to the getThreadInfo() call are not valid ids or the threads // no // longer exists, then the corresponding info object will contain null. - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.JVM_THREAD_ID_NO_LONGER_EXISTS, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.JVM_THREAD_ID_NO_LONGER_EXISTS); } } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/metricsdb/MetricsDB.java b/src/main/java/org/opensearch/performanceanalyzer/metricsdb/MetricsDB.java index bf640965f..0411e0461 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/metricsdb/MetricsDB.java +++ b/src/main/java/org/opensearch/performanceanalyzer/metricsdb/MetricsDB.java @@ -38,9 +38,9 @@ import org.jooq.exception.DataAccessException; import org.jooq.impl.DSL; import org.opensearch.performanceanalyzer.DBUtils; +import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.config.PluginSettings; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.reader.Removable; /** @@ -92,8 +92,8 @@ public MetricsDB(long windowStartTime) throws Exception { conn = DriverManager.getConnection(url); conn.setAutoCommit(false); } catch (Exception e) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.READER_METRICSDB_ACCESS_ERRORS, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.READER_METRICSDB_ACCESS_ERRORS); throw e; } create = DSL.using(conn, SQLDialect.SQLITE); @@ -109,8 +109,8 @@ public MetricsDB(long windowStartTime) throws Exception { public static MetricsDB fetchExisting(long windowStartTime) throws Exception { String filePath = getDBFilePath(windowStartTime); if (!(new File(filePath)).exists()) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.READER_METRICSDB_ACCESS_ERRORS, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.READER_METRICSDB_ACCESS_ERRORS); throw new FileNotFoundException( String.format("MetricsDB file %s could not be found.", filePath)); } @@ -347,10 +347,10 @@ public static void deleteOnDiskFile(long windowStartTime) { LOG.error( "Failed to delete File - {} with ExceptionCode: {}", dbFilePath, - ExceptionsAndErrors.READER_METRICSDB_ACCESS_ERRORS, + StatExceptionCode.READER_METRICSDB_ACCESS_ERRORS, e); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.READER_METRICSDB_ACCESS_ERRORS, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.READER_METRICSDB_ACCESS_ERRORS); } } @@ -382,10 +382,10 @@ public static Set listOnDiskFiles() { LOG.error( "Failed to access metricsdb directory - {} with ExceptionCode: {}", parentPath, - ExceptionsAndErrors.READER_METRICSDB_ACCESS_ERRORS, + StatExceptionCode.READER_METRICSDB_ACCESS_ERRORS, e); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.READER_METRICSDB_ACCESS_ERRORS, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.READER_METRICSDB_ACCESS_ERRORS); } return found; } diff --git a/src/main/java/org/opensearch/performanceanalyzer/net/GRPCConnectionManager.java b/src/main/java/org/opensearch/performanceanalyzer/net/GRPCConnectionManager.java index c751720f5..3e82e4455 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/net/GRPCConnectionManager.java +++ b/src/main/java/org/opensearch/performanceanalyzer/net/GRPCConnectionManager.java @@ -5,7 +5,6 @@ package org.opensearch.performanceanalyzer.net; -import static org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors.GRPC_CHANNEL_CLOSURE_ERROR; import com.google.common.annotations.VisibleForTesting; import io.grpc.ManagedChannel; @@ -23,7 +22,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.CertificateUtils; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.grpc.InterNodeRpcServiceGrpc; import org.opensearch.performanceanalyzer.grpc.InterNodeRpcServiceGrpc.InterNodeRpcServiceStub; import org.opensearch.performanceanalyzer.rca.framework.util.InstanceDetails; @@ -220,8 +220,8 @@ private void terminateAllConnections() { channel.shutdownNow(); try { if (!channel.awaitTermination(1, TimeUnit.MINUTES)) { - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - GRPC_CHANNEL_CLOSURE_ERROR, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.GRPC_CHANNEL_CLOSURE_ERROR); LOG.warn("Unable to close channel gracefully for host: {}", entry.getKey()); } } catch (InterruptedException e) { diff --git a/src/main/java/org/opensearch/performanceanalyzer/net/NetClient.java b/src/main/java/org/opensearch/performanceanalyzer/net/NetClient.java index c19cec21d..c43a13984 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/net/NetClient.java +++ b/src/main/java/org/opensearch/performanceanalyzer/net/NetClient.java @@ -14,9 +14,9 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.grpc.InterNodeRpcServiceGrpc; import org.opensearch.performanceanalyzer.grpc.MetricsRequest; @@ -77,7 +77,7 @@ public void subscribe( connectionManager .getClientStubForHost(remoteHost) .subscribe(subscribeMessage, serverResponseStream); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.NET_BYTES_OUT, subscribeMessage.getRequesterGraphNode(), subscribeMessage.getSerializedSize()); @@ -106,7 +106,7 @@ public void publish( getDataStreamForHost( remoteHost, flowUnitMessage.getGraphNode(), serverResponseStream); stream.onNext(flowUnitMessage); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.NET_BYTES_OUT, flowUnitMessage.getGraphNode(), flowUnitMessage.getSerializedSize()); diff --git a/src/main/java/org/opensearch/performanceanalyzer/net/NetServer.java b/src/main/java/org/opensearch/performanceanalyzer/net/NetServer.java index d65ff34ff..9638d4beb 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/net/NetServer.java +++ b/src/main/java/org/opensearch/performanceanalyzer/net/NetServer.java @@ -5,7 +5,6 @@ package org.opensearch.performanceanalyzer.net; -import static org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors.GRPC_SERVER_CLOSURE_ERROR; import com.google.common.annotations.VisibleForTesting; import io.grpc.Server; @@ -24,7 +23,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.CertificateUtils; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.grpc.InterNodeRpcServiceGrpc; import org.opensearch.performanceanalyzer.grpc.MetricsRequest; @@ -253,8 +253,8 @@ public void shutdown() { server.shutdown(); try { if (!server.awaitTermination(1, TimeUnit.MINUTES)) { - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat( - GRPC_SERVER_CLOSURE_ERROR, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.GRPC_SERVER_CLOSURE_ERROR); LOG.warn("Timed out while gracefully shutting down net server"); } } catch (InterruptedException e) { diff --git a/src/main/java/org/opensearch/performanceanalyzer/os/SchemaFileParser.java b/src/main/java/org/opensearch/performanceanalyzer/os/SchemaFileParser.java index dcc912103..5bb3ff021 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/os/SchemaFileParser.java +++ b/src/main/java/org/opensearch/performanceanalyzer/os/SchemaFileParser.java @@ -17,8 +17,8 @@ import java.util.Map; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; public class SchemaFileParser { private static final Logger LOGGER = LogManager.getLogger(SchemaFileParser.class); diff --git a/src/main/java/org/opensearch/performanceanalyzer/os/ThreadDiskIO.java b/src/main/java/org/opensearch/performanceanalyzer/os/ThreadDiskIO.java index 276607ffb..62eb5fc0d 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/os/ThreadDiskIO.java +++ b/src/main/java/org/opensearch/performanceanalyzer/os/ThreadDiskIO.java @@ -15,8 +15,8 @@ import java.util.Map; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.metrics_generator.linux.LinuxDiskIOMetricsGenerator; public class ThreadDiskIO { diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/RcaController.java b/src/main/java/org/opensearch/performanceanalyzer/rca/RcaController.java index 41385f782..ab89f813e 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/RcaController.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/RcaController.java @@ -28,20 +28,17 @@ import org.opensearch.performanceanalyzer.AppContext; import org.opensearch.performanceanalyzer.ClientServers; import org.opensearch.performanceanalyzer.PerformanceAnalyzerThreads; +import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.config.PluginSettings; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; -import org.opensearch.performanceanalyzer.commons.util.Util; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; +import org.opensearch.performanceanalyzer.core.Util; import org.opensearch.performanceanalyzer.net.GRPCConnectionManager; import org.opensearch.performanceanalyzer.net.NetClient; import org.opensearch.performanceanalyzer.net.NetServer; import org.opensearch.performanceanalyzer.rca.exceptions.MalformedConfig; -import org.opensearch.performanceanalyzer.rca.framework.core.ConnectedComponent; -import org.opensearch.performanceanalyzer.rca.framework.core.Queryable; -import org.opensearch.performanceanalyzer.rca.framework.core.RcaConf; -import org.opensearch.performanceanalyzer.rca.framework.core.Stats; -import org.opensearch.performanceanalyzer.rca.framework.core.ThresholdMain; +import org.opensearch.performanceanalyzer.rca.framework.core.*; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaRuntimeMetrics; import org.opensearch.performanceanalyzer.rca.framework.util.InstanceDetails; import org.opensearch.performanceanalyzer.rca.framework.util.RcaConsts; @@ -282,8 +279,8 @@ public void stop() { private void restart() { stop(); start(); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - RcaRuntimeMetrics.RCA_SCHEDULER_RESTART, "", 1); + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + RcaRuntimeMetrics.RCA_SCHEDULER_RESTART, 1); } protected RcaConf getRcaConfForMyRole(AllMetrics.NodeRole role) { @@ -318,8 +315,6 @@ public void run() { Thread.sleep(rcaStateCheckIntervalMillis - duration); } } catch (InterruptedException ie) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.RCA_FRAMEWORK_CRASH, "", 1); if (deliberateInterrupt) { // This should only happen in case of tests. So, its okay for this log level to // be info. @@ -327,6 +322,7 @@ public void run() { } else { LOG.error("RCA controller thread was interrupted.", ie); } + StatsCollector.instance().logException(StatExceptionCode.RCA_FRAMEWORK_CRASH); break; } tick++; @@ -426,9 +422,8 @@ private boolean updateMutedComponents() { rcaScheduler.updateAppContextWithMutedActions(actionsForMute); } } catch (Exception e) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.MUTE_ERROR, "", 1); LOG.error("Couldn't read/update the muted RCAs", e); + StatsCollector.instance().logException(StatExceptionCode.MUTE_ERROR); return false; } @@ -464,13 +459,13 @@ private void updateRcaState() { if (!rcaEnabled) { // Need to shutdown the rca scheduler stop(); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - RcaRuntimeMetrics.RCA_STOPPED_BY_OPERATOR, "", 1); + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + RcaRuntimeMetrics.RCA_STOPPED_BY_OPERATOR, 1); } else { if (rcaScheduler.getRole() != currentRole) { restart(); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - RcaRuntimeMetrics.RCA_RESTARTED_BY_OPERATOR, "", 1); + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + RcaRuntimeMetrics.RCA_RESTARTED_BY_OPERATOR, 1); } } } else { diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/RcaControllerHelper.java b/src/main/java/org/opensearch/performanceanalyzer/rca/RcaControllerHelper.java index fb4a32a76..1b522da8f 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/RcaControllerHelper.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/RcaControllerHelper.java @@ -23,7 +23,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.rca.framework.core.RcaConf; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaRuntimeMetrics; import org.opensearch.performanceanalyzer.rca.framework.util.RcaConsts; @@ -73,7 +73,7 @@ public static RcaConf pickRcaConfForRole(final AllMetrics.NodeRole nodeRole) { public static String getElectedClusterManagerHostAddress() { try { LOG.info("Making _cat/cluster_manager call"); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( RcaRuntimeMetrics.OPEN_SEARCH_APIS_CALLED, "catClusterManager", 1); final URL url = new URL(CAT_CLUSTER_MANAGER_URL); diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/formatter/StatsCollectorFormatter.java b/src/main/java/org/opensearch/performanceanalyzer/rca/formatter/StatsCollectorFormatter.java deleted file mode 100644 index c67ea5d2f..000000000 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/formatter/StatsCollectorFormatter.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.performanceanalyzer.rca.formatter; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; -import org.opensearch.performanceanalyzer.commons.formatter.Formatter; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.Statistics; - -public class StatsCollectorFormatter implements Formatter { - StringBuilder formatted; - String sep = ""; - long startTime; - long endTime; - - public StatsCollectorFormatter() { - formatted = new StringBuilder(); - } - - private void format( - MeasurementSet measurementSet, Statistics aggregationType, String name, Number value) { - formatted.append(sep); - formatted.append(measurementSet.getName()).append("=").append(value); - if (!measurementSet.getUnit().isEmpty()) { - formatted.append(" ").append(measurementSet.getUnit()); - } - formatted.append(" ").append("aggr|").append(aggregationType); - if (!name.isEmpty()) { - formatted.append(" ").append("key|").append(name); - } - sep = ","; - } - - @Override - public void formatNamedAggregatedValue( - MeasurementSet measurementSet, Statistics aggregationType, String name, Number value) { - format(measurementSet, aggregationType, name, value); - } - - @Override - public void formatAggregatedValue( - MeasurementSet measurementSet, Statistics aggregationType, Number value) { - format(measurementSet, aggregationType, "", value); - } - - @Override - public void setStartAndEndTime(long start, long end) { - this.startTime = start; - this.endTime = end; - } - - public List getAllMetrics() { - List list = new ArrayList<>(); - StatsCollectorReturn statsCollectorReturn = - new StatsCollectorReturn(this.startTime, this.endTime); - statsCollectorReturn.statsdata.put("Metrics", formatted.toString()); - list.add(statsCollectorReturn); - - return list; - } - - public static class StatsCollectorReturn { - private Map counters; - private Map statsdata; - private Map latencies; - private long startTimeMillis; - private long endTimeMillis; - - public StatsCollectorReturn(long startTimeMillis, long endTimeMillis) { - counters = new HashMap<>(); - statsdata = new HashMap<>(); - latencies = new HashMap<>(); - this.startTimeMillis = startTimeMillis; - this.endTimeMillis = endTimeMillis; - } - - public Map getCounters() { - return counters; - } - - public Map getStatsdata() { - return statsdata; - } - - public Map getLatencies() { - return latencies; - } - - public long getStartTimeMillis() { - return startTimeMillis; - } - - public long getEndTimeMillis() { - return endTimeMillis; - } - - public boolean isEmpty() { - return counters.isEmpty() && statsdata.isEmpty() && latencies.isEmpty(); - } - } -} diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Metric.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Metric.java index a2dd6dd6c..5d456f676 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Metric.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Metric.java @@ -13,12 +13,12 @@ import org.jooq.Result; import org.jooq.exception.DataAccessException; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; import org.opensearch.performanceanalyzer.rca.framework.api.flow_units.MetricFlowUnit; import org.opensearch.performanceanalyzer.rca.framework.core.LeafNode; import org.opensearch.performanceanalyzer.rca.framework.core.Queryable; +import org.opensearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; import org.opensearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; @@ -52,7 +52,7 @@ public MetricFlowUnit gather(Queryable queryable) { try { db = queryable.getMetricsDB(); } catch (Exception e) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_GATHER, name(), 1); // TODO: Emit log/stats that gathering failed. LOG.error("RCA: Caught an exception while getting the DB", e); @@ -70,7 +70,7 @@ public MetricFlowUnit gather(Queryable queryable) { // if RCA is trying to read node stats which are not enabled yet. LOG.warn("Looking for metric {}, when it does not exist.", name); } catch (Exception e) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_GATHER, name(), 1); LOG.error("Metric exception:", e); } @@ -83,7 +83,7 @@ public void generateFlowUnitListFromLocal(FlowUnitOperationArgWrapper args) { long endTime = System.currentTimeMillis(); long duration = endTime - startTime; - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.METRIC_GATHER_CALL, this.name(), duration); setFlowUnits(Collections.singletonList(mfu)); } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/OpenSearchConfigNode.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/OpenSearchConfigNode.java index 69341b8bd..7ee74effd 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/OpenSearchConfigNode.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/OpenSearchConfigNode.java @@ -10,11 +10,11 @@ import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.rca.framework.api.flow_units.NodeConfigFlowUnit; import org.opensearch.performanceanalyzer.rca.framework.core.NonLeafNode; +import org.opensearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; import org.opensearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; @@ -43,14 +43,14 @@ public void generateFlowUnitListFromLocal(FlowUnitOperationArgWrapper args) { result = this.operate(); } catch (Exception ex) { LOG.error("Exception in operate.", ex); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_OPERATE, name(), 1); result = new NodeConfigFlowUnit(System.currentTimeMillis()); } long endTime = System.currentTimeMillis(); long duration = endTime - startTime; - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.GRAPH_NODE_OPERATE_CALL, this.name(), duration); setLocalFlowUnit(result); diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Rca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Rca.java index 5fc78aff4..b1580ccfd 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Rca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Rca.java @@ -8,10 +8,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.rca.framework.api.flow_units.ResourceFlowUnit; import org.opensearch.performanceanalyzer.rca.framework.core.NonLeafNode; +import org.opensearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; import org.opensearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; @@ -38,14 +38,14 @@ public void generateFlowUnitListFromLocal(FlowUnitOperationArgWrapper args) { result = this.operate(); } catch (Exception ex) { LOG.error("Exception in operate.", ex); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_OPERATE, name(), 1); result = (T) T.generic(); } long endTime = System.currentTimeMillis(); long duration = endTime - startTime; - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.GRAPH_NODE_OPERATE_CALL, this.name(), duration); setLocalFlowUnit(result); @@ -68,14 +68,14 @@ public void persistFlowUnit(FlowUnitOperationArgWrapper args) { args.getPersistable().write(this, flowUnit); } catch (Exception ex) { LOG.error("Caught exception while persisting node: {}", args.getNode().name(), ex); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_PERSIST, name(), 1); } } long endTime = System.currentTimeMillis(); long duration = endTime - startTime; - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.RCA_PERSIST_CALL, this.name(), duration); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Symptom.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Symptom.java index 473a6b84e..8b0580754 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Symptom.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/api/Symptom.java @@ -9,10 +9,10 @@ import java.util.Collections; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.rca.framework.api.flow_units.SymptomFlowUnit; import org.opensearch.performanceanalyzer.rca.framework.core.NonLeafNode; +import org.opensearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; import org.opensearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; @@ -31,15 +31,16 @@ public void generateFlowUnitListFromLocal(FlowUnitOperationArgWrapper args) { try { result = this.operate(); } catch (Exception ex) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.EXCEPTION_IN_OPERATE, name(), 1); + LOG.error("[MOCHI]: Key Value is: {}", this.name()); + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ExceptionsAndErrors.EXCEPTION_IN_OPERATE, this.name(), 1); LOG.error("Exception caught during operate", ex); result = SymptomFlowUnit.generic(); } long endTime = System.currentTimeMillis(); long durationMillis = endTime - startTime; - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.GRAPH_NODE_OPERATE_CALL, this.name(), durationMillis); setFlowUnits(Collections.singletonList(result)); diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/core/RcaConf.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/core/RcaConf.java index 2db226801..4005e1c15 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/core/RcaConf.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/core/RcaConf.java @@ -34,8 +34,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.decisionmaker.actions.configs.CacheActionConfig; import org.opensearch.performanceanalyzer.decisionmaker.actions.configs.QueueActionConfig; import org.opensearch.performanceanalyzer.decisionmaker.deciders.configs.DeciderConfig; @@ -276,8 +276,8 @@ public boolean updateAllRcaConfFiles( for (String confFilePath : rcaConfFiles) { updateStatus = updateRcaConf(confFilePath, mutedRcas, mutedDeciders, mutedActions); if (!updateStatus) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.WRITE_UPDATED_RCA_CONF_ERROR, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.WRITE_UPDATED_RCA_CONF_ERROR); LOG.error("Failed to update the conf file at path: {}", confFilePath); break; } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/ExceptionsAndErrors.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/ExceptionsAndErrors.java new file mode 100644 index 000000000..803638cf5 --- /dev/null +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/ExceptionsAndErrors.java @@ -0,0 +1,93 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.performanceanalyzer.rca.framework.metrics; + + +import java.util.Collections; +import java.util.List; +import org.opensearch.performanceanalyzer.commons.stats.eval.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.measurements.MeasurementSet; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatsType; + +/** + * Aggregate metrics across RCA Graph nodes tracking failure in various staged of RCA Graph + * Execution. Only add errors and exceptions which require {@link + * org.opensearch.performanceanalyzer.commons.stats.eval.impl.NamedCounter}. + */ +public enum ExceptionsAndErrors implements MeasurementSet { + + /** Exception thrown in operate() method, implemented by each RCA Graph node */ + EXCEPTION_IN_OPERATE("ExceptionInOperate"), + + /** Exception thrown in compute() method in publisher. */ + EXCEPTION_IN_COMPUTE("ExceptionInCompute"), + + /** When calling the MetricsDB API throws an exception. */ + EXCEPTION_IN_GATHER("ExceptionInGather"), + + /** Exception thrown when persisting action or flowunit when unable to write to DB */ + EXCEPTION_IN_PERSIST("ExceptionInPersist"); + + /** What we want to appear as the metric name. */ + private String name; + + /** + * The unit the measurement is in. This is not used for the statistics calculations but as an + * information that will be dumped with the metrics. + */ + private String unit; + + /** + * The type of the measurement, refer {@link + * org.opensearch.performanceanalyzer.commons.stats.metrics.StatsType} + */ + private StatsType statsType; + + /** + * Multiple statistics can be collected for each measurement like MAX, MIN and MEAN. This is a + * collection of one or more such statistics. + */ + private List statsList; + + ExceptionsAndErrors(String name) { + this( + name, + "namedCount", + StatsType.STATS_DATA, + Collections.singletonList(Statistics.NAMED_COUNTERS)); + } + + ExceptionsAndErrors(String name, String unit, StatsType statType, List stats) { + this.name = name; + this.unit = unit; + this.statsType = statType; + this.statsList = stats; + } + + public String toString() { + return new StringBuilder(name).append("-").append(unit).toString(); + } + + @Override + public List getStatsList() { + return statsList; + } + + @Override + public StatsType getStatsType() { + return statsType; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getUnit() { + return unit; + } +} diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/JvmMetrics.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/JvmMetrics.java index 618a31979..22693cf35 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/JvmMetrics.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/JvmMetrics.java @@ -8,8 +8,9 @@ import java.util.Collections; import java.util.List; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.eval.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.measurements.MeasurementSet; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatsType; public enum JvmMetrics implements MeasurementSet { JVM_FREE_MEM_SAMPLER("JvmFreeMem", "bytes"), @@ -18,10 +19,12 @@ public enum JvmMetrics implements MeasurementSet { private String name; private String unit; + private StatsType statsType; JvmMetrics(String name, String unit) { this.name = name; this.unit = unit; + this.statsType = StatsType.STATS_DATA; } @Override @@ -29,6 +32,11 @@ public List getStatsList() { return Collections.singletonList(Statistics.SAMPLE); } + @Override + public StatsType getStatsType() { + return statsType; + } + @Override public String getName() { return name; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaGraphMetrics.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaGraphMetrics.java index 78a99b042..44d684268 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaGraphMetrics.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaGraphMetrics.java @@ -9,83 +9,101 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.eval.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.measurements.MeasurementSet; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatsType; public enum RcaGraphMetrics implements MeasurementSet { /** Time taken per run of the RCA graph */ GRAPH_EXECUTION_TIME( "RcaGraphExecution", "millis", + StatsType.LATENCIES, Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), /** Measures the time spent in the operate() method of a graph node. */ GRAPH_NODE_OPERATE_CALL( "OperateCall", "millis", + StatsType.LATENCIES, Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), /** Measures the time taken to call gather on metrics */ METRIC_GATHER_CALL( "MetricGatherCall", "millis", + StatsType.LATENCIES, Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), - NUM_GRAPH_NODES("NumGraphNodes", "count", Collections.singletonList(Statistics.SAMPLE)), + NUM_GRAPH_NODES("NumGraphNodes"), - NUM_GRAPH_NODES_MUTED( - "NumOfMutedGraphNodes", "count", Collections.singletonList(Statistics.SAMPLE)), + NUM_GRAPH_NODES_MUTED("NumOfMutedGraphNodes"), - NUM_NODES_EXECUTED_LOCALLY( - "NodesExecutedLocally", "count", Collections.singletonList(Statistics.COUNT)), + NUM_NODES_EXECUTED_LOCALLY("NodesExecutedLocally"), - NUM_NODES_EXECUTED_REMOTELY( - "NodesExecutedRemotely", "count", Collections.singletonList(Statistics.COUNT)), + NUM_NODES_EXECUTED_REMOTELY("NodesExecutedRemotely"), /** Measures number of bytes that was sent out as part of a protobuf message. */ - NET_BYTES_OUT("TotalRcaBytesOutSerialized", "bytes", Collections.singletonList(Statistics.SUM)), + NET_BYTES_OUT( + "TotalRcaBytesOutSerialized", + "bytes", + StatsType.STATS_DATA, + Collections.singletonList(Statistics.NAMED_COUNTERS)), /** Measures number of bytes that was received as part of a protobuf message. */ - NET_BYTES_IN("TotalRcaBytesInSerialized", "bytes", Collections.singletonList(Statistics.SUM)), + NET_BYTES_IN( + "TotalRcaBytesInSerialized", + "bytes", + StatsType.STATS_DATA, + Collections.singletonList(Statistics.NAMED_COUNTERS)), /** RCA Node received an empty Flow Unit */ RCA_RX_EMPTY_FU( "RcaReceivedEmptyFU", "namedCount", + StatsType.STATS_DATA, Collections.singletonList(Statistics.NAMED_COUNTERS)), /** Number of Network Error encountered per node. */ RCA_NETWORK_ERROR( - "RcaNetworkError", "namedCount", Collections.singletonList(Statistics.NAMED_COUNTERS)), + "RcaNetworkError", + "namedCount", + StatsType.STATS_DATA, + Collections.singletonList(Statistics.NAMED_COUNTERS)), /** Measures the time spent in the persistence layer. */ RCA_PERSIST_CALL( "RcaPersistCall", "millis", + StatsType.LATENCIES, Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), /** Number of nodes that are currently publishing flow units to downstream nodes. */ RCA_NODES_FU_PUBLISH_COUNT( "RcaFlowUnitPublishCount", "namedCount", + StatsType.STATS_DATA, Collections.singletonList(Statistics.NAMED_COUNTERS)), /** Number of nodes that are currently receiving flow units from upstream nodes. */ RCA_NODES_FU_CONSUME_COUNT( "RcaFlowUnitConsumeCount", "namedCount", + StatsType.STATS_DATA, Collections.singletonList(Statistics.NAMED_COUNTERS)), /** Number of subscription requests sent per node. */ RCA_NODES_SUB_REQ_COUNT( "RcaSubscriptionRequestCount", "namedCount", + StatsType.STATS_DATA, Collections.singletonList(Statistics.NAMED_COUNTERS)), /** Number of subscriptions acknowledged per node. */ RCA_NODES_SUB_ACK_COUNT( "RcaSubscriptionAckCount", "namedCount", + StatsType.STATS_DATA, Collections.singletonList(Statistics.NAMED_COUNTERS)); /** What we want to appear as the metric name. */ @@ -97,15 +115,23 @@ public enum RcaGraphMetrics implements MeasurementSet { */ private String unit; + /** The type of the measurement, refer {@link StatsType} */ + private StatsType statsType; + /** * Multiple statistics can be collected for each measurement like MAX, MIN and MEAN. This is a * collection of one or more such statistics. */ private List statsList; - RcaGraphMetrics(String name, String unit, List statisticList) { + RcaGraphMetrics(String name) { + this(name, "count", StatsType.STATS_DATA, Collections.singletonList(Statistics.COUNT)); + } + + RcaGraphMetrics(String name, String unit, StatsType statsType, List statisticList) { this.name = name; this.unit = unit; + this.statsType = statsType; this.statsList = statisticList; } @@ -113,6 +139,11 @@ public String toString() { return new StringBuilder(name).append("-").append(unit).toString(); } + @Override + public StatsType getStatsType() { + return statsType; + } + @Override public List getStatsList() { return statsList; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaRuntimeMetrics.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaRuntimeMetrics.java index 435b6ea12..cc7d299d9 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaRuntimeMetrics.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaRuntimeMetrics.java @@ -8,49 +8,57 @@ import java.util.Collections; import java.util.List; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.eval.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.measurements.MeasurementSet; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatsType; +import org.opensearch.performanceanalyzer.rca.RcaController; public enum RcaRuntimeMetrics implements MeasurementSet { - /** - * Tracks scheduler restart issued at {@link - * org.opensearch.performanceanalyzer.rca.RcaController#restart} - */ - RCA_SCHEDULER_RESTART( - "RcaSchedulerRestart", "count", Collections.singletonList(Statistics.COUNT)), + /** Tracks scheduler restart issued at {@link RcaController#restart()} */ + RCA_SCHEDULER_RESTART("RcaSchedulerRestart"), /** The number of times the framework was stopped by the operator. */ - RCA_STOPPED_BY_OPERATOR( - "RcaStoppedByOperator", "count", Collections.singletonList(Statistics.COUNT)), + RCA_STOPPED_BY_OPERATOR("RcaStoppedByOperator"), /** The number of times the framework was restarted by the operator. */ - RCA_RESTARTED_BY_OPERATOR( - "RcaRestartedByOperator", "count", Collections.singletonList(Statistics.COUNT)), + RCA_RESTARTED_BY_OPERATOR("RcaRestartedByOperator"), /** * OpenSearch APIs calls are expensive and we want to keep track of how many we are making. This * is a named counter and therefore we can get a count per OpenSearch API. */ OPEN_SEARCH_APIS_CALLED( - "OpenSearchApisCalled", "count", Collections.singletonList(Statistics.NAMED_COUNTERS)), + "OpenSearchApisCalled", + "namedCount", + StatsType.STATS_DATA, + Collections.singletonList(Statistics.NAMED_COUNTERS)), /** * Metric tracking if RCA is enabled or disabled. We write a 0 if RCA is disabled and 1 if it is * enabled. */ - RCA_ENABLED("RcaEnabled", "count", Collections.singletonList(Statistics.SAMPLE)), + RCA_ENABLED( + "RcaEnabled", + "count", + StatsType.STATS_DATA, + Collections.singletonList(Statistics.SAMPLE)), /** Metric tracking the actions published by the publisher that are persisted in sqlite. */ NO_INCREASE_ACTION_SUGGESTED( - "NoIncreaseAction", "namedCount", Collections.singletonList(Statistics.NAMED_COUNTERS)), + "NoIncreaseAction", + "namedCount", + StatsType.STATS_DATA, + Collections.singletonList(Statistics.NAMED_COUNTERS)), /** Metric tracking the Heap Size increase action published by the publisher. */ - HEAP_SIZE_INCREASE_ACTION_SUGGESTED( - "HeapSizeIncreaseAction", "count", Collections.singletonList(Statistics.COUNT)), + HEAP_SIZE_INCREASE_ACTION_SUGGESTED("HeapSizeIncreaseAction"), /** Metric tracking the actions published by the publisher that are persisted in sqlite. */ ACTIONS_PUBLISHED( - "ActionsPublished", "namedCount", Collections.singletonList(Statistics.NAMED_COUNTERS)); + "ActionsPublished", + "namedCount", + StatsType.STATS_DATA, + Collections.singletonList(Statistics.NAMED_COUNTERS)); /** What we want to appear as the metric name. */ private String name; @@ -61,15 +69,24 @@ public enum RcaRuntimeMetrics implements MeasurementSet { */ private String unit; + /** The type of the measurement, refer {@link StatsType} */ + private StatsType statsType; + /** * Multiple statistics can be collected for each measurement like MAX, MIN and MEAN. This is a * collection of one or more such statistics. */ private List statsList; - RcaRuntimeMetrics(String name, String unit, List statisticList) { + RcaRuntimeMetrics(String name) { + this(name, "count", StatsType.STATS_DATA, Collections.singletonList(Statistics.COUNT)); + } + + RcaRuntimeMetrics( + String name, String unit, StatsType statsType, List statisticList) { this.name = name; this.unit = unit; + this.statsType = statsType; this.statsList = statisticList; } @@ -82,6 +99,11 @@ public List getStatsList() { return statsList; } + @Override + public StatsType getStatsType() { + return statsType; + } + @Override public String getName() { return name; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaVerticesMetrics.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaVerticesMetrics.java index a7901ee37..4d5a1b277 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaVerticesMetrics.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/RcaVerticesMetrics.java @@ -8,45 +8,39 @@ import java.util.Collections; import java.util.List; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.eval.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.measurements.MeasurementSet; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatsType; /** * metrics added by each RCA vertex in RCA graph. All metrics under this category are RCA specific */ public enum RcaVerticesMetrics implements MeasurementSet { - INVALID_OLD_GEN_SIZE("InvalidOldGenSize", "count", Collections.singletonList(Statistics.COUNT)), - - OLD_GEN_RECLAMATION_INEFFECTIVE( - "OldGenReclamationIneffective", "count", Collections.singletonList(Statistics.COUNT)), - - OLD_GEN_CONTENDED("OldGenContended", "count", Collections.singletonList(Statistics.COUNT)), - - OLD_GEN_OVER_OCCUPIED( - "OldGenOverOccupied", "count", Collections.singletonList(Statistics.COUNT)), - - HOT_SHARD_RCA_ERROR("HotShardRcaError", "count", Collections.singletonList(Statistics.COUNT)), - - NUM_YOUNG_GEN_RCA_TRIGGERED( - "YoungGenRcaCount", "count", Collections.singletonList(Statistics.COUNT)), - NUM_OLD_GEN_RCA_TRIGGERED( - "OldGenRcaCount", "count", Collections.singletonList(Statistics.COUNT)), - NUM_HIGH_HEAP_CLUSTER_RCA_TRIGGERED( - "HighHeapClusterRcaCount", "count", Collections.singletonList(Statistics.COUNT)), + INVALID_OLD_GEN_SIZE("InvalidOldGenSize"), + + OLD_GEN_RECLAMATION_INEFFECTIVE("OldGenReclamationIneffective"), + OLD_GEN_CONTENDED("OldGenContended"), + OLD_GEN_OVER_OCCUPIED("OldGenOverOccupied"), + NUM_YOUNG_GEN_RCA_TRIGGERED("YoungGenRcaCount"), + NUM_OLD_GEN_RCA_TRIGGERED("OldGenRcaCount"), + NUM_HIGH_HEAP_CLUSTER_RCA_TRIGGERED("HighHeapClusterRcaCount"), YOUNG_GEN_RCA_NAMED_COUNT( "YoungGenRcaNamedCount", "namedCount", + StatsType.STATS_DATA, Collections.singletonList(Statistics.NAMED_COUNTERS)), - NUM_FIELD_DATA_CACHE_RCA_TRIGGERED( - "FieldDataCacheRcaCount", "count", Collections.singletonList(Statistics.COUNT)), - NUM_SHARD_REQUEST_CACHE_RCA_TRIGGERED( - "ShardRequestCacheCount", "count", Collections.singletonList(Statistics.COUNT)), + NUM_FIELD_DATA_CACHE_RCA_TRIGGERED("FieldDataCacheRcaCount"), + NUM_SHARD_REQUEST_CACHE_RCA_TRIGGERED("ShardRequestCacheCount"), + + HOT_SHARD_RCA_ERROR("HotShardRcaError"), + ADMISSION_CONTROL_RCA_TRIGGERED("AdmissionControlRcaCount"), + CLUSTER_RCA_NAMED_COUNT( "ClusterRcaNamedCount", "namedCount", - Collections.singletonList(Statistics.NAMED_COUNTERS)), - ADMISSION_CONTROL_RCA_TRIGGERED( - "AdmissionControlRcaCount", "count", Collections.singletonList(Statistics.COUNT)); + StatsType.STATS_DATA, + Collections.singletonList(Statistics.NAMED_COUNTERS)); + /** What we want to appear as the metric name. */ private String name; @@ -56,15 +50,24 @@ public enum RcaVerticesMetrics implements MeasurementSet { */ private String unit; + /** The type of the measurement, refer {@link StatsType} */ + private StatsType statsType; + /** * Multiple statistics can be collected for each measurement like MAX, MIN and MEAN. This is a * collection of one or more such statistics. */ private List statsList; - RcaVerticesMetrics(String name, String unit, List statisticList) { + RcaVerticesMetrics(String name) { + this(name, "count", StatsType.STATS_DATA, Collections.singletonList(Statistics.COUNT)); + } + + RcaVerticesMetrics( + String name, String unit, StatsType statType, List statisticList) { this.name = name; this.unit = unit; + this.statsType = statType; this.statsList = statisticList; } @@ -77,6 +80,11 @@ public List getStatsList() { return statsList; } + @Override + public StatsType getStatsType() { + return statsType; + } + @Override public String getName() { return name; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/ReaderMetrics.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/ReaderMetrics.java index 0fee5fe04..2f22de254 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/ReaderMetrics.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/metrics/ReaderMetrics.java @@ -9,135 +9,97 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.eval.Statistics; +import org.opensearch.performanceanalyzer.commons.stats.measurements.MeasurementSet; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatsType; public enum ReaderMetrics implements MeasurementSet { - /** - * We start 6 threads within RCA Agent, details at {@link - * org.opensearch.performanceanalyzer.PerformanceAnalyzerThreads}. Below metrics track count of - * thread started and ended. - * - *

Note: The 'PA' in metricName is confusing, it is meant to imply threads started within RCA - * Agent. - */ - NUM_PA_THREADS_STARTED( - "NumberOfPAThreadsStarted", "namedCount", Collections.singletonList(Statistics.COUNT)), - NUM_PA_THREADS_ENDED( - "NumberOfPAThreadsEnded", "namedCount", Collections.singletonList(Statistics.COUNT)), - - /** - * For each thread defined in {@link - * org.opensearch.performanceanalyzer.PerformanceAnalyzerThreads}, we add a respective - * 'threadExceptionCode' metric. These metrics are emitted in catch block of {@link - * org.opensearch.performanceanalyzer.threads.ThreadProvider#createThreadForRunnable} - */ - READER_THREAD_STOPPED( - "ReaderThreadStopped", "count", Collections.singletonList(Statistics.COUNT)), - ERROR_HANDLER_THREAD_STOPPED( - "ErrorHandlerThreadStopped", "count", Collections.singletonList(Statistics.COUNT)), - GRPC_SERVER_THREAD_STOPPED( - "GRPCServerThreadStopped", "count", Collections.singletonList(Statistics.COUNT)), - WEB_SERVER_THREAD_STOPPED( - "WebServerThreadStopped", "count", Collections.singletonList(Statistics.COUNT)), - RCA_CONTROLLER_THREAD_STOPPED( - "RcaControllerThreadStopped", "count", Collections.singletonList(Statistics.COUNT)), - RCA_SCHEDULER_THREAD_STOPPED( - "RcaSchedulerThreadStopped", "count", Collections.singletonList(Statistics.COUNT)), - /** * Tracks MetricDB related metrics, the size of below metricDB file is factor of events(shard + * cluster traffic) and also the collector functioning. */ METRICSDB_FILE_SIZE( - "MetricsdbFileSize", "bytes", Arrays.asList(Statistics.MAX, Statistics.MEAN)), - METRICSDB_NUM_FILES("MetricsdbNumFiles", "count", Statistics.SAMPLE), - METRICSDB_SIZE_FILES("MetricsdbSizeFiles", "bytes", Statistics.SAMPLE), - METRICSDB_NUM_UNCOMPRESSED_FILES("MetricsdbNumUncompressedFiles", "count", Statistics.SAMPLE), - METRICSDB_SIZE_UNCOMPRESSED_FILES("MetricsdbSizeUncompressedFiles", "bytes", Statistics.SAMPLE), - BATCH_METRICS_ENABLED("BatchMetricsEnabled", "count", Statistics.SAMPLE), - BATCH_METRICS_HTTP_SUCCESS("BatchMetricsHttpSuccess", "count", Statistics.COUNT), + "MetricsdbFileSize", + "bytes", + StatsType.STATS_DATA, + Arrays.asList(Statistics.MAX, Statistics.MEAN)), + METRICSDB_NUM_FILES("MetricsdbNumFiles", "count", StatsType.STATS_DATA, Statistics.SAMPLE), + METRICSDB_SIZE_FILES("MetricsdbSizeFiles", "bytes", StatsType.STATS_DATA, Statistics.SAMPLE), + METRICSDB_NUM_UNCOMPRESSED_FILES( + "MetricsdbNumUncompressedFiles", "count", StatsType.STATS_DATA, Statistics.SAMPLE), + METRICSDB_SIZE_UNCOMPRESSED_FILES( + "MetricsdbSizeUncompressedFiles", "bytes", StatsType.STATS_DATA, Statistics.SAMPLE), + BATCH_METRICS_ENABLED("BatchMetricsEnabled", "count", StatsType.STATS_DATA, Statistics.SAMPLE), + BATCH_METRICS_HTTP_SUCCESS("BatchMetricsHttpSuccess"), BATCH_METRICS_QUERY_PROCESSING_TIME( - "BatchMetricsQueryProcessingTime", - "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + "BatchMetricsQueryProcessingTime", "millis", StatsType.LATENCIES, Statistics.SUM), /** * Tracks time taken by respective emitters and the total time to process and emit event * metrics. */ READER_METRICS_EMIT_TIME( - "ReaderMetricsEmitTime", - "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + "ReaderMetricsEmitTime", "millis", StatsType.LATENCIES, Statistics.SUM), + READER_OS_METRICS_EMIT_TIME( + "ReaderOSMetricsEmitTime", "millis", StatsType.LATENCIES, Statistics.SUM), READER_METRICS_PROCESS_TIME( - "ReaderMetricsProcessTime", - "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + "ReaderMetricsProcessTime", "millis", StatsType.LATENCIES, Statistics.SUM), GC_INFO_EMITTER_EXECUTION_TIME( - "GCInfoEmitterExecutionTime", - "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + "GCInfoEmitterExecutionTime", "millis", StatsType.LATENCIES, Statistics.SUM), WORKLOAD_METRICS_EMITTER_EXECUTION_TIME( - "WorkloadMetricsEmitterExecutionTime", - "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + "WorkloadMetricsEmitterExecutionTime", "millis", StatsType.LATENCIES, Statistics.SUM), THREAD_NAME_METRICS_EMITTER_EXECUTION_TIME( - "ThreadNameMetricsEmitterExecutionTime", - "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + "ThreadNameMetricsEmitterExecutionTime", "millis", StatsType.LATENCIES, Statistics.SUM), AGGREGATED_OS_METRICS_EMITTER_EXECUTION_TIME( "AggregatedOSMetricsEmitterExecutionTime", "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + StatsType.LATENCIES, + Statistics.SUM), SHARD_REQUEST_METRICS_EMITTER_EXECUTION_TIME( "ShardRequestMetricsEmitterExecutionTime", "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + StatsType.LATENCIES, + Statistics.SUM), HTTP_METRICS_EMITTER_EXECUTION_TIME( - "HTTPMetricsEmitterExecutionTime", - "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + "HTTPMetricsEmitterExecutionTime", "millis", StatsType.LATENCIES, Statistics.SUM), ADMISSION_CONTROL_METRICS_EMITTER_EXECUTION_TIME( "AdmissionControlMetricsEmitterExecutionTime", "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + StatsType.LATENCIES, + Statistics.SUM), CLUSTER_MANAGER_EVENT_METRICS_EMITTER_EXECUTION_TIME( "ClusterManagerEventMetricsEmitterExecutionTime", "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + StatsType.LATENCIES, + Statistics.SUM), NODE_METRICS_EMITTER_EXECUTION_TIME( - "NodeMetricsEmitterExecutionTime", - "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + "NodeMetricsEmitterExecutionTime", "millis", StatsType.LATENCIES, Statistics.SUM), SHARD_STATE_EMITTER_EXECUTION_TIME( - "ShardStateEmitterExecutionTime", - "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + "ShardStateEmitterExecutionTime", "millis", StatsType.LATENCIES, Statistics.SUM), CLUSTER_MANAGER_THROTTLING_EMITTER_EXECUTION_TIME( "ClusterManagerThrottlingEmitterExecutionTime", "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + StatsType.LATENCIES, + Statistics.SUM), FAULT_DETECTION_METRICS_EMITTER_EXECUTION_TIME( "FaultDetectionMetricsEmitterExecutionTime", "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.SUM)), + StatsType.LATENCIES, + Statistics.SUM), /** * Tracks transport thread state(WAITING, TIMED-WAITING, BLOCKED) and time. T The last 2 metrics * track time for 60s moving window. */ - BLOCKED_TRANSPORT_THREAD_COUNT("BlockedTransportThreadCount", "count", Statistics.MAX), - WAITED_TRANSPORT_THREAD_COUNT("WaitedTransportThreadCount", "count", Statistics.MAX), - MAX_TRANSPORT_THREAD_BLOCKED_TIME("MaxTransportThreadBlockedTime", "seconds", Statistics.MAX), - MAX_TRANSPORT_THREAD_WAITED_TIME("MaxTransportThreadWaitedTime", "seconds", Statistics.MAX), - - /** - * A blanket exception code for {@link - * org.opensearch.performanceanalyzer.reader.ReaderMetricsProcessor} failures. - */ - OTHER("Other", "count", Collections.singletonList(Statistics.COUNT)); + BLOCKED_TRANSPORT_THREAD_COUNT( + "BlockedTransportThreadCount", "count", StatsType.STATS_DATA, Statistics.MAX), + WAITED_TRANSPORT_THREAD_COUNT( + "WaitedTransportThreadCount", "count", StatsType.STATS_DATA, Statistics.MAX), + MAX_TRANSPORT_THREAD_BLOCKED_TIME( + "MaxTransportThreadBlockedTime", "seconds", StatsType.LATENCIES, Statistics.MAX), + MAX_TRANSPORT_THREAD_WAITED_TIME( + "MaxTransportThreadWaitedTime", "seconds", StatsType.LATENCIES, Statistics.MAX); /** What we want to appear as the metric name. */ private String name; @@ -148,22 +110,30 @@ public enum ReaderMetrics implements MeasurementSet { */ private String unit; + /** The type of the measurement, refer {@link StatsType} */ + private StatsType statsType; + /** * Multiple statistics can be collected for each measurement like MAX, MIN and MEAN. This is a * collection of one or more such statistics. */ private List statsList; - ReaderMetrics(String name, String unit, List stats) { + ReaderMetrics(String name) { + this(name, "count", StatsType.STATS_DATA, Collections.singletonList(Statistics.COUNT)); + } + + ReaderMetrics(String name, String unit, StatsType statType, Statistics stats) { + this(name, unit, statType, Collections.singletonList(stats)); + } + + ReaderMetrics(String name, String unit, StatsType statType, List stats) { this.name = name; this.unit = unit; + this.statsType = statType; this.statsList = stats; } - ReaderMetrics(String name, String unit, Statistics stats) { - this(name, unit, Collections.singletonList(stats)); - } - public String toString() { return new StringBuilder(name).append("-").append(unit).toString(); } @@ -173,6 +143,11 @@ public List getStatsList() { return statsList; } + @Override + public StatsType getStatsType() { + return statsType; + } + @Override public String getName() { return name; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/AllJvmSamplers.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/AllJvmSamplers.java index cb2a94cdb..4abc208e5 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/AllJvmSamplers.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/AllJvmSamplers.java @@ -8,7 +8,7 @@ import java.util.Arrays; import java.util.List; -import org.opensearch.performanceanalyzer.rca.stats.emitters.ISampler; +import org.opensearch.performanceanalyzer.commons.stats.emitters.ISampler; public class AllJvmSamplers { public static List getJvmSamplers() { diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/JvmFreeMem.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/JvmFreeMem.java index b24f0e091..874f90e7b 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/JvmFreeMem.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/JvmFreeMem.java @@ -6,14 +6,14 @@ package org.opensearch.performanceanalyzer.rca.framework.sys; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.collectors.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.emitters.ISampler; import org.opensearch.performanceanalyzer.rca.framework.metrics.JvmMetrics; -import org.opensearch.performanceanalyzer.rca.stats.emitters.ISampler; public class JvmFreeMem implements ISampler { @Override public void sample(SampleAggregator sampleCollector) { sampleCollector.updateStat( - JvmMetrics.JVM_FREE_MEM_SAMPLER, "", Runtime.getRuntime().freeMemory()); + JvmMetrics.JVM_FREE_MEM_SAMPLER, Runtime.getRuntime().freeMemory()); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/JvmTotalMem.java b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/JvmTotalMem.java index 897ce5d3b..1541d487f 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/JvmTotalMem.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/framework/sys/JvmTotalMem.java @@ -6,14 +6,14 @@ package org.opensearch.performanceanalyzer.rca.framework.sys; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.collectors.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.emitters.ISampler; import org.opensearch.performanceanalyzer.rca.framework.metrics.JvmMetrics; -import org.opensearch.performanceanalyzer.rca.stats.emitters.ISampler; public class JvmTotalMem implements ISampler { @Override public void sample(SampleAggregator sampleCollector) { sampleCollector.updateStat( - JvmMetrics.JVM_TOTAL_MEM_SAMPLER, "", Runtime.getRuntime().totalMemory()); + JvmMetrics.JVM_TOTAL_MEM_SAMPLER, Runtime.getRuntime().totalMemory()); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListener.java b/src/main/java/org/opensearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListener.java index f906d69ec..3a2f804c2 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListener.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListener.java @@ -14,16 +14,16 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.IListener; +import org.opensearch.performanceanalyzer.commons.stats.listeners.IListener; +import org.opensearch.performanceanalyzer.commons.stats.measurements.MeasurementSet; import org.opensearch.performanceanalyzer.rca.framework.core.Stats; +import org.opensearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; public class MisbehavingGraphOperateMethodListener implements IListener { private static final Logger LOG = LogManager.getLogger(MisbehavingGraphOperateMethodListener.class); /** - * A map to keep track of the graohNodeName and the number of times it threw an exception in the + * A map to keep track of the graphNodeName and the number of times it threw an exception in the * {@code operate()} method. */ Map map; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/net/ReceivedFlowUnitStore.java b/src/main/java/org/opensearch/performanceanalyzer/rca/net/ReceivedFlowUnitStore.java index 05b8212ee..2dce75d0e 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/net/ReceivedFlowUnitStore.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/net/ReceivedFlowUnitStore.java @@ -15,8 +15,8 @@ import java.util.concurrent.ConcurrentMap; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.rca.framework.util.RcaConsts; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/net/WireHopper.java b/src/main/java/org/opensearch/performanceanalyzer/rca/net/WireHopper.java index 0bfa29089..d874983d6 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/net/WireHopper.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/net/WireHopper.java @@ -16,8 +16,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.net.NetClient; import org.opensearch.performanceanalyzer.rca.framework.core.Node; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/net/handler/PublishRequestHandler.java b/src/main/java/org/opensearch/performanceanalyzer/rca/net/handler/PublishRequestHandler.java index 94a18796b..9fbdbaf45 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/net/handler/PublishRequestHandler.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/net/handler/PublishRequestHandler.java @@ -15,9 +15,9 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.grpc.PublishResponse; import org.opensearch.performanceanalyzer.grpc.PublishResponse.PublishResponseStatus; @@ -103,7 +103,7 @@ public void onNext(FlowUnitMessage flowUnitMessage) { executorService.execute( new FlowUnitRxTask( nodeStateManager, receivedFlowUnitStore, flowUnitMessage)); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.NET_BYTES_IN, flowUnitMessage.getGraphNode(), flowUnitMessage.getSerializedSize()); diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/net/handler/SubscribeServerHandler.java b/src/main/java/org/opensearch/performanceanalyzer/rca/net/handler/SubscribeServerHandler.java index 4b39d24bf..e37589008 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/net/handler/SubscribeServerHandler.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/net/handler/SubscribeServerHandler.java @@ -12,9 +12,9 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.grpc.SubscribeMessage; import org.opensearch.performanceanalyzer.grpc.SubscribeResponse; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; @@ -46,7 +46,7 @@ public void handleSubscriptionRequest( try { executorService.execute( new SubscriptionRxTask(subscriptionManager, subscribeRequest)); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.NET_BYTES_IN, subscribeRequest.getSubscribeMessage().getRequesterGraphNode(), subscribeRequest.getSubscribeMessage().getSerializedSize()); diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/FlowUnitRxTask.java b/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/FlowUnitRxTask.java index 9058fd70e..5b0dae779 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/FlowUnitRxTask.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/FlowUnitRxTask.java @@ -8,7 +8,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; import org.opensearch.performanceanalyzer.rca.framework.util.InstanceDetails; @@ -54,7 +54,7 @@ public void run() { "Dropped a flow unit because the vertex buffer was full for vertex: {}", vertex); } - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.RCA_NODES_FU_CONSUME_COUNT, vertex, 1); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/FlowUnitTxTask.java b/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/FlowUnitTxTask.java index 49b891eae..e4afce8c9 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/FlowUnitTxTask.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/FlowUnitTxTask.java @@ -11,7 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.PublishResponse; import org.opensearch.performanceanalyzer.grpc.PublishResponse.PublishResponseStatus; import org.opensearch.performanceanalyzer.net.NetClient; @@ -85,7 +85,7 @@ public void onNext(final PublishResponse value) { @Override public void onError(final Throwable t) { - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.RCA_NETWORK_ERROR, sourceGraphNode, 1); LOG.error("rca: Encountered an exception at the server: ", t); subscriptionManager.unsubscribeAndTerminateConnection( @@ -98,7 +98,7 @@ public void onCompleted() { LOG.debug("rca: Server closed the data channel!"); } }); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.RCA_NODES_FU_PUBLISH_COUNT, sourceGraphNode, 1); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/SubscriptionRxTask.java b/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/SubscriptionRxTask.java index e0f9088a2..af7543fab 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/SubscriptionRxTask.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/SubscriptionRxTask.java @@ -10,7 +10,7 @@ import java.util.Map; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.SubscribeMessage; import org.opensearch.performanceanalyzer.grpc.SubscribeResponse; import org.opensearch.performanceanalyzer.grpc.SubscribeResponse.SubscriptionStatus; @@ -66,7 +66,7 @@ public void run() { responseStream.onNext( SubscribeResponse.newBuilder().setSubscriptionStatus(subscriptionStatus).build()); responseStream.onCompleted(); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.RCA_NODES_SUB_ACK_COUNT, request.getRequesterGraphNode() + ":" + request.getDestinationGraphNode(), 1); diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/SubscriptionTxTask.java b/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/SubscriptionTxTask.java index d8ca3bacd..c934c4f6f 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/SubscriptionTxTask.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/net/tasks/SubscriptionTxTask.java @@ -11,7 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.SubscribeMessage; import org.opensearch.performanceanalyzer.net.NetClient; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; @@ -73,7 +73,7 @@ protected void sendSubscribeRequest( subscribeMessage, new SubscribeResponseHandler( subscriptionManager, nodeStateManager, remoteHost, destinationVertex)); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.RCA_NODES_SUB_REQ_COUNT, requesterVertex + ":" + destinationVertex, 1); diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/persistence/PublisherEventsPersistor.java b/src/main/java/org/opensearch/performanceanalyzer/rca/persistence/PublisherEventsPersistor.java index 86889347c..e1422c86f 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/persistence/PublisherEventsPersistor.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/persistence/PublisherEventsPersistor.java @@ -11,9 +11,9 @@ import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.decisionmaker.actions.Action; +import org.opensearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaRuntimeMetrics; import org.opensearch.performanceanalyzer.rca.persistence.actions.PersistedAction; @@ -32,7 +32,7 @@ public PublisherEventsPersistor(final Persistable persistable) { public void persistAction(final List actionsPublished, long timestamp) { for (Action action : actionsPublished) { LOG.debug("Action: [{}] published to persistor publisher.", action.name()); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( RcaRuntimeMetrics.ACTIONS_PUBLISHED, action.name(), 1); if (action.impactedNodes() != null) { final String nodeIds = @@ -56,7 +56,7 @@ public void persistAction(final List actionsPublished, long timestamp) { persistable.write(actionsSummary); } catch (Exception e) { LOG.error("Unable to write publisher events to sqlite", e); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_PERSIST, action.name(), 1); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/BatchMetricsEnabledSampler.java b/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/BatchMetricsEnabledSampler.java index 3ac92f806..d2ebbcaab 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/BatchMetricsEnabledSampler.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/BatchMetricsEnabledSampler.java @@ -8,10 +8,10 @@ import java.util.Objects; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.collectors.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.emitters.ISampler; import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; import org.opensearch.performanceanalyzer.rca.framework.util.InstanceDetails; -import org.opensearch.performanceanalyzer.rca.stats.emitters.ISampler; import org.opensearch.performanceanalyzer.reader.ReaderMetricsProcessor; public class BatchMetricsEnabledSampler implements ISampler { @@ -25,7 +25,7 @@ public BatchMetricsEnabledSampler(final AppContext appContext) { @Override public void sample(SampleAggregator sampleCollector) { sampleCollector.updateStat( - ReaderMetrics.BATCH_METRICS_ENABLED, "", isBatchMetricsEnabled() ? 1 : 0); + ReaderMetrics.BATCH_METRICS_ENABLED, isBatchMetricsEnabled() ? 1 : 0); } boolean isBatchMetricsEnabled() { diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/MetricsDBFileSampler.java b/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/MetricsDBFileSampler.java index 890af72eb..3631386a2 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/MetricsDBFileSampler.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/MetricsDBFileSampler.java @@ -17,10 +17,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.collectors.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.emitters.ISampler; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; -import org.opensearch.performanceanalyzer.rca.stats.emitters.ISampler; public class MetricsDBFileSampler implements ISampler { private static final Logger LOG = LogManager.getLogger(MetricsDBFileSampler.class); @@ -84,13 +84,11 @@ public void sample(SampleAggregator sampleCollector) { numMetricsdbFiles += numUncompressedMetricsdbFiles; sizeMetricsdbFiles += sizeUncompressedMetricsdbFiles; - sampleCollector.updateStat(ReaderMetrics.METRICSDB_NUM_FILES, "", numMetricsdbFiles); - sampleCollector.updateStat(ReaderMetrics.METRICSDB_SIZE_FILES, "", sizeMetricsdbFiles); + sampleCollector.updateStat(ReaderMetrics.METRICSDB_NUM_FILES, numMetricsdbFiles); + sampleCollector.updateStat(ReaderMetrics.METRICSDB_SIZE_FILES, sizeMetricsdbFiles); sampleCollector.updateStat( - ReaderMetrics.METRICSDB_NUM_UNCOMPRESSED_FILES, "", numUncompressedMetricsdbFiles); + ReaderMetrics.METRICSDB_NUM_UNCOMPRESSED_FILES, numUncompressedMetricsdbFiles); sampleCollector.updateStat( - ReaderMetrics.METRICSDB_SIZE_UNCOMPRESSED_FILES, - "", - sizeUncompressedMetricsdbFiles); + ReaderMetrics.METRICSDB_SIZE_UNCOMPRESSED_FILES, sizeUncompressedMetricsdbFiles); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/RcaEnabledSampler.java b/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/RcaEnabledSampler.java index 539e50263..fb7d5d4e9 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/RcaEnabledSampler.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/RcaEnabledSampler.java @@ -9,10 +9,10 @@ import java.util.Objects; import org.opensearch.performanceanalyzer.AppContext; import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.collectors.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.emitters.ISampler; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaRuntimeMetrics; import org.opensearch.performanceanalyzer.rca.framework.util.InstanceDetails; -import org.opensearch.performanceanalyzer.rca.stats.emitters.ISampler; public class RcaEnabledSampler implements ISampler { private final AppContext appContext; @@ -24,7 +24,7 @@ public class RcaEnabledSampler implements ISampler { @Override public void sample(SampleAggregator sampleCollector) { - sampleCollector.updateStat(RcaRuntimeMetrics.RCA_ENABLED, "", isRcaEnabled() ? 1 : 0); + sampleCollector.updateStat(RcaRuntimeMetrics.RCA_ENABLED, isRcaEnabled() ? 1 : 0); } boolean isRcaEnabled() { diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/RcaStateSamplers.java b/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/RcaStateSamplers.java index 738ee9c46..710cbf4df 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/RcaStateSamplers.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/samplers/RcaStateSamplers.java @@ -7,7 +7,7 @@ import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.rca.stats.emitters.ISampler; +import org.opensearch.performanceanalyzer.commons.stats.emitters.ISampler; public class RcaStateSamplers { diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/scheduler/GraphNodeOperations.java b/src/main/java/org/opensearch/performanceanalyzer/rca/scheduler/GraphNodeOperations.java index 707a9b582..154ba2c87 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/scheduler/GraphNodeOperations.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/scheduler/GraphNodeOperations.java @@ -8,7 +8,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.rca.framework.core.Stats; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; @@ -22,15 +22,15 @@ static void readFromLocal(FlowUnitOperationArgWrapper args) { } args.getNode().generateFlowUnitListFromLocal(args); args.getNode().persistFlowUnit(args); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( - RcaGraphMetrics.NUM_NODES_EXECUTED_LOCALLY, "", 1); + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + RcaGraphMetrics.NUM_NODES_EXECUTED_LOCALLY, 1); } // This is the abstraction for when the data arrives on the wire from a remote dependency. static void readFromWire(FlowUnitOperationArgWrapper args) { // flowUnits.forEach(i -> LOG.info("rca: Read from wire: {}", i)); args.getNode().generateFlowUnitListFromWire(args); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( - RcaGraphMetrics.NUM_NODES_EXECUTED_REMOTELY, "", 1); + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + RcaGraphMetrics.NUM_NODES_EXECUTED_REMOTELY, 1); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/scheduler/RCASchedulerTask.java b/src/main/java/org/opensearch/performanceanalyzer/rca/scheduler/RCASchedulerTask.java index 420f39bde..f000c369f 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/scheduler/RCASchedulerTask.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/scheduler/RCASchedulerTask.java @@ -20,7 +20,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.collectors.SampleAggregator; import org.opensearch.performanceanalyzer.rca.framework.core.ConnectedComponent; import org.opensearch.performanceanalyzer.rca.framework.core.Node; import org.opensearch.performanceanalyzer.rca.framework.core.Queryable; @@ -375,8 +376,9 @@ public void run() { currTick = currTick + 1; long runStartTime = System.currentTimeMillis(); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( - RcaGraphMetrics.NUM_GRAPH_NODES, "", Stats.getInstance().getTotalNodesCount()); + SampleAggregator test = ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR; + LOG.error("MOCHI: {} ", test); + test.updateStat(RcaGraphMetrics.NUM_GRAPH_NODES, Stats.getInstance().getTotalNodesCount()); changeDbForTasklets(); List> lastLevelTasks = createAsyncTasks(); @@ -432,11 +434,10 @@ protected void postCompletion(long runStartTime) { long runEndTime = System.currentTimeMillis(); long durationMillis = runEndTime - runStartTime; - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( - RcaGraphMetrics.GRAPH_EXECUTION_TIME, "", durationMillis); - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + RcaGraphMetrics.GRAPH_EXECUTION_TIME, durationMillis); + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.NUM_GRAPH_NODES_MUTED, - "", Stats.getInstance().getMutedGraphNodesCount()); } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/stats/README.md b/src/main/java/org/opensearch/performanceanalyzer/rca/stats/README.md deleted file mode 100644 index 358a91876..000000000 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/stats/README.md +++ /dev/null @@ -1,74 +0,0 @@ -# Health of the RCA framework - -The classes in this package help you gather measurements such as latency of executions and -occurrences of events, aggregate them and then report them. - -## Measurements - -Measurements are defined in the `stats/measurements`. They are the quantities we want to measure. -Each measurement has a statistic associated with it - -### Aggregates -They do some calculations on the raw numbers without just reporting them. The supported -statistics are in the `stats/eval/impl`. New aggregates can be written and plugged in without -much effort. Currently supported statistics are: - 1. Count - 1. Max - 1. Min - 1. Mean - 1. NamedCounter - 1. Sample - 1. Sum - -With max and min you can choose to send the value along with a key and then the statistic reports -the max or the min and also the key associated with it. The way we use it here is with -calculating the max and min of latencies for calling the operate on the graph nodes. We pass -the name of the graph as the key to it. Therefore, for each run we get not only the maximum -duration to execute `operate()` across all the nodes, but also the the name name of the node -which took the longest. -One other statistic that deserves special mention is the `NamedCounter` type. This also takes a -key with it and finally it gives the count of occurrences for each key. This can be handy in -cases like exception reporting. Instead of enlisting all the exceptions in the Measurement -beforehand, we just have a few, and we can use the key to specify the cause of it and get a -grouping over the common causes for which the exceptions are thrown. - - -### Samples -These are reported as they were witnessed, the raw numbers. Some of the examples are the JVM free - space or the current number of live threads in the rca system. - -## Emitters - -Emitters emit certain measurements. They can be found in two places - scattered all around the -code to track execution latencies and the occurrence of errors or call to an expensive -OpenSearch API. The second place is the `stats/emitters`. These are fired at every certain -interval. - -## Aggregators - -They collect the emitted metrics and may compute statistics on them if specified in the -measurement definition. - -## Reporter -Reporter asks the Aggregators for the metrics collected so far and generate reports. This is -where the concept of formatters comes in. Reporting is currently handled by `StatsCollector` class. - -### Formatters - -Formatters are classes that implement the `Formatter` interface. This is the language the -reporter and aggregators talk in. When the reporter asks for the metrics, it sends across a -formatter with it. The aggregator uses the formatter to format the measurements. Formatters are -located in `stat/format`. The formatter that comes with the repo might not suit your needs and -therefore, you might choose to write another formatter that formats the measurements in -accordance with your metric backend. - -## Extending the measurements - -If you want to add more measurements, then you can add them to one of the three categories or - even create one of your own. The three categories we have, stores metrics related to: - 1. `RcaGraphMeasurements` : Measurements related to each run of the RCA graph. - 1. `RcaFrameworkMeasurements`: Measurements are concerned with the general workings of the - framework outside of the graph execution. - 1. `ExceptionsAndErrors`: To get a count of the errors and exceptions thrown by the system. - 1. `LivenessMeasurements`: These are the list of system samples that are collected periodically - rather than on occurrence of events. \ No newline at end of file diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/stats/RcaStatsReporter.java b/src/main/java/org/opensearch/performanceanalyzer/rca/stats/RcaStatsReporter.java deleted file mode 100644 index 9acb63b8c..000000000 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/stats/RcaStatsReporter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.performanceanalyzer.rca.stats; - - -import com.google.common.annotations.VisibleForTesting; -import java.util.List; -import org.opensearch.performanceanalyzer.commons.formatter.Formatter; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; - -/** - * This is meant to be the registry for all the stats that are collected by the Rca framework and - * needs to be reported periodically by the {@link - * org.opensearch.performanceanalyzer.commons.collectors.StatsCollector#collectMetrics} - */ -public class RcaStatsReporter { - /** The list of collectors for which a report can be generated. */ - private final List aggregators; - - /** The index of the collector whose measurements will be reported on this iteration. */ - private int idxOfCollectorToReport; - - public RcaStatsReporter(List aggregators) { - this.aggregators = aggregators; - idxOfCollectorToReport = 0; - } - - /** - * The caller is expected to call this method with a {@code new} formatter every time. This is - * not thread-safe. - * - *

Each time this is called, this method sources a measurement type and formats it and sends - * it. - * - * @param formatter The formatter to use to format the measurementSet - * @return true if there are collectors left to be reported or false otherwise. - */ - public boolean getNextReport(Formatter formatter) { - if (aggregators == null || aggregators.isEmpty()) { - return false; - } - - SampleAggregator collector = aggregators.get(idxOfCollectorToReport); - collector.fillValuesAndReset(formatter); - boolean ret = true; - - idxOfCollectorToReport += 1; - - if (idxOfCollectorToReport == aggregators.size()) { - ret = false; - idxOfCollectorToReport = 0; - } - return ret; - } - - @VisibleForTesting - public boolean isMeasurementCollected(MeasurementSet measure) { - for (SampleAggregator aggregator : aggregators) { - if (aggregator.isMeasurementObserved(measure)) { - return true; - } - } - return false; - } -} diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/stats/emitters/ISampler.java b/src/main/java/org/opensearch/performanceanalyzer/rca/stats/emitters/ISampler.java deleted file mode 100644 index 31109616d..000000000 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/stats/emitters/ISampler.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.performanceanalyzer.rca.stats.emitters; - - -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; - -public interface ISampler { - void sample(SampleAggregator sampleCollector); -} diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/stats/emitters/PeriodicSamplers.java b/src/main/java/org/opensearch/performanceanalyzer/rca/stats/emitters/PeriodicSamplers.java deleted file mode 100644 index 9693c2287..000000000 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/stats/emitters/PeriodicSamplers.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.performanceanalyzer.rca.stats.emitters; - - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import java.util.List; -import java.util.concurrent.CancellationException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; - -public class PeriodicSamplers implements Runnable { - private static final Logger LOG = LogManager.getLogger(PeriodicSamplers.class); - private final SampleAggregator aggregator; - private final List allSamplers; - private final ScheduledExecutorService executor; - - ScheduledFuture future; - - public PeriodicSamplers( - SampleAggregator aggregator, List samplers, long freq, TimeUnit timeUnit) { - this.aggregator = aggregator; - this.allSamplers = samplers; - - this.executor = - Executors.newScheduledThreadPool( - 1, new ThreadFactoryBuilder().setNameFormat("resource-sampler-%d").build()); - this.future = this.executor.scheduleAtFixedRate(this, 0, freq, timeUnit); - startExceptionHandlingThread(); - } - - @Override - public void run() { - for (ISampler sampler : allSamplers) { - sampler.sample(aggregator); - } - } - - private void startExceptionHandlingThread() { - new Thread( - () -> { - while (true) { - try { - future.get(); - } catch (CancellationException cex) { - LOG.info("Periodic sampler cancellation requested."); - } catch (Exception ex) { - LOG.error("Resource state poller exception cause:", ex); - } - } - }) - .start(); - } -} diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/collector/NodeConfigClusterCollector.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/collector/NodeConfigClusterCollector.java index c36dfb324..3970fdecb 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/collector/NodeConfigClusterCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/collector/NodeConfigClusterCollector.java @@ -9,12 +9,12 @@ import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.decisionmaker.deciders.EmptyFlowUnit; import org.opensearch.performanceanalyzer.rca.framework.api.flow_units.NodeConfigFlowUnit; import org.opensearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; import org.opensearch.performanceanalyzer.rca.framework.core.NonLeafNode; +import org.opensearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaGraphMetrics; import org.opensearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper; import org.opensearch.performanceanalyzer.rca.store.rca.cluster.NodeKey; @@ -72,12 +72,12 @@ public void generateFlowUnitListFromLocal(FlowUnitOperationArgWrapper args) { this.operate(); } catch (Exception ex) { LOG.error("Collector: Exception in operate", ex); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ServiceMetrics.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_OPERATE, name(), 1); } long duration = System.currentTimeMillis() - startTime; - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.GRAPH_NODE_OPERATE_CALL, this.name(), duration); } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/HighHeapUsageClusterRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/HighHeapUsageClusterRca.java index 2ac814414..883f43c2f 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/HighHeapUsageClusterRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/HighHeapUsageClusterRca.java @@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.ResourceEnum; import org.opensearch.performanceanalyzer.rca.framework.api.Rca; import org.opensearch.performanceanalyzer.rca.framework.api.Resources; @@ -157,8 +157,8 @@ public ResourceFlowUnit operate() { for (HotNodeSummary unhealthyNodeSummary : unhealthyNodeList) { summary.appendNestedSummary(unhealthyNodeSummary); } - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( - RcaVerticesMetrics.NUM_HIGH_HEAP_CLUSTER_RCA_TRIGGERED, "", 1); + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + RcaVerticesMetrics.NUM_HIGH_HEAP_CLUSTER_RCA_TRIGGERED, 1); } else { context = new ResourceContext(Resources.State.HEALTHY); } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/OldGenRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/OldGenRca.java index fe320eb32..fc3558339 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/OldGenRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/OldGenRca.java @@ -13,9 +13,9 @@ import org.jooq.Field; import org.jooq.Record; import org.jooq.Result; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; import org.opensearch.performanceanalyzer.rca.framework.api.Metric; import org.opensearch.performanceanalyzer.rca.framework.api.Rca; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/admissioncontrol/heap/AdmissionControlByMediumHeap.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/admissioncontrol/heap/AdmissionControlByMediumHeap.java index 5e18c9655..68c4f0780 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/admissioncontrol/heap/AdmissionControlByMediumHeap.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/admissioncontrol/heap/AdmissionControlByMediumHeap.java @@ -13,7 +13,7 @@ import java.util.Objects; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.rca.framework.api.contexts.ResourceContext; import org.opensearch.performanceanalyzer.rca.framework.api.flow_units.ResourceFlowUnit; import org.opensearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary; @@ -75,7 +75,7 @@ public ResourceFlowUnit generateFlowUnits(HeapMetric heapMetric) new HotResourceSummary(HEAP_MAX_SIZE, currentThreshold, previousThreshold, 0); nodeSummary.appendNestedSummary(resourceSummary); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( ADMISSION_CONTROL_RCA_TRIGGERED, instanceDetails.getInstanceId().toString(), 1); return new ResourceFlowUnit<>( diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cache/FieldDataCacheRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cache/FieldDataCacheRca.java index 6580050a3..4cfff439f 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cache/FieldDataCacheRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cache/FieldDataCacheRca.java @@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.grpc.Resource; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; @@ -126,7 +126,7 @@ public ResourceFlowUnit operate() { context = new ResourceContext(Resources.State.UNHEALTHY); nodeSummary.appendNestedSummary( cacheEvictionCollector.generateSummary(currTimestamp)); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( RcaVerticesMetrics.NUM_FIELD_DATA_CACHE_RCA_TRIGGERED, instanceDetails.getInstanceId().toString(), 1); @@ -208,7 +208,7 @@ public void collect(final long currTimestamp) { this.getClass().getSimpleName(), consecutivePeriodsToClear); } - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.RCA_RX_EMPTY_FU, this.getClass().getSimpleName(), 1); continue; } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cache/ShardRequestCacheRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cache/ShardRequestCacheRca.java index 73887419c..093213952 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cache/ShardRequestCacheRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cache/ShardRequestCacheRca.java @@ -17,7 +17,7 @@ import org.apache.logging.log4j.Logger; import org.jooq.Record; import org.jooq.Result; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.grpc.Resource; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; @@ -150,7 +150,7 @@ public ResourceFlowUnit operate() { context = new ResourceContext(Resources.State.UNHEALTHY); nodeSummary.appendNestedSummary( cacheEvictionCollector.generateSummary(currTimestamp)); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( RcaVerticesMetrics.NUM_SHARD_REQUEST_CACHE_RCA_TRIGGERED, instanceDetails.getInstanceId().toString(), 1); @@ -231,7 +231,7 @@ public void collect(final long currTimestamp) { this.getClass().getSimpleName(), consecutivePeriodsToClear); } - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.RCA_RX_EMPTY_FU, this.getClass().getSimpleName(), 1); continue; } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cluster/BaseClusterRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cluster/BaseClusterRca.java index 4f2af3703..7d334f5a6 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cluster/BaseClusterRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/cluster/BaseClusterRca.java @@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.rca.framework.api.Rca; import org.opensearch.performanceanalyzer.rca.framework.api.Resources; import org.opensearch.performanceanalyzer.rca.framework.api.contexts.ResourceContext; @@ -162,7 +162,7 @@ private ResourceFlowUnit generateFlowUnit() { for (HotNodeSummary nodeSummary : unhealthyNodeSummaries) { clusterSummary.appendNestedSummary(nodeSummary); } - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( RcaVerticesMetrics.CLUSTER_RCA_NAMED_COUNT, this.getClass().getName(), 1); return new ResourceFlowUnit<>( timestamp, diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hot_node/ThreadMetricsRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hot_node/ThreadMetricsRca.java index 8cbdd5f49..46d950d7a 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hot_node/ThreadMetricsRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hot_node/ThreadMetricsRca.java @@ -18,7 +18,7 @@ import org.jooq.Record; import org.jooq.Result; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; import org.opensearch.performanceanalyzer.rca.framework.api.Metric; @@ -116,28 +116,24 @@ public ResourceFlowUnit operate() { private void publishStats() { threadAnalyses.forEach( analysis -> { - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( analysis.getBlockedThreadCountMetric(), - "", analysis.getBlockedTimeWindow() .getCountExceedingThreshold( HIGH_BLOCKED_TIME_THRESHOLD_IN_SECONDS)); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( analysis.getMaxBlockedTimeMetric(), - "", analysis.getBlockedTimeWindow().getMaxSum()); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( analysis.getWaitedThreadCountMetric(), - "", analysis.getWaitedTimeWindow() .getCountExceedingThreshold( HIGH_BLOCKED_TIME_THRESHOLD_IN_SECONDS)); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( analysis.getMaxWaitedTimeMetric(), - "", analysis.getWaitedTimeWindow().getMaxSum()); }); } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotheap/HighHeapUsageOldGenRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotheap/HighHeapUsageOldGenRca.java index 94bb9868d..f8416260e 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotheap/HighHeapUsageOldGenRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotheap/HighHeapUsageOldGenRca.java @@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.rca.configs.HighHeapUsageOldGenRcaConfig; import org.opensearch.performanceanalyzer.rca.framework.api.Metric; import org.opensearch.performanceanalyzer.rca.framework.api.Resources; @@ -146,8 +146,8 @@ public ResourceFlowUnit operate() { gcEventSlidingWindow.readSum(), currentMinOldGenUsage / maxTotalHeapSize); context = new ResourceContext(Resources.State.UNHEALTHY); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( - RcaVerticesMetrics.NUM_OLD_GEN_RCA_TRIGGERED, "", 1); + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + RcaVerticesMetrics.NUM_OLD_GEN_RCA_TRIGGERED, 1); } else { context = new ResourceContext(Resources.State.HEALTHY); } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotheap/HighHeapUsageYoungGenRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotheap/HighHeapUsageYoungGenRca.java index 8c0a33ed3..1ed9656a4 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotheap/HighHeapUsageYoungGenRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotheap/HighHeapUsageYoungGenRca.java @@ -15,7 +15,7 @@ import org.jooq.Record; import org.jooq.Result; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; import org.opensearch.performanceanalyzer.rca.configs.HighHeapUsageYoungGenRcaConfig; import org.opensearch.performanceanalyzer.rca.framework.api.Metric; @@ -207,7 +207,7 @@ private ResourceFlowUnit computeFlowUnit( getFollowerCheckTimeoutMs(), avgFullGCTime, PROMOTION_RATE_SLIDING_WINDOW_IN_MINS * 60); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( RcaVerticesMetrics.YOUNG_GEN_RCA_NAMED_COUNT, FULL_GC_TIME_TOO_HIGH, 1); } else if (promotionRateTooHigh(avgPromotionRate, this.lowerBoundThreshold)) { // check to see if the value is above lower bound thres @@ -217,7 +217,7 @@ private ResourceFlowUnit computeFlowUnit( promotionRateThreshold * this.lowerBoundThreshold, avgPromotionRate, PROMOTION_RATE_SLIDING_WINDOW_IN_MINS * 60); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( RcaVerticesMetrics.YOUNG_GEN_RCA_NAMED_COUNT, PROMOTION_RATE_TOO_HIGH, 1); } else if (youngGcTimeTooHigh(avgYoungGCTime)) { summary = @@ -226,7 +226,7 @@ private ResourceFlowUnit computeFlowUnit( youngGenGcTimeThreshold, avgYoungGCTime, PROMOTION_RATE_SLIDING_WINDOW_IN_MINS * 60); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( RcaVerticesMetrics.YOUNG_GEN_RCA_NAMED_COUNT, YOUNG_GC_TIME_TOO_HIGH, 1); } else if (prematurePromotionTooHigh(avgGarbagePromoted)) { summary = @@ -235,7 +235,7 @@ private ResourceFlowUnit computeFlowUnit( garbagePromotionPctThreshold, avgGarbagePromoted, PROMOTION_RATE_SLIDING_WINDOW_IN_MINS * 60); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( RcaVerticesMetrics.YOUNG_GEN_RCA_NAMED_COUNT, PREMATURE_PROMOTION_TOO_HIGH, 1); } else { unhealthy = false; @@ -249,8 +249,8 @@ private ResourceFlowUnit computeFlowUnit( avgYoungGCTime, avgGarbagePromoted, avgFullGCTime); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( - RcaVerticesMetrics.NUM_YOUNG_GEN_RCA_TRIGGERED, "", 1); + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + RcaVerticesMetrics.NUM_YOUNG_GEN_RCA_TRIGGERED, 1); } return new ResourceFlowUnit<>(this.clock.millis(), context, summary); diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotshard/HotShardRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotshard/HotShardRca.java index 7a7c2d245..76fd4622d 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotshard/HotShardRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/hotshard/HotShardRca.java @@ -19,7 +19,7 @@ import org.jooq.Record; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics.OSMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.grpc.HotShardSummaryMessage.CriteriaEnum; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; @@ -105,8 +105,8 @@ private void consumeFlowUnit(final MetricFlowUnit metricFlowUnit, OSMetrics metr usageWindow.next(metricType, usage, this.clock.millis()); } } catch (Exception e) { - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( - RcaVerticesMetrics.HOT_SHARD_RCA_ERROR, "", 1); + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + RcaVerticesMetrics.HOT_SHARD_RCA_ERROR, 1); LOG.error( "Failed to parse metric in FlowUnit: {} from {}", record, diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/HighOldGenOccupancyRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/HighOldGenOccupancyRca.java index 92bd4c90b..39d09fbd8 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/HighOldGenOccupancyRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/HighOldGenOccupancyRca.java @@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.rca.configs.HighOldGenOccupancyRcaConfig; import org.opensearch.performanceanalyzer.rca.framework.api.Metric; import org.opensearch.performanceanalyzer.rca.framework.api.Resources; @@ -113,8 +113,8 @@ private ResourceFlowUnit evaluateAndEmit() { averageUtilizationPercentage, (int) rcaEvaluationIntervalInS); if (averageUtilizationPercentage >= heapUtilizationThreshold) { - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( - RcaVerticesMetrics.OLD_GEN_OVER_OCCUPIED, "", 1); + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + RcaVerticesMetrics.OLD_GEN_OVER_OCCUPIED, 1); context = new ResourceContext(Resources.State.UNHEALTHY); } this.previousSummary = summary; @@ -127,8 +127,8 @@ private void addToSlidingWindow() { double maxOldGen = getMaxOldGenSizeOrDefault(Double.MAX_VALUE); if (maxOldGen == 0d) { - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( - RcaVerticesMetrics.INVALID_OLD_GEN_SIZE, "", 1); + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + RcaVerticesMetrics.INVALID_OLD_GEN_SIZE, 1); LOG.info("Max Old Gen capacity cannot be 0. Skipping."); return; } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/OldGenContendedRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/OldGenContendedRca.java index a7bce7258..28f2a8c0a 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/OldGenContendedRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/OldGenContendedRca.java @@ -11,7 +11,7 @@ import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.rca.configs.OldGenContendedRcaConfig; import org.opensearch.performanceanalyzer.rca.framework.api.Rca; @@ -103,8 +103,8 @@ public ResourceFlowUnit operate() { summary.appendNestedSummary(oldGenReclamationFlowUnit.getSummary()); ResourceContext context = new ResourceContext(Resources.State.CONTENDED); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( - RcaVerticesMetrics.OLD_GEN_CONTENDED, "", 1); + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + RcaVerticesMetrics.OLD_GEN_CONTENDED, 1); return new ResourceFlowUnit<>(currTime, context, summary); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/OldGenReclamationRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/OldGenReclamationRca.java index c7c6d4619..23748c579 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/OldGenReclamationRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/jvmsizing/OldGenReclamationRca.java @@ -7,7 +7,7 @@ import java.util.concurrent.TimeUnit; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.rca.framework.api.Metric; import org.opensearch.performanceanalyzer.rca.framework.api.Resources; import org.opensearch.performanceanalyzer.rca.framework.api.aggregators.SlidingWindow; @@ -105,8 +105,8 @@ public ResourceFlowUnit operate() { minOldGenSlidingWindow.readMin(), rcaEvaluationIntervalInS); context = new ResourceContext(Resources.State.UNHEALTHY); - CommonStats.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( - RcaVerticesMetrics.OLD_GEN_RECLAMATION_INEFFECTIVE, "", 1); + ServiceMetrics.RCA_VERTICES_METRICS_AGGREGATOR.updateStat( + RcaVerticesMetrics.OLD_GEN_RECLAMATION_INEFFECTIVE, 1); prevSummary = summary; prevContext = context; return new ResourceFlowUnit<>(currTime, context, summary); diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/threadpool/QueueRejectionRca.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/threadpool/QueueRejectionRca.java index 2926a4d5e..e374db3ab 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/threadpool/QueueRejectionRca.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/rca/threadpool/QueueRejectionRca.java @@ -16,7 +16,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.grpc.FlowUnitMessage; import org.opensearch.performanceanalyzer.grpc.Resource; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; @@ -180,7 +180,7 @@ public void collect(final long currTimestamp) { this.getClass().getSimpleName(), consecutivePeriodsToClear); } - CommonStats.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.RCA_GRAPH_METRICS_AGGREGATOR.updateStat( RcaGraphMetrics.RCA_RX_EMPTY_FU, this.getClass().getSimpleName(), 1); continue; } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/util/MemInfoParser.java b/src/main/java/org/opensearch/performanceanalyzer/rca/util/MemInfoParser.java index d4528af0b..f78a0308e 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/util/MemInfoParser.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/util/MemInfoParser.java @@ -12,8 +12,8 @@ import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; public class MemInfoParser { diff --git a/src/main/java/org/opensearch/performanceanalyzer/reader/FaultDetectionMetricsProcessor.java b/src/main/java/org/opensearch/performanceanalyzer/reader/FaultDetectionMetricsProcessor.java index 53fc1ee44..587b7646b 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/reader/FaultDetectionMetricsProcessor.java +++ b/src/main/java/org/opensearch/performanceanalyzer/reader/FaultDetectionMetricsProcessor.java @@ -13,12 +13,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jooq.BatchBindStep; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.event_process.Event; import org.opensearch.performanceanalyzer.commons.event_process.EventProcessor; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; public class FaultDetectionMetricsProcessor implements EventProcessor { private static final Logger LOG = LogManager.getLogger(FaultDetectionMetricsProcessor.class); diff --git a/src/main/java/org/opensearch/performanceanalyzer/reader/HttpRequestEventProcessor.java b/src/main/java/org/opensearch/performanceanalyzer/reader/HttpRequestEventProcessor.java index 3e49c478c..b5adbecd7 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/reader/HttpRequestEventProcessor.java +++ b/src/main/java/org/opensearch/performanceanalyzer/reader/HttpRequestEventProcessor.java @@ -13,12 +13,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jooq.BatchBindStep; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.event_process.Event; import org.opensearch.performanceanalyzer.commons.event_process.EventProcessor; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; public class HttpRequestEventProcessor implements EventProcessor { diff --git a/src/main/java/org/opensearch/performanceanalyzer/reader/MetricProperties.java b/src/main/java/org/opensearch/performanceanalyzer/reader/MetricProperties.java index 9ea6e2886..d2de20087 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/reader/MetricProperties.java +++ b/src/main/java/org/opensearch/performanceanalyzer/reader/MetricProperties.java @@ -26,13 +26,13 @@ import org.jooq.Field; import org.jooq.impl.DSL; import org.opensearch.performanceanalyzer.DBUtils; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.event_process.Event; import org.opensearch.performanceanalyzer.commons.metrics.MetricDimension; import org.opensearch.performanceanalyzer.commons.metrics.MetricValue; import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.util.JsonConverter; import org.opensearch.performanceanalyzer.util.JsonPathNotFoundException; diff --git a/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java b/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java index 29f372d9d..d209bf7f1 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java +++ b/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java @@ -26,7 +26,7 @@ import org.opensearch.performanceanalyzer.DBUtils; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; import org.opensearch.performanceanalyzer.config.TroubleshootingConfig; import org.opensearch.performanceanalyzer.metricsdb.Dimensions; import org.opensearch.performanceanalyzer.metricsdb.Metric; @@ -291,8 +291,8 @@ public static void emitAggregatedOSMetrics( } mFinalT = System.currentTimeMillis(); LOG.debug("Total time taken for writing resource metrics metricsdb: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.AGGREGATED_OS_METRICS_EMITTER_EXECUTION_TIME, "", mFinalT - mCurrT); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.AGGREGATED_OS_METRICS_EMITTER_EXECUTION_TIME, mFinalT - mCurrT); } /** @@ -460,8 +460,8 @@ public static void emitWorkloadMetrics( } long mFinalT = System.currentTimeMillis(); LOG.debug("Total time taken for writing workload metrics metricsdb: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.WORKLOAD_METRICS_EMITTER_EXECUTION_TIME, "", mFinalT - mCurrT); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.WORKLOAD_METRICS_EMITTER_EXECUTION_TIME, mFinalT - mCurrT); } public static void emitThreadNameMetrics( @@ -500,8 +500,8 @@ public static void emitThreadNameMetrics( long mFinalT = System.currentTimeMillis(); LOG.debug( "Total time taken for writing threadName metrics metricsdb: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.THREAD_NAME_METRICS_EMITTER_EXECUTION_TIME, "", mFinalT - mCurrT); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.THREAD_NAME_METRICS_EMITTER_EXECUTION_TIME, mFinalT - mCurrT); } public static String categorizeThreadName(String threadName, Dimensions dimensions) { @@ -698,8 +698,8 @@ public static void emitHttpMetrics( long mFinalT = System.currentTimeMillis(); LOG.debug("Total time taken for writing http metrics metricsdb: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.HTTP_METRICS_EMITTER_EXECUTION_TIME, "", mFinalT - mCurrT); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.HTTP_METRICS_EMITTER_EXECUTION_TIME, mFinalT - mCurrT); } public static void emitGarbageCollectionInfo( @@ -745,8 +745,8 @@ public static void emitGarbageCollectionInfo( LOG.debug( "Total time taken for writing garbage collection info into metricsDB: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.GC_INFO_EMITTER_EXECUTION_TIME, "", mFinalT - mCurrT); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.GC_INFO_EMITTER_EXECUTION_TIME, mFinalT - mCurrT); } public static void emitAdmissionControlMetrics( @@ -799,10 +799,8 @@ public static void emitAdmissionControlMetrics( LOG.debug( "Total time taken for writing AdmissionControl into metricsDB: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.ADMISSION_CONTROL_METRICS_EMITTER_EXECUTION_TIME, - "", - mFinalT - mCurrT); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.ADMISSION_CONTROL_METRICS_EMITTER_EXECUTION_TIME, mFinalT - mCurrT); } public static void emitClusterManagerEventMetrics( @@ -841,9 +839,8 @@ public static void emitClusterManagerEventMetrics( LOG.debug( "Total time taken for writing cluster_manager event queue metrics metricsdb: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( ReaderMetrics.CLUSTER_MANAGER_EVENT_METRICS_EMITTER_EXECUTION_TIME, - "", mFinalT - mCurrT); } @@ -1089,8 +1086,8 @@ public static void emitNodeMetrics( "Total time taken for writing {} metrics metricsdb: {}", tableName, mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.NODE_METRICS_EMITTER_EXECUTION_TIME, "", mFinalT - mCurrT); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.NODE_METRICS_EMITTER_EXECUTION_TIME, mFinalT - mCurrT); } } @@ -1241,8 +1238,8 @@ public static void emitFaultDetectionMetrics( LOG.debug( "Total time taken for writing fault detection metrics to metricsdb: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.FAULT_DETECTION_METRICS_EMITTER_EXECUTION_TIME, "", mFinalT - mCurrT); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.FAULT_DETECTION_METRICS_EMITTER_EXECUTION_TIME, mFinalT - mCurrT); } public static void emitClusterManagerThrottledTaskMetric( @@ -1260,10 +1257,8 @@ public static void emitClusterManagerThrottledTaskMetric( LOG.debug( "Total time taken for writing cluster_manager throttling metrics metricsdb: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.CLUSTER_MANAGER_THROTTLING_EMITTER_EXECUTION_TIME, - "", - mFinalT - mCurrT); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.CLUSTER_MANAGER_THROTTLING_EMITTER_EXECUTION_TIME, mFinalT - mCurrT); } // TODO: Refactor and remove this out into metric-specific emitter @@ -1437,7 +1432,7 @@ public static void emitShardStateMetric( LOG.debug( "Total time taken for writing shard state event queue metrics metricsdb: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.SHARD_STATE_EMITTER_EXECUTION_TIME, "", mFinalT - mCurrT); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.SHARD_STATE_EMITTER_EXECUTION_TIME, mFinalT - mCurrT); } } diff --git a/src/main/java/org/opensearch/performanceanalyzer/reader/NodeMetricsEventProcessor.java b/src/main/java/org/opensearch/performanceanalyzer/reader/NodeMetricsEventProcessor.java index 610d289da..fac1c23cc 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/reader/NodeMetricsEventProcessor.java +++ b/src/main/java/org/opensearch/performanceanalyzer/reader/NodeMetricsEventProcessor.java @@ -16,14 +16,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jooq.BatchBindStep; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.event_process.Event; import org.opensearch.performanceanalyzer.commons.event_process.EventProcessor; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.util.JsonConverter; import org.opensearch.performanceanalyzer.util.JsonPathNotFoundException; @@ -160,8 +158,7 @@ private boolean processEvent( "Malformed json (%s) ExceptionCode: %s", lines[0], StatExceptionCode.JSON_PARSER_ERROR.toString()), ex); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.JSON_PARSER_ERROR, this.getClass().getSimpleName(), 1); + StatsCollector.instance().logException(StatExceptionCode.JSON_PARSER_ERROR); return false; } catch (IOException ex) { LOG.warn( diff --git a/src/main/java/org/opensearch/performanceanalyzer/reader/ReaderMetricsProcessor.java b/src/main/java/org/opensearch/performanceanalyzer/reader/ReaderMetricsProcessor.java index 41dfbbb64..512c52f6d 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/reader/ReaderMetricsProcessor.java +++ b/src/main/java/org/opensearch/performanceanalyzer/reader/ReaderMetricsProcessor.java @@ -5,8 +5,6 @@ package org.opensearch.performanceanalyzer.reader; -import static org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors.IN_MEMORY_DATABASE_CONN_CLOSURE_ERROR; -import static org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors.METRICS_DB_CLOSURE_ERROR; import com.google.common.annotations.VisibleForTesting; import java.io.File; @@ -35,18 +33,19 @@ import org.jooq.SQLDialect; import org.jooq.impl.DSL; import org.opensearch.performanceanalyzer.AppContext; +import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.config.PluginSettings; import org.opensearch.performanceanalyzer.commons.event_process.EventDispatcher; import org.opensearch.performanceanalyzer.commons.event_process.EventLog; import org.opensearch.performanceanalyzer.commons.event_process.EventLogFileHandler; import org.opensearch.performanceanalyzer.commons.event_process.EventProcessor; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; -import org.opensearch.performanceanalyzer.commons.util.Util; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.config.overrides.ConfigOverridesApplier; +import org.opensearch.performanceanalyzer.core.Util; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; @@ -183,13 +182,13 @@ public void run() { } } } catch (Throwable e) { - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat(ReaderMetrics.OTHER, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.READER_METRICS_PROCESSOR_ERROR); LOG.error( (Supplier) () -> new ParameterizedMessage( - "READER PROCESSOR ERROR. NEEDS DEBUGGING {} ExceptionCode: {}.", - ReaderMetrics.OTHER.toString(), + "READER PROCESSOR ERROR. NEEDS DEBUGGING: {}", e.toString()), e); try { @@ -217,8 +216,8 @@ public void shutdown() { conn.close(); } } catch (Exception e) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - IN_MEMORY_DATABASE_CONN_CLOSURE_ERROR, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.IN_MEMORY_DATABASE_CONN_CLOSURE_ERROR); LOG.error("Unable to close inmemory database connection.", e); } @@ -226,7 +225,7 @@ public void shutdown() { try { db.close(); } catch (Exception e) { - CommonStats.WRITER_METRICS_AGGREGATOR.updateStat(METRICS_DB_CLOSURE_ERROR, "", 1); + StatsCollector.instance().logException(StatExceptionCode.METRICS_DB_CLOSURE_ERROR); LOG.error("Unable to close database - " + db.getDBFilePath(), e); } } @@ -382,8 +381,8 @@ private void emitMetrics(long currWindowStartTime) throws Exception { long mFinalT = System.currentTimeMillis(); LOG.debug("Total time taken for aligning OS Metrics: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.READER_METRICS_EMIT_TIME, "", (double) (mFinalT - mCurrT)); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.READER_OS_METRICS_EMIT_TIME, (double) (mFinalT - mCurrT)); mCurrT = System.currentTimeMillis(); MetricsDB metricsDB = createMetricsDB(prevWindowStartTime); @@ -401,17 +400,15 @@ private void emitMetrics(long currWindowStartTime) throws Exception { metricsDB.commit(); metricsDBMap.put(prevWindowStartTime, metricsDB); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.METRICSDB_FILE_SIZE, - "", - new File(metricsDB.getDBFilePath()).length()); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.METRICSDB_FILE_SIZE, new File(metricsDB.getDBFilePath()).length()); if (batchMetricsEnabled) { batchMetricsDBSet.add(prevWindowStartTime); } mFinalT = System.currentTimeMillis(); LOG.debug("Total time taken for emitting Metrics: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.READER_METRICS_EMIT_TIME, "", (double) (mFinalT - mCurrT)); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.READER_METRICS_EMIT_TIME, (double) (mFinalT - mCurrT)); } private void emitGarbageCollectionInfo(long prevWindowStartTime, MetricsDB metricsDB) @@ -455,9 +452,8 @@ private void emitShardRequestMetrics( LOG.debug("OS METRICS NULL"); } alignedOSSnapHolder.remove(); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( ReaderMetrics.SHARD_REQUEST_METRICS_EMITTER_EXECUTION_TIME, - "", System.currentTimeMillis() - mCurrT); } else { LOG.debug( @@ -726,8 +722,8 @@ is ready so it starts to read that file (go back two windows and } long mFinalT = System.currentTimeMillis(); LOG.debug("Total time taken for processing Metrics: {}", mFinalT - mCurrT); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.READER_METRICS_PROCESS_TIME, "", (double) (mFinalT - mCurrT)); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.READER_METRICS_PROCESS_TIME, (double) (mFinalT - mCurrT)); } /** @@ -989,8 +985,8 @@ private void readBatchMetricsEnabledFromConf() { newValue); } } catch (IOException e) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.BATCH_METRICS_CONFIG_ERROR, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.BATCH_METRICS_CONFIG_ERROR); LOG.error("Error reading file '{}': {}", filePath.toString(), e); batchMetricsEnabled = defaultBatchMetricsEnabled; } diff --git a/src/main/java/org/opensearch/performanceanalyzer/rest/QueryActionRequestHandler.java b/src/main/java/org/opensearch/performanceanalyzer/rest/QueryActionRequestHandler.java index b6d1f5ec6..db171ec1e 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rest/QueryActionRequestHandler.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rest/QueryActionRequestHandler.java @@ -22,7 +22,7 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.Supplier; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.rca.persistence.Persistable; import org.opensearch.performanceanalyzer.rca.persistence.actions.PersistedAction; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rest/QueryBatchRequestHandler.java b/src/main/java/org/opensearch/performanceanalyzer/rest/QueryBatchRequestHandler.java index 8c6d5019c..aa0459ff9 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rest/QueryBatchRequestHandler.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rest/QueryBatchRequestHandler.java @@ -25,9 +25,10 @@ import org.jooq.Record; import org.jooq.Result; import org.jooq.exception.DataAccessException; +import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.config.PluginSettings; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.metrics.MetricsRestUtil; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; import org.opensearch.performanceanalyzer.model.MetricsModel; @@ -199,43 +200,40 @@ public void handle(HttpExchange exchange) throws IOException { endTime, samplingPeriod, DEFAULT_MAX_DATAPOINTS); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( ReaderMetrics.BATCH_METRICS_QUERY_PROCESSING_TIME, - "", System.currentTimeMillis() - processingStartTime); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.BATCH_METRICS_HTTP_SUCCESS, "", 1); + ServiceMetrics.READER_METRICS_AGGREGATOR.updateStat( + ReaderMetrics.BATCH_METRICS_HTTP_SUCCESS, 1); sendResponse(exchange, queryResponse, HttpURLConnection.HTTP_OK); } catch (DataAccessException e) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.READER_METRICSDB_ACCESS_ERRORS, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.READER_METRICSDB_ACCESS_ERRORS); LOG.error( "QueryException {} ExceptionCode: {}.", e, - ExceptionsAndErrors.BATCH_METRICS_HTTP_HOST_ERROR, + StatExceptionCode.BATCH_METRICS_HTTP_HOST_ERROR, e); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.BATCH_METRICS_HTTP_HOST_ERROR, "", 1); + StatsCollector.instance().logException(StatExceptionCode.BATCH_METRICS_HTTP_HOST_ERROR); String response = "{\"error\":\"" + e.toString() + "\"}"; sendResponse(exchange, response, HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (InvalidParameterException e) { LOG.error( "QueryException {} ExceptionCode: {}.", e, - ExceptionsAndErrors.BATCH_METRICS_HTTP_CLIENT_ERROR, + StatExceptionCode.BATCH_METRICS_HTTP_CLIENT_ERROR, e); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.BATCH_METRICS_HTTP_CLIENT_ERROR, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.BATCH_METRICS_HTTP_CLIENT_ERROR); String response = "{\"error\":\"" + e.getMessage() + ".\"}"; sendResponse(exchange, response, HttpURLConnection.HTTP_BAD_REQUEST); } catch (Exception e) { LOG.error( "QueryException {} ExceptionCode: {}.", e, - ExceptionsAndErrors.BATCH_METRICS_HTTP_HOST_ERROR, + StatExceptionCode.BATCH_METRICS_HTTP_HOST_ERROR, e); - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.BATCH_METRICS_HTTP_HOST_ERROR, "", 1); + StatsCollector.instance().logException(StatExceptionCode.BATCH_METRICS_HTTP_HOST_ERROR); String response = "{\"error\":\"" + e.toString() + "\"}"; sendResponse(exchange, response, HttpURLConnection.HTTP_INTERNAL_ERROR); } @@ -261,8 +259,8 @@ private int appendMetrics( if (results != null) { maxDatapoints -= results.size(); if (maxDatapoints <= 0) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.BATCH_METRICS_EXCEEDED_MAX_DATAPOINTS, "", 1); + StatsCollector.instance() + .logException(StatExceptionCode.BATCH_METRICS_EXCEEDED_MAX_DATAPOINTS); throw new InvalidParameterException( String.format( "requested data exceeds the %d datapoints limit", @@ -282,10 +280,10 @@ private int appendMetrics( if (results != null) { maxDatapoints -= results.size(); if (maxDatapoints <= 0) { - CommonStats.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( - ExceptionsAndErrors.BATCH_METRICS_EXCEEDED_MAX_DATAPOINTS, - "", - 1); + StatsCollector.instance() + .logException( + StatExceptionCode + .BATCH_METRICS_EXCEEDED_MAX_DATAPOINTS); throw new InvalidParameterException( String.format( "requested data exceeds the %d datapoints limit", diff --git a/src/main/java/org/opensearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java b/src/main/java/org/opensearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java index 289405856..963fffb4e 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java @@ -26,8 +26,8 @@ import org.jooq.Record; import org.jooq.Result; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.util.Util; import org.opensearch.performanceanalyzer.grpc.MetricsRequest; import org.opensearch.performanceanalyzer.grpc.MetricsResponse; diff --git a/src/main/java/org/opensearch/performanceanalyzer/rest/QueryRcaRequestHandler.java b/src/main/java/org/opensearch/performanceanalyzer/rest/QueryRcaRequestHandler.java index af85b5a74..5bd23c24d 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rest/QueryRcaRequestHandler.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rest/QueryRcaRequestHandler.java @@ -22,8 +22,8 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.Supplier; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.rca.Version; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.metrics.MetricsRestUtil; import org.opensearch.performanceanalyzer.rca.framework.core.Stats; import org.opensearch.performanceanalyzer.rca.framework.util.SQLiteQueryUtils; diff --git a/src/main/java/org/opensearch/performanceanalyzer/threads/ThreadProvider.java b/src/main/java/org/opensearch/performanceanalyzer/threads/ThreadProvider.java index a8acc71db..eb684a7b1 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/threads/ThreadProvider.java +++ b/src/main/java/org/opensearch/performanceanalyzer/threads/ThreadProvider.java @@ -5,14 +5,15 @@ package org.opensearch.performanceanalyzer.threads; +import static org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode.NUM_PA_THREADS_ENDED; +import static org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode.NUM_PA_THREADS_STARTED; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; import org.opensearch.performanceanalyzer.PerformanceAnalyzerThreads; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; -import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; +import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.threads.exceptions.PAThreadException; /** Class that wraps a given runnable in a thread with exception handling capabilities. */ @@ -38,7 +39,7 @@ public Thread createThreadForRunnable( threadName.append("-").append(threadNameAppender); } String threadNameStr = threadName.toString(); - MeasurementSet metric = paThread.getThreadExceptionCode(); + StatExceptionCode metric = paThread.getThreadExceptionCode(); Thread t = new Thread( () -> { @@ -50,28 +51,21 @@ public Thread createThreadForRunnable( PerformanceAnalyzerApp.exceptionQueue.put( new PAThreadException(paThread, innerThrowable)); } catch (InterruptedException e) { - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - metric, "", 1); LOG.error( "Thread was interrupted while waiting to put an exception into the queue. " + "Message: {}", e.getMessage(), e); + StatsCollector.instance().logException(metric); } } - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.NUM_PA_THREADS_ENDED, - ReaderMetrics.NUM_PA_THREADS_ENDED.toString(), - 1); LOG.info("Thread: {} completed.", threadNameStr); + StatsCollector.instance().logException(NUM_PA_THREADS_ENDED); }, threadNameStr); - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat( - ReaderMetrics.NUM_PA_THREADS_STARTED, - ReaderMetrics.NUM_PA_THREADS_STARTED.toString(), - 1); LOG.info("Spun up a thread with name: {}", threadNameStr); + StatsCollector.instance().logException(NUM_PA_THREADS_STARTED); return t; } diff --git a/src/main/java/org/opensearch/performanceanalyzer/threads/exceptions/PAThreadException.java b/src/main/java/org/opensearch/performanceanalyzer/threads/exceptions/PAThreadException.java index 3eae747f5..47a74d26a 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/threads/exceptions/PAThreadException.java +++ b/src/main/java/org/opensearch/performanceanalyzer/threads/exceptions/PAThreadException.java @@ -7,7 +7,7 @@ import org.opensearch.performanceanalyzer.PerformanceAnalyzerThreads; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; /** Exception that is thrown when one of the PA threads run into an unhandled exception. */ public class PAThreadException extends Exception { @@ -33,9 +33,9 @@ public String getPaThreadName() { /** * Gets the counter against which we need to record an error metric. * - * @return The {@link MeasurementSet} enum value that represents the error metric name. + * @return The {@link StatExceptionCode} value that represents the error metric name. */ - public MeasurementSet getExceptionCode() { + public StatExceptionCode getExceptionCode() { return paThread.getThreadExceptionCode(); } diff --git a/src/main/java/org/opensearch/performanceanalyzer/util/FileHelper.java b/src/main/java/org/opensearch/performanceanalyzer/util/FileHelper.java deleted file mode 100644 index 5d1751f5f..000000000 --- a/src/main/java/org/opensearch/performanceanalyzer/util/FileHelper.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.performanceanalyzer.util; - - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; -import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; - -public class FileHelper { - private static final Logger log = LogManager.getLogger(FileHelper.class); - private static boolean jvmSupportMillisecondFileModityTime = true; - private static long SECOND_TO_MILLISECONDS = 1000; - - static { - try { - // Create tmp file and test if we can read millisecond - for (int i = 0; i < 2; i++) { - File tmpFile = File.createTempFile("performanceanalyzer", ".tmp"); - tmpFile.deleteOnExit(); - jvmSupportMillisecondFileModityTime = tmpFile.lastModified() % 1000 != 0; - if (jvmSupportMillisecondFileModityTime) { - break; - } - Thread.sleep(2); - } - } catch (Exception ex) { - log.error("Having issue creating tmp file. Using default value.", ex); - } - log.info("jvmSupportMillisecondFileModityTime: {}", jvmSupportMillisecondFileModityTime); - } - - public static long getLastModified(File file, long startTime, long endTime) { - if (!file.isFile() || jvmSupportMillisecondFileModityTime) { - return file.lastModified(); - } - - if (file.lastModified() < startTime - SECOND_TO_MILLISECONDS - || file.lastModified() > endTime) { - return file.lastModified(); - } - - try (BufferedReader reader = new BufferedReader(new FileReader(file))) { - String line = reader.readLine(); - if (line != null) { - String[] fields = line.split(PerformanceAnalyzerMetrics.sKeyValueDelimitor); - if (fields[0].equals(PerformanceAnalyzerMetrics.METRIC_CURRENT_TIME)) { - return Long.parseLong(fields[1]); - } - } - } catch (Exception ex) { - CommonStats.RCA_RUNTIME_METRICS_AGGREGATOR.updateStat(ReaderMetrics.OTHER, "", 1); - log.debug( - "Having issue to read current time from the content of file. Using file metadata; exception: {} ExceptionCode: {}", - () -> ex, - () -> ReaderMetrics.OTHER.toString()); - } - return file.lastModified(); - } -} diff --git a/src/main/java/org/opensearch/performanceanalyzer/util/JsonConverter.java b/src/main/java/org/opensearch/performanceanalyzer/util/JsonConverter.java index cdbcbf49d..efb871535 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/util/JsonConverter.java +++ b/src/main/java/org/opensearch/performanceanalyzer/util/JsonConverter.java @@ -17,8 +17,8 @@ import java.util.Map; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.performanceanalyzer.commons.collectors.StatExceptionCode; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; public class JsonConverter { private static final ObjectMapper MAPPER = new ObjectMapper(); diff --git a/src/test/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerAppTest.java b/src/test/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerAppTest.java index 84188530e..3d838b1c7 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerAppTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerAppTest.java @@ -8,16 +8,21 @@ import java.util.concurrent.ArrayBlockingQueue; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.opensearch.performanceanalyzer.commons.config.ConfigStatus; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.rca.RcaTestHelper; -import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; import org.opensearch.performanceanalyzer.threads.ThreadProvider; import org.opensearch.performanceanalyzer.threads.exceptions.PAThreadException; public class PerformanceAnalyzerAppTest { + @Before + public void setup() { + System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); + } + @Test public void testMain() { PerformanceAnalyzerApp.main(new String[0]); @@ -29,7 +34,8 @@ public void testInvalidConfigStatusMain() throws InterruptedException { ConfigStatus.INSTANCE.setConfigurationInvalid(); PerformanceAnalyzerApp.main(new String[0]); Assert.assertTrue( - RcaTestHelper.verify(ExceptionsAndErrors.INVALID_CONFIG_RCA_AGENT_STOPPED)); + RcaTestHelper.verifyStatException( + StatExceptionCode.INVALID_CONFIG_RCA_AGENT_STOPPED.toString())); } @Test @@ -39,6 +45,8 @@ public void testStartErrorHandlingThread() throws InterruptedException { final Thread errorHandlingThread = PerformanceAnalyzerApp.startErrorHandlingThread(threadProvider, exceptionQueue); errorHandlingThread.interrupt(); - Assert.assertTrue(RcaTestHelper.verify(ReaderMetrics.ERROR_HANDLER_THREAD_STOPPED)); + Assert.assertTrue( + RcaTestHelper.verifyStatException( + StatExceptionCode.ERROR_HANDLER_THREAD_STOPPED.toString())); } } diff --git a/src/test/java/org/opensearch/performanceanalyzer/collectors/RcaStatsCollectorTest.java b/src/test/java/org/opensearch/performanceanalyzer/collectors/RcaStatsCollectorTest.java index 55c81aa88..fe427db90 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/collectors/RcaStatsCollectorTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/collectors/RcaStatsCollectorTest.java @@ -7,22 +7,21 @@ import java.nio.file.Paths; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; +import java.util.*; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.opensearch.performanceanalyzer.AppContext; import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.emitters.PeriodicSamplers; +import org.opensearch.performanceanalyzer.commons.stats.measurements.MeasurementSet; import org.opensearch.performanceanalyzer.rca.RcaTestHelper; import org.opensearch.performanceanalyzer.rca.framework.api.AnalysisGraph; import org.opensearch.performanceanalyzer.rca.framework.api.Metric; @@ -40,10 +39,10 @@ import org.opensearch.performanceanalyzer.rca.framework.util.RcaUtil; import org.opensearch.performanceanalyzer.rca.scheduler.RCASchedulerTask; import org.opensearch.performanceanalyzer.rca.spec.MetricsDBProviderTestHelper; -import org.opensearch.performanceanalyzer.rca.stats.emitters.PeriodicSamplers; import org.opensearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; public class RcaStatsCollectorTest { + class FaultyAnalysisGraph extends AnalysisGraph { @Override public void construct() { @@ -81,6 +80,11 @@ public SymptomFlowUnit operate() { } } + @Before + public void setup() { + PerformanceAnalyzerApp.initAggregators(); + } + @Test public void rcaGraphMetrics() throws Exception { RcaTestHelper.cleanUpLogs(); @@ -129,7 +133,7 @@ public void rcaGraphMetrics() throws Exception { if (!verify(jvmMetrics1)) { PerformanceAnalyzerApp.PERIODIC_SAMPLERS = new PeriodicSamplers( - CommonStats.PERIODIC_SAMPLE_AGGREGATOR, + ServiceMetrics.PERIODIC_SAMPLE_AGGREGATOR, PerformanceAnalyzerApp.getAllSamplers(appContext), (MetricsConfiguration.CONFIG_MAP.get(StatsCollector.class) .samplingInterval) @@ -147,7 +151,7 @@ private boolean verify(MeasurementSet measurementSet) throws InterruptedExceptio final int MAX_TIME_TO_WAIT_MILLIS = 10_000; int waited_for_millis = 0; while (waited_for_millis++ < MAX_TIME_TO_WAIT_MILLIS) { - if (CommonStats.RCA_STATS_REPORTER.isMeasurementCollected(measurementSet)) { + if (ServiceMetrics.STATS_REPORTER.isMeasurementCollected(measurementSet)) { return true; } Thread.sleep(1); diff --git a/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/CacheHealthDeciderTest.java b/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/CacheHealthDeciderTest.java index f18dc71f6..75a76455a 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/CacheHealthDeciderTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/CacheHealthDeciderTest.java @@ -20,6 +20,7 @@ import org.junit.Before; import org.junit.Test; import org.opensearch.performanceanalyzer.AppContext; +import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; import org.opensearch.performanceanalyzer.decisionmaker.actions.Action; import org.opensearch.performanceanalyzer.grpc.ResourceEnum; @@ -43,6 +44,7 @@ public class CacheHealthDeciderTest { @Before public void setupCluster() throws SQLException, ClassNotFoundException { + PerformanceAnalyzerApp.initAggregators(); final long heapMaxSizeInBytes = 12000 * 1_000_000L; final long fieldDataCacheMaxSizeInBytes = 12000; final long shardRequestCacheMaxSizeInBytes = 12000; diff --git a/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/PublisherTest.java b/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/PublisherTest.java index 178533b77..9b6a518ee 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/PublisherTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/PublisherTest.java @@ -16,6 +16,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; import org.opensearch.performanceanalyzer.decisionmaker.actions.Action; import org.opensearch.performanceanalyzer.decisionmaker.actions.ActionListener; import org.opensearch.performanceanalyzer.decisionmaker.actions.ImpactVector; @@ -47,6 +48,7 @@ public class PublisherTest { @Before public void setup() { MockitoAnnotations.initMocks(this); + PerformanceAnalyzerApp.initAggregators(); publisher = new Publisher(EVAL_INTERVAL_S, collator); publisher.addActionListener(actionListener); List decisionList = Lists.newArrayList(decision); diff --git a/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDeciderTest.java b/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDeciderTest.java index 2515ec48f..688da2c8c 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDeciderTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/decisionmaker/deciders/QueueHealthDeciderTest.java @@ -19,6 +19,7 @@ import org.junit.Before; import org.junit.Test; import org.opensearch.performanceanalyzer.AppContext; +import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; import org.opensearch.performanceanalyzer.decisionmaker.actions.Action; import org.opensearch.performanceanalyzer.grpc.ResourceEnum; @@ -41,6 +42,8 @@ public class QueueHealthDeciderTest { @Before public void setupCluster() { + PerformanceAnalyzerApp.initAggregators(); + ClusterDetailsEventProcessor clusterDetailsEventProcessor = new ClusterDetailsEventProcessor(); ClusterDetailsEventProcessor.NodeDetails node1 = diff --git a/src/test/java/org/opensearch/performanceanalyzer/jvm/ThreadListTest.java b/src/test/java/org/opensearch/performanceanalyzer/jvm/ThreadListTest.java index b68ade241..ff4cea991 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/jvm/ThreadListTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/jvm/ThreadListTest.java @@ -11,14 +11,15 @@ import org.junit.Before; import org.junit.Test; import org.opensearch.performanceanalyzer.OSMetricsGeneratorFactory; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.rca.RcaTestHelper; -// This test only runs in linux systems as the some of the static members of the ThreadList +// This test only runs in linux systems as the some static members of the ThreadList // class are specific to Linux. public class ThreadListTest { @Before public void before() { + System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); org.junit.Assume.assumeNotNull(OSMetricsGeneratorFactory.getInstance()); } @@ -33,7 +34,9 @@ public void testNullThreadInfo() throws InterruptedException { infos[0] = null; ThreadList.parseAllThreadInfos(infos); - Assert.assertTrue(RcaTestHelper.verify(ExceptionsAndErrors.JVM_THREAD_ID_NO_LONGER_EXISTS)); + Assert.assertTrue( + RcaTestHelper.verifyStatException( + StatExceptionCode.JVM_THREAD_ID_NO_LONGER_EXISTS.toString())); if (old_clk_tck != null) { System.setProperty(propertyName, old_clk_tck); } diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/RcaControllerTest.java b/src/test/java/org/opensearch/performanceanalyzer/rca/RcaControllerTest.java index cc47fe566..732f449ef 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/RcaControllerTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/rca/RcaControllerTest.java @@ -39,7 +39,7 @@ import org.opensearch.performanceanalyzer.commons.config.PluginSettings; import org.opensearch.performanceanalyzer.commons.event_process.Event; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; +import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode; import org.opensearch.performanceanalyzer.net.GRPCConnectionManager; import org.opensearch.performanceanalyzer.rca.framework.core.ConnectedComponent; import org.opensearch.performanceanalyzer.rca.framework.core.RcaConf; @@ -68,6 +68,8 @@ public class RcaControllerTest { @Before public void setUp() throws Exception { + System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); + threadProvider = new ThreadProvider(); String cwd = System.getProperty("user.dir"); rcaEnabledFileLoc = Paths.get(cwd, "src", "test", "resources", "rca"); @@ -187,7 +189,9 @@ public void tearDown() throws InterruptedException { @Test public void rcaFrameworkCrash() throws InterruptedException { controllerThread.interrupt(); - Assert.assertTrue(RcaTestHelper.verify(ExceptionsAndErrors.RCA_FRAMEWORK_CRASH)); + Assert.assertTrue( + RcaTestHelper.verifyStatException( + StatExceptionCode.RCA_FRAMEWORK_CRASH.toString())); } @Test diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/RcaTestHelper.java b/src/test/java/org/opensearch/performanceanalyzer/rca/RcaTestHelper.java index 06cc0aa4d..461601966 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/RcaTestHelper.java +++ b/src/test/java/org/opensearch/performanceanalyzer/rca/RcaTestHelper.java @@ -29,10 +29,11 @@ import org.apache.logging.log4j.core.appender.FileAppender; import org.jooq.tools.json.JSONObject; import org.opensearch.performanceanalyzer.AppContext; +import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; import org.opensearch.performanceanalyzer.commons.event_process.Event; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.CommonStats; +import org.opensearch.performanceanalyzer.commons.stats.ServiceMetrics; +import org.opensearch.performanceanalyzer.commons.stats.measurements.MeasurementSet; import org.opensearch.performanceanalyzer.rca.framework.core.ConnectedComponent; import org.opensearch.performanceanalyzer.rca.framework.core.Node; import org.opensearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; @@ -145,7 +146,7 @@ public static AppContext setMyIp(String ip, AllMetrics.NodeRole nodeRole) { nodeDetails.append(separator); nodeDetails.append(overridesTimestamp); nodeDetails.append(separator); - nodeDetails.append(jNode.toString()); + nodeDetails.append(jNode); eventProcessor.processEvent(new Event("", nodeDetails.toString(), 0)); AppContext appContext = new AppContext(); appContext.setClusterDetailsEventProcessor(eventProcessor); @@ -185,7 +186,19 @@ public static boolean verify(MeasurementSet measurementSet) throws InterruptedEx final int MAX_TIME_TO_WAIT_MILLIS = 10_000; int waited_for_millis = 0; while (waited_for_millis++ < MAX_TIME_TO_WAIT_MILLIS) { - if (CommonStats.RCA_STATS_REPORTER.isMeasurementCollected(measurementSet)) { + if (ServiceMetrics.STATS_REPORTER.isMeasurementCollected(measurementSet)) { + return true; + } + Thread.sleep(1); + } + return false; + } + + public static boolean verifyStatException(String exceptionCode) throws InterruptedException { + final int MAX_TIME_TO_WAIT_MILLIS = 10_000; + int waited_for_millis = 0; + while (waited_for_millis++ < MAX_TIME_TO_WAIT_MILLIS) { + if (StatsCollector.instance().getCounters().containsKey(exceptionCode)) { return true; } Thread.sleep(1); diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListenerTest.java b/src/test/java/org/opensearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListenerTest.java index a73b156e8..d0a23865f 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListenerTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/rca/listener/MisbehavingGraphOperateMethodListenerTest.java @@ -16,7 +16,6 @@ import org.junit.Test; import org.opensearch.performanceanalyzer.AppContext; import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.rca.RcaTestHelper; import org.opensearch.performanceanalyzer.rca.framework.api.AnalysisGraph; import org.opensearch.performanceanalyzer.rca.framework.api.Metric; @@ -29,6 +28,7 @@ import org.opensearch.performanceanalyzer.rca.framework.core.ConnectedComponent; import org.opensearch.performanceanalyzer.rca.framework.core.RcaConf; import org.opensearch.performanceanalyzer.rca.framework.core.Stats; +import org.opensearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.rca.framework.util.RcaConsts; import org.opensearch.performanceanalyzer.rca.framework.util.RcaUtil; import org.opensearch.performanceanalyzer.rca.scheduler.RCASchedulerTask; diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/persistence/PublisherEventsPersistorTest.java b/src/test/java/org/opensearch/performanceanalyzer/rca/persistence/PublisherEventsPersistorTest.java index 1886d9ac0..0d1e7707b 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/persistence/PublisherEventsPersistorTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/rca/persistence/PublisherEventsPersistorTest.java @@ -19,6 +19,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; import org.opensearch.performanceanalyzer.decisionmaker.actions.Action; import org.opensearch.performanceanalyzer.decisionmaker.actions.ImpactVector; import org.opensearch.performanceanalyzer.rca.framework.util.InstanceDetails; @@ -35,6 +36,8 @@ public class PublisherEventsPersistorTest { @Before public void init() throws Exception { + PerformanceAnalyzerApp.initAggregators(); + String cwd = System.getProperty("user.dir"); testLocation = Paths.get(cwd, "src", "test", "resources", "tmp", "file_rotate"); Files.createDirectories(testLocation); diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/BatchMetricsEnabledSamplerTest.java b/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/BatchMetricsEnabledSamplerTest.java index 34d6c68f0..06621e4d0 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/BatchMetricsEnabledSamplerTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/BatchMetricsEnabledSamplerTest.java @@ -21,7 +21,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.collectors.SampleAggregator; import org.opensearch.performanceanalyzer.commons.util.Util; import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; import org.opensearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; @@ -108,8 +108,6 @@ public void testSample() { uut.sample(sampleAggregator); verify(sampleAggregator, times(1)) .updateStat( - ReaderMetrics.BATCH_METRICS_ENABLED, - "", - mp.getBatchMetricsEnabled() ? 1 : 0); + ReaderMetrics.BATCH_METRICS_ENABLED, mp.getBatchMetricsEnabled() ? 1 : 0); } } diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/MetricsDBFileSamplerTest.java b/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/MetricsDBFileSamplerTest.java index 4d0d7c47c..e0d4dd123 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/MetricsDBFileSamplerTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/MetricsDBFileSamplerTest.java @@ -21,7 +21,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.opensearch.performanceanalyzer.AppContext; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.collectors.SampleAggregator; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; import org.opensearch.performanceanalyzer.rca.framework.metrics.ReaderMetrics; import org.powermock.core.classloader.annotations.PowerMockIgnore; @@ -111,21 +111,17 @@ public void testSample() throws IOException { verify(sampleAggregator, times(1)) .updateStat( ReaderMetrics.METRICSDB_NUM_FILES, - "", metricsdbFiles.length + metricsdbTarFiles.length); verify(sampleAggregator, times(1)) .updateStat( ReaderMetrics.METRICSDB_SIZE_FILES, - "", metricsdbFiles.length * metricsdbFileSize + metricsdbTarFiles.length * metricsdbTarFileSize); verify(sampleAggregator, times(1)) - .updateStat( - ReaderMetrics.METRICSDB_NUM_UNCOMPRESSED_FILES, "", metricsdbFiles.length); + .updateStat(ReaderMetrics.METRICSDB_NUM_UNCOMPRESSED_FILES, metricsdbFiles.length); verify(sampleAggregator, times(1)) .updateStat( ReaderMetrics.METRICSDB_SIZE_UNCOMPRESSED_FILES, - "", metricsdbFiles.length * metricsdbFileSize); } } diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/RcaEnabledSamplerTest.java b/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/RcaEnabledSamplerTest.java index e79fbfa5c..d7aec0354 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/RcaEnabledSamplerTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/rca/samplers/RcaEnabledSamplerTest.java @@ -17,7 +17,7 @@ import org.mockito.MockitoAnnotations; import org.opensearch.performanceanalyzer.AppContext; import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; +import org.opensearch.performanceanalyzer.commons.stats.collectors.SampleAggregator; import org.opensearch.performanceanalyzer.rca.RcaController; import org.opensearch.performanceanalyzer.rca.framework.metrics.RcaRuntimeMetrics; import org.opensearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; @@ -65,7 +65,6 @@ public void testSample() { verify(sampleAggregator, times(1)) .updateStat( RcaRuntimeMetrics.RCA_ENABLED, - "", PerformanceAnalyzerApp.getRcaController().isRcaEnabled() ? 1 : 0); } } diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/stats/collectors/SampleAggregatorTest.java b/src/test/java/org/opensearch/performanceanalyzer/rca/stats/collectors/SampleAggregatorTest.java deleted file mode 100644 index cfb289c4e..000000000 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/stats/collectors/SampleAggregatorTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.performanceanalyzer.rca.stats.collectors; - - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import org.junit.Assert; -import org.junit.Test; -import org.opensearch.performanceanalyzer.commons.formatter.DefaultFormatter; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; -import org.opensearch.performanceanalyzer.commons.stats.Statistics; -import org.opensearch.performanceanalyzer.commons.stats.impl.IStatistic; -import org.opensearch.performanceanalyzer.commons.stats.vals.AggregateValue; -import org.opensearch.performanceanalyzer.commons.stats.vals.NamedAggregateValue; -import org.opensearch.performanceanalyzer.commons.stats.vals.Value; -import org.opensearch.performanceanalyzer.rca.stats.RcaStatsReporter; -import org.opensearch.performanceanalyzer.rca.stats.emitters.ISampler; -import org.opensearch.performanceanalyzer.rca.stats.emitters.PeriodicSamplers; -import org.opensearch.performanceanalyzer.rca.stats.measurements.MeasurementSetTestHelper; - -public class SampleAggregatorTest { - - private boolean matchList(Collection l1, Collection l2) { - for (Value v1 : l1) { - boolean matched = false; - for (Value v2 : l2) { - if (v1.equals(v2)) { - matched = true; - break; - } - } - if (!matched) { - System.out.println(l1 + "\n" + l2); - return false; - } - } - return true; - } - - private boolean match( - MeasurementSet measurementSet, - Map>> expected, - SampleAggregator aggregator) { - for (IStatistic value : aggregator.getValues(measurementSet)) { - List expectedValue = expected.get(measurementSet).get(value.type()); - if (!matchList(value.get(), expectedValue)) { - System.out.println(value.get() + " does not match \n" + expectedValue); - Assert.fail(); - } - } - return true; - } - - private boolean match( - Map>> m1, - Map>> m2, - Set skipMeasures) { - for (Map.Entry>> entry : m1.entrySet()) { - Map> statisticsListMap = entry.getValue(); - for (Map.Entry> entry1 : statisticsListMap.entrySet()) { - if (skipMeasures.contains(entry.getKey())) { - continue; - } - if (!matchList(entry1.getValue(), m2.get(entry.getKey()).get(entry1.getKey()))) { - return false; - } - } - } - return true; - } - - @Test - public void updateStat() { - SampleAggregator sampleAggregator = new SampleAggregator(MeasurementSetTestHelper.values()); - - ISampler sampler = - sampleCollector -> - sampleCollector.updateStat( - MeasurementSetTestHelper.JVM_FREE_MEM_SAMPLER, - "", - Runtime.getRuntime().freeMemory()); - - PeriodicSamplers periodicSamplers = - new PeriodicSamplers( - sampleAggregator, Collections.singletonList(sampler), 10, TimeUnit.HOURS); - - RcaStatsReporter reporter = - new RcaStatsReporter(Collections.singletonList(sampleAggregator)); - - Map>> expected = new HashMap<>(); - - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT1, "key1", 50L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT1, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT1, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT1, "key2", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT1, "key3", 500L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT1, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT1, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT1, "key1", 200L); - - expected.put(MeasurementSetTestHelper.TEST_MEASUREMENT1, new HashMap<>()); - expected.get(MeasurementSetTestHelper.TEST_MEASUREMENT1) - .put( - Statistics.MAX, - Collections.singletonList( - new NamedAggregateValue(500L, Statistics.MAX, "key3"))); - expected.get(MeasurementSetTestHelper.TEST_MEASUREMENT1) - .put( - Statistics.MIN, - Collections.singletonList( - new NamedAggregateValue(50L, Statistics.MIN, "key1"))); - expected.get(MeasurementSetTestHelper.TEST_MEASUREMENT1) - .put( - Statistics.MEAN, - Collections.singletonList(new AggregateValue(1750.0 / 8, Statistics.MEAN))); - Assert.assertTrue( - match(MeasurementSetTestHelper.TEST_MEASUREMENT1, expected, sampleAggregator)); - - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT2, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT2, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT2, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT2, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT2, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT2, "key1", 200L); - - expected.put(MeasurementSetTestHelper.TEST_MEASUREMENT2, new HashMap<>()); - expected.get(MeasurementSetTestHelper.TEST_MEASUREMENT2) - .put( - Statistics.COUNT, - Collections.singletonList(new AggregateValue(6, Statistics.COUNT))); - Assert.assertTrue( - match(MeasurementSetTestHelper.TEST_MEASUREMENT2, expected, sampleAggregator)); - - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT4, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT4, "key1", 300L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT4, "key1", 100L); - - expected.put(MeasurementSetTestHelper.TEST_MEASUREMENT4, new HashMap<>()); - expected.get(MeasurementSetTestHelper.TEST_MEASUREMENT4) - .put(Statistics.SAMPLE, Collections.singletonList(new Value(100))); - Assert.assertTrue( - match(MeasurementSetTestHelper.TEST_MEASUREMENT4, expected, sampleAggregator)); - - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT5, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT5, "key1", 300L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT5, "key1", 100L); - - expected.put(MeasurementSetTestHelper.TEST_MEASUREMENT5, new HashMap<>()); - expected.get(MeasurementSetTestHelper.TEST_MEASUREMENT5) - .put( - Statistics.SUM, - Collections.singletonList(new AggregateValue(600, Statistics.SUM))); - Assert.assertTrue( - match(MeasurementSetTestHelper.TEST_MEASUREMENT5, expected, sampleAggregator)); - - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT6, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT6, "key2", 300L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT6, "key4", 100L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT6, "key1", 200L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT6, "key2", 300L); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT6, "key3", 100L); - - expected.put(MeasurementSetTestHelper.TEST_MEASUREMENT6, new HashMap<>()); - expected.get(MeasurementSetTestHelper.TEST_MEASUREMENT6) - .put( - Statistics.NAMED_COUNTERS, - Arrays.asList( - new NamedAggregateValue(2, Statistics.NAMED_COUNTERS, "key1"), - new NamedAggregateValue(2, Statistics.NAMED_COUNTERS, "key2"), - new NamedAggregateValue(1, Statistics.NAMED_COUNTERS, "key3"), - new NamedAggregateValue(1, Statistics.NAMED_COUNTERS, "key4"))); - Assert.assertTrue( - match(MeasurementSetTestHelper.TEST_MEASUREMENT6, expected, sampleAggregator)); - - reporter.isMeasurementCollected(MeasurementSetTestHelper.JVM_FREE_MEM_SAMPLER); - - DefaultFormatter defaultFormatter = new DefaultFormatter(); - sampleAggregator.fill(defaultFormatter); - - Set skipList = new HashSet<>(); - skipList.add(MeasurementSetTestHelper.JVM_FREE_MEM_SAMPLER); - Assert.assertTrue(match(defaultFormatter.getFormatted(), expected, skipList)); - - DefaultFormatter defaultFormatter1 = new DefaultFormatter(); - reporter.getNextReport(defaultFormatter1); - if (!match( - defaultFormatter.getFormatted(), - defaultFormatter1.getFormatted(), - new HashSet<>())) { - System.out.println( - defaultFormatter.getFormatted() + "\n" + defaultFormatter1.getFormatted()); - Assert.fail(); - } - } -} diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/stats/eval/impl/NamedCounterTest.java b/src/test/java/org/opensearch/performanceanalyzer/rca/stats/eval/impl/NamedCounterTest.java deleted file mode 100644 index 7bdd84c97..000000000 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/stats/eval/impl/NamedCounterTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.performanceanalyzer.commons.stats.impl; - - -import org.junit.Assert; -import org.junit.Test; -import org.opensearch.performanceanalyzer.commons.stats.vals.NamedAggregateValue; - -public class NamedCounterTest { - - @Test - public void calculate() { - NamedCounter namedCounter = new NamedCounter(); - namedCounter.calculate("x", 20); - namedCounter.calculate("x", 20); - namedCounter.calculate("x", 20); - namedCounter.calculate("y", 20); - namedCounter.calculate("y", 20); - namedCounter.calculate("z", 20); - - for (NamedAggregateValue v : namedCounter.get()) { - if (v.getName().equals("x")) { - Assert.assertEquals(3L, v.getValue()); - } else if (v.getName().equals("y")) { - Assert.assertEquals(2L, v.getValue()); - } else if (v.getName().equals("z")) { - Assert.assertEquals(1L, v.getValue()); - } - } - } - - @Test - public void concurrentCalculate() { - int N = 2000000; - int countOfEach = 5000; - - int differentKeys = N / countOfEach; - String[] arr = new String[N]; - - for (int i = 0; i < differentKeys; i++) { - String name = "x" + i; - for (int j = i; j < N; j += differentKeys) { - arr[j] = name; - } - } - - NamedCounter namedCounter = new NamedCounter(); - Th[] threads = new Th[countOfEach]; - - int thi = 0; - for (int i = 0; i < N; i += differentKeys, thi++) { - threads[thi] = new Th(arr, i, differentKeys, namedCounter); - } - - for (int i = 0; i < thi; i++) { - threads[i].start(); - } - - for (int i = 0; i < thi; i++) { - try { - threads[i].join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - for (NamedAggregateValue value : namedCounter.get()) { - boolean found = false; - for (int i = 0; i < differentKeys; i++) { - String name = "x" + i; - if (name.equals(value.getName())) { - Assert.assertEquals((long) countOfEach, value.getValue()); - found = true; - break; - } - } - Assert.assertTrue(found); - } - } - - class Th extends Thread { - String[] arr; - int start; - int delta; - NamedCounter namedCounter; - - Th(String[] arr, int start, int delta, NamedCounter counter) { - this.arr = arr; - this.start = start; - this.delta = delta; - this.namedCounter = counter; - } - - public void run() { - for (int i = start; i < start + delta; i++) { - namedCounter.calculate(arr[i], 0); - // System.out.println(Thread.currentThread().getId() + ": "+arr[i]); - } - } - } -} diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/stats/listeners/IListenerTest.java b/src/test/java/org/opensearch/performanceanalyzer/rca/stats/listeners/IListenerTest.java deleted file mode 100644 index c6d760b11..000000000 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/stats/listeners/IListenerTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.performanceanalyzer.rca.stats.listeners; - - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Assert; -import org.junit.Test; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.IListener; -import org.opensearch.performanceanalyzer.commons.stats.SampleAggregator; -import org.opensearch.performanceanalyzer.rca.stats.measurements.MeasurementSetTestHelper; - -public class IListenerTest { - class Listener implements IListener { - private AtomicInteger count; - - public Listener() { - count = new AtomicInteger(0); - } - - @Override - public Set getMeasurementsListenedTo() { - Set set = - new HashSet() { - { - this.add(MeasurementSetTestHelper.TEST_MEASUREMENT1); - this.add(MeasurementSetTestHelper.TEST_MEASUREMENT2); - } - }; - return set; - } - - @Override - public void onOccurrence(MeasurementSet measurementSet, Number value, String key) { - count.getAndIncrement(); - } - } - - @Test - public void onOccurrence() { - Listener listener = new Listener(); - SampleAggregator sampleAggregator = - new SampleAggregator( - listener.getMeasurementsListenedTo(), - listener, - MeasurementSetTestHelper.values()); - - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT4, "", 1); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT1, "", 1); - sampleAggregator.updateStat(MeasurementSetTestHelper.TEST_MEASUREMENT2, "", 1); - - Assert.assertEquals(2, listener.count.get()); - } -} diff --git a/src/test/java/org/opensearch/performanceanalyzer/rca/stats/measurements/MeasurementSetTestHelper.java b/src/test/java/org/opensearch/performanceanalyzer/rca/stats/measurements/MeasurementSetTestHelper.java deleted file mode 100644 index fa4210396..000000000 --- a/src/test/java/org/opensearch/performanceanalyzer/rca/stats/measurements/MeasurementSetTestHelper.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.performanceanalyzer.rca.stats.measurements; - - -import java.util.Arrays; -import java.util.List; -import org.opensearch.performanceanalyzer.commons.metrics.MeasurementSet; -import org.opensearch.performanceanalyzer.commons.stats.Statistics; - -public enum MeasurementSetTestHelper implements MeasurementSet { - TEST_MEASUREMENT1( - "TestMeasurement1", - "millis", - Arrays.asList(Statistics.MAX, Statistics.MEAN, Statistics.MIN)), - TEST_MEASUREMENT2("TestMeasurement2", "millis", Arrays.asList(Statistics.COUNT)), - TEST_MEASUREMENT3("TestMeasurement3", "millis", Arrays.asList(Statistics.COUNT)), - TEST_MEASUREMENT4("TestMeasurement4", "millis", Arrays.asList(Statistics.SAMPLE)), - TEST_MEASUREMENT5("TestMeasurement5", "millis", Arrays.asList(Statistics.SUM)), - TEST_MEASUREMENT6("TestMeasurement6", "millis", Arrays.asList(Statistics.NAMED_COUNTERS)), - JVM_FREE_MEM_SAMPLER("jvmFreeMemorySampler", "bytes", Arrays.asList(Statistics.SAMPLE)); - - private String name; - private String unit; - private List statsList; - - MeasurementSetTestHelper(String name, String unit, List statisticList) { - this.name = name; - this.unit = unit; - this.statsList = statisticList; - } - - public String toString() { - return new StringBuilder(name).append("-").append(unit).toString(); - } - - @Override - public List getStatsList() { - return statsList; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getUnit() { - return unit; - } -} diff --git a/src/test/java/org/opensearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java b/src/test/java/org/opensearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java index 54ea56b0a..8e232e289 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java +++ b/src/test/java/org/opensearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java @@ -37,12 +37,10 @@ import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics.ClusterManagerPendingTaskDimension; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics.ClusterManagerPendingValue; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics.MetricName; -import org.opensearch.performanceanalyzer.commons.metrics.ExceptionsAndErrors; import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; -import org.opensearch.performanceanalyzer.commons.util.Util; +import org.opensearch.performanceanalyzer.core.Util; import org.opensearch.performanceanalyzer.metricsdb.MetricsDB; -import org.opensearch.performanceanalyzer.rca.RcaTestHelper; public class ReaderMetricsProcessorTests extends AbstractReaderTests { public String rootLocation; @@ -435,8 +433,6 @@ public void testReadBatchMetricsEnabledFromConf() throws Exception { mp.readBatchMetricsEnabledFromConfShim(); assertTrue( mp.getBatchMetricsEnabled() == ReaderMetricsProcessor.defaultBatchMetricsEnabled); - - assertTrue(RcaTestHelper.verify(ExceptionsAndErrors.BATCH_METRICS_CONFIG_ERROR)); } @Test