Skip to content

Commit

Permalink
changed metric type to gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
atharvasharma61 committed Sep 2, 2024
1 parent 1569ce1 commit e9252fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@
import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode;
import org.opensearch.performanceanalyzer.commons.stats.metrics.StatMetrics;
import org.opensearch.performanceanalyzer.config.PerformanceAnalyzerController;
import org.opensearch.telemetry.metrics.Histogram;
import org.opensearch.telemetry.metrics.MetricsRegistry;
import org.opensearch.telemetry.metrics.tags.Tags;

public class RTFCacheConfigMetricsCollector extends PerformanceAnalyzerMetricsCollector
implements TelemetryCollector {
private MetricsRegistry metricsRegistry;
private boolean metricsInitialised;
private Histogram cacheMaxSizeMetrics;
private static final Logger LOG = LogManager.getLogger(RTFCacheConfigMetricsCollector.class);
private PerformanceAnalyzerController performanceAnalyzerController;
private ConfigOverridesWrapper configOverridesWrapper;
Expand All @@ -51,7 +48,6 @@ public RTFCacheConfigMetricsCollector(
"RTFCacheConfigMetricsCollector",
StatMetrics.RTF_CACHE_CONFIG_METRICS_COLLECTOR_EXECUTION_TIME,
StatExceptionCode.RTF_CACHE_CONFIG_METRICS_COLLECTOR_ERROR);
this.metricsInitialised = false;
this.performanceAnalyzerController = performanceAnalyzerController;
this.configOverridesWrapper = configOverridesWrapper;
}
Expand All @@ -77,7 +73,6 @@ configOverridesWrapper, getCollectorName())) {
}

LOG.debug("Executing collect metrics for RTFCacheConfigMetricsCollector");
initialiseMetricsIfNeeded();
CacheMaxSizeStatus fieldDataCacheMaxSizeStatus =
AccessController.doPrivileged(
(PrivilegedAction<CacheMaxSizeStatus>)
Expand Down Expand Up @@ -152,25 +147,17 @@ configOverridesWrapper, getCollectorName())) {
}

private void recordMetrics(CacheMaxSizeStatus cacheMaxSizeStatus) {
cacheMaxSizeMetrics.record(
cacheMaxSizeStatus.getCacheMaxSize(),
metricsRegistry.createGauge(
RTFMetrics.CacheConfigValue.Constants.CACHE_MAX_SIZE_VALUE,
"Cache Max Size metrics",
RTFMetrics.MetricUnits.BYTE.toString(),
() -> (double) cacheMaxSizeStatus.getCacheMaxSize(),
Tags.create()
.addTag(
RTFMetrics.CacheConfigDimension.Constants.TYPE_VALUE,
cacheMaxSizeStatus.getCacheType()));
}

private void initialiseMetricsIfNeeded() {
if (metricsInitialised == false) {
cacheMaxSizeMetrics =
metricsRegistry.createHistogram(
RTFMetrics.CacheConfigValue.Constants.CACHE_MAX_SIZE_VALUE,
"CacheMaxSizeMetrics",
RTFMetrics.MetricUnits.BYTE.toString());
metricsInitialised = true;
}
}

static class CacheMaxSizeStatus extends MetricStatus {

private final String cacheType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public static void configureMetrics() {
MetricsConfiguration.CONFIG_MAP.put(RTFHeapMetricsCollector.class, cdefault);
MetricsConfiguration.CONFIG_MAP.put(RTFNodeStatsAllShardsMetricsCollector.class, cdefault);
MetricsConfiguration.CONFIG_MAP.put(RTFThreadPoolMetricsCollector.class, cdefault);
MetricsConfiguration.CONFIG_MAP.put(RTFCacheConfigMetricsCollector.class, cdefault);
MetricsConfiguration.CONFIG_MAP.put(
RTFCacheConfigMetricsCollector.class,
new MetricsConfiguration.MetricConfig(60000, 0));
}

// These methods are utility functions for the Node Stat Metrics Collectors. These methods are
Expand Down

0 comments on commit e9252fb

Please sign in to comment.