From 43ed34293dcbb2bf5660de282893a01d2cd63459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dharmesh=20=F0=9F=92=A4?= Date: Wed, 3 Mar 2021 00:26:26 +0530 Subject: [PATCH] Added metrics publishing logic --- .../ShardIndexingPressureMetricsCollector.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ShardIndexingPressureMetricsCollector.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ShardIndexingPressureMetricsCollector.java index 6528a9f6..a8833314 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ShardIndexingPressureMetricsCollector.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ShardIndexingPressureMetricsCollector.java @@ -16,6 +16,7 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors; import com.amazon.opendistro.elasticsearch.performanceanalyzer.ESResources; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.PerformanceAnalyzerController; import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.overrides.ConfigOverridesWrapper; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics; @@ -24,6 +25,8 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.MetricsConfiguration; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.MetricsProcessor; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.PerformanceAnalyzerMetrics; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.metrics.ExceptionsAndErrors; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.metrics.WriterMetrics; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -76,6 +79,7 @@ public void collectMetrics(long startTime) { return; } + long mCurrT = System.currentTimeMillis(); try { ClusterService clusterService = ESResources.INSTANCE.getClusterService(); if (clusterService != null) { @@ -124,11 +128,18 @@ public void collectMetrics(long startTime) { }); } } - } catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException e) { - LOG.debug("Exception raised. Skipping IndexingPressureMetricsCollector"); + if(value.length() != 0) { + saveMetricValues(value.toString(), startTime); + PerformanceAnalyzerApp.WRITER_METRICS_AGGREGATOR.updateStat( + WriterMetrics.SHARD_INDEXING_PRESSURE_COLLECTOR_EXECUTION_TIME, "", + System.currentTimeMillis() - mCurrT); + } + } catch (Exception ex) { + PerformanceAnalyzerApp.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( + ExceptionsAndErrors.SHARD_INDEXING_PRESSURE_COLLECTOR_ERROR, "", 1); + LOG.debug("Exception in Collecting Shard Indexing Pressure Metrics: {} for startTime {}", () -> ex.toString(), () -> startTime); } - saveMetricValues(value.toString(), startTime); } Field getField(String className, String fieldName) throws NoSuchFieldException, ClassNotFoundException {