@@ -201,34 +201,44 @@ void execute() {
201201 logger .trace ("starting async refresh" );
202202
203203 try (var ignoredRefs = fetchRefs ) {
204- if (diskThresholdEnabled ) {
205- try (var ignored = threadPool .getThreadContext ().clearTraceContext ()) {
206- fetchIndicesStats ();
207- }
208- } else {
209- logger .trace ("skipping collecting disk usage info from cluster, notifying listeners with empty cluster info" );
210- indicesStatsSummary = IndicesStatsSummary .EMPTY ;
204+ maybeFetchIndicesStats (diskThresholdEnabled );
205+ maybeFetchNodeStats (diskThresholdEnabled || shardHeapThresholdEnabled );
206+ maybeFetchNodesHeapUsage (shardHeapThresholdEnabled );
207+ }
208+ }
209+
210+ private void maybeFetchIndicesStats (boolean shouldFetch ) {
211+ if (shouldFetch ) {
212+ try (var ignored = threadPool .getThreadContext ().clearTraceContext ()) {
213+ fetchIndicesStats ();
211214 }
215+ } else {
216+ logger .trace ("skipping collecting disk usage info from cluster, notifying listeners with empty indices stats" );
217+ indicesStatsSummary = IndicesStatsSummary .EMPTY ;
218+ }
219+ }
212220
213- if (diskThresholdEnabled || shardHeapThresholdEnabled ) {
214- try (var ignored = threadPool .getThreadContext ().clearTraceContext ()) {
215- fetchNodeStats ();
216- }
217- } else {
218- logger .trace ("skipping collecting node stats from cluster, notifying listeners with empty node stats" );
219- leastAvailableSpaceUsages = Map .of ();
220- mostAvailableSpaceUsages = Map .of ();
221- maxHeapPerNode = Map .of ();
221+ private void maybeFetchNodeStats (boolean shouldFetch ) {
222+ if (shouldFetch ) {
223+ try (var ignored = threadPool .getThreadContext ().clearTraceContext ()) {
224+ fetchNodeStats ();
222225 }
226+ } else {
227+ logger .trace ("skipping collecting node stats from cluster, notifying listeners with empty node stats" );
228+ leastAvailableSpaceUsages = Map .of ();
229+ mostAvailableSpaceUsages = Map .of ();
230+ maxHeapPerNode = Map .of ();
231+ }
232+ }
223233
224- if (shardHeapThresholdEnabled ) {
225- try (var ignored = threadPool .getThreadContext ().clearTraceContext ()) {
226- fetchNodesHeapUsage ();
227- }
228- } else {
229- logger .trace ("skipping collecting shard heap usage from cluster, notifying listeners with empty shard heap usage" );
230- shardHeapUsagePerNode = Map .of ();
234+ private void maybeFetchNodesHeapUsage (boolean shouldFetch ) {
235+ if (shouldFetch ) {
236+ try (var ignored = threadPool .getThreadContext ().clearTraceContext ()) {
237+ fetchNodesHeapUsage ();
231238 }
239+ } else {
240+ logger .trace ("skipping collecting shard heap usage from cluster, notifying listeners with empty shard heap usage" );
241+ shardHeapUsagePerNode = Map .of ();
232242 }
233243 }
234244
0 commit comments