Skip to content

Commit

Permalink
Add null check for shard stats to data tier telemetry (elastic#75185)
Browse files Browse the repository at this point in the history
This adds a null check, as `getShardStats(index)` may return null.

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
2 people authored and masseyke committed Jul 16, 2021
1 parent 19ed187 commit 5db102d
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,16 +109,19 @@ private DataTiersFeatureSetUsage.TierSpecificStats calculateStats(List<NodeStats
.collect(Collectors.toSet());
indexCount += indicesOnNode.size();
indicesOnNode.forEach(index -> {
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<IndexShardStats> 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);
});
}
});
}
}
Expand Down

0 comments on commit 5db102d

Please sign in to comment.