From 948b54a7f11820f2e5753036545a190d4b4a554b Mon Sep 17 00:00:00 2001 From: Atharva Sharma <60044988+atharvasharma61@users.noreply.github.com> Date: Tue, 23 Jul 2024 21:10:02 +0530 Subject: [PATCH] [Feature] adds index_uuid as a tag in node stats all shard metrics (#680) * Adds index_uuid as a dimension for node stats col Signed-off-by: Atharva Sharma * updates gauge usage and added index_uuid as tag Signed-off-by: Atharva Sharma * removed incomplete collector Signed-off-by: Atharva Sharma * fixed UTs after gauge changes Signed-off-by: Atharva Sharma * addressed comments Signed-off-by: Atharva Sharma * reverted gauge related changes Signed-off-by: Atharva Sharma --------- Signed-off-by: Atharva Sharma --- ...RTFNodeStatsAllShardsMetricsCollector.java | 30 +++++++++++-------- ...deStatsAllShardsMetricsCollectorTests.java | 4 +-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFNodeStatsAllShardsMetricsCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFNodeStatsAllShardsMetricsCollector.java index 63033dba..6b32b3c5 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFNodeStatsAllShardsMetricsCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFNodeStatsAllShardsMetricsCollector.java @@ -143,8 +143,7 @@ configOverridesWrapper, getCollectorName())) { // Populating value for the first run. recordMetrics( new NodeStatsMetricsAllShardsPerCollectionStatus(currentShardStats), - shardId.getIndexName(), - String.valueOf(shardId.id())); + shardId); continue; } ShardStats prevShardStats = prevPerShardStats.get(shardId); @@ -153,15 +152,14 @@ configOverridesWrapper, getCollectorName())) { // run. recordMetrics( new NodeStatsMetricsAllShardsPerCollectionStatus(currentShardStats), - shardId.getIndexName(), - String.valueOf(shardId.id())); + shardId); continue; } NodeStatsMetricsAllShardsPerCollectionStatus prevValue = new NodeStatsMetricsAllShardsPerCollectionStatus(prevShardStats); NodeStatsMetricsAllShardsPerCollectionStatus currValue = new NodeStatsMetricsAllShardsPerCollectionStatus(currentShardStats); - populateDiffMetricValue(prevValue, currValue, shardId.getIndexName(), shardId.id()); + populateDiffMetricValue(prevValue, currValue, shardId); } } @@ -243,13 +241,20 @@ public void populatePerShardStats(IndicesService indicesService) { } private void recordMetrics( - NodeStatsMetricsAllShardsPerCollectionStatus metrics, - String indexName, - String shardId) { + NodeStatsMetricsAllShardsPerCollectionStatus metrics, ShardId shardId) { Tags nodeStatsMetricsTag = Tags.create() - .addTag(RTFMetrics.CommonDimension.INDEX_NAME.toString(), indexName) - .addTag(RTFMetrics.CommonDimension.SHARD_ID.toString(), shardId); + .addTag( + RTFMetrics.CommonDimension.INDEX_NAME.toString(), + shardId.getIndexName()) + .addTag( + RTFMetrics.CommonDimension.SHARD_ID.toString(), + String.valueOf(shardId.getId())); + + if (shardId.getIndex() != null) { + nodeStatsMetricsTag.addTag( + RTFMetrics.CommonDimension.INDEX_UUID.toString(), shardId.getIndex().getUUID()); + } cacheQueryMissMetrics.add(metrics.getQueryCacheMissCount(), nodeStatsMetricsTag); cacheQuerySizeMetrics.add(metrics.getQueryCacheInBytes(), nodeStatsMetricsTag); @@ -267,8 +272,7 @@ private void recordMetrics( public void populateDiffMetricValue( NodeStatsMetricsAllShardsPerCollectionStatus prevValue, NodeStatsMetricsAllShardsPerCollectionStatus currValue, - String indexName, - int shardId) { + ShardId shardId) { NodeStatsMetricsAllShardsPerCollectionStatus metrics = new NodeStatsMetricsAllShardsPerCollectionStatus( @@ -289,7 +293,7 @@ public void populateDiffMetricValue( 0), currValue.requestCacheInBytes); - recordMetrics(metrics, indexName, String.valueOf(shardId)); + recordMetrics(metrics, shardId); } public static class NodeStatsMetricsAllShardsPerCollectionStatus extends MetricStatus { diff --git a/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFNodeStatsAllShardsMetricsCollectorTests.java b/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFNodeStatsAllShardsMetricsCollectorTests.java index 089a685b..918c766a 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFNodeStatsAllShardsMetricsCollectorTests.java +++ b/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFNodeStatsAllShardsMetricsCollectorTests.java @@ -120,11 +120,11 @@ public void testCollectMetrics() throws IOException { createIndex(TEST_INDEX); rtfNodeStatsAllShardsMetricsCollector.collectMetrics(startTimeInMills); verify(rtfNodeStatsAllShardsMetricsCollector, never()) - .populateDiffMetricValue(any(), any(), anyString(), anyInt()); + .populateDiffMetricValue(any(), any(), any()); startTimeInMills += 500; rtfNodeStatsAllShardsMetricsCollector.collectMetrics(startTimeInMills); verify(rtfNodeStatsAllShardsMetricsCollector, times(1)) - .populateDiffMetricValue(any(), any(), anyString(), anyInt()); + .populateDiffMetricValue(any(), any(), any()); verify(cacheFieldDataEvictionCounter, atLeastOnce()).add(anyDouble(), any()); verify(cacheFieldDataSizeCounter, atLeastOnce()).add(anyDouble(), any()); verify(cacheQueryMissCounter, atLeastOnce()).add(anyDouble(), any());