From 5db102d22d4ca66a73c2203c3424410599b4d06a Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Thu, 15 Jul 2021 10:11:42 -0600 Subject: [PATCH] Add null check for shard stats to data tier telemetry (#75185) This adds a null check, as `getShardStats(index)` may return null. Co-authored-by: Elastic Machine --- .../core/DataTiersUsageTransportAction.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTiersUsageTransportAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTiersUsageTransportAction.java index 208c1aebb25b3..27762c4617cee 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTiersUsageTransportAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTiersUsageTransportAction.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags; +import org.elasticsearch.action.admin.indices.stats.IndexShardStats; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; @@ -108,16 +109,19 @@ private DataTiersFeatureSetUsage.TierSpecificStats calculateStats(List { - nodeStats.getIndices().getShardStats(index).stream() - .filter(shardStats -> shardStats.getPrimary().getStore() != null) - .forEach(shardStats -> { - StoreStats primaryStoreStats = shardStats.getPrimary().getStore(); - // If storeStats is null, it means this is not a replica - primaryShardCount.incrementAndGet(); - long primarySize = primaryStoreStats.getSizeInBytes(); - primaryByteCount.addAndGet(primarySize); - valueSketch.add(primarySize); - }); + final List allShardStats = nodeStats.getIndices().getShardStats(index); + if (allShardStats != null) { + allShardStats.stream() + .filter(shardStats -> shardStats.getPrimary().getStore() != null) + .forEach(shardStats -> { + StoreStats primaryStoreStats = shardStats.getPrimary().getStore(); + // If storeStats is null, it means this is not a replica + primaryShardCount.incrementAndGet(); + long primarySize = primaryStoreStats.getSizeInBytes(); + primaryByteCount.addAndGet(primarySize); + valueSketch.add(primarySize); + }); + } }); } }