13
13
import org .apache .logging .log4j .Logger ;
14
14
import org .elasticsearch .action .admin .cluster .node .stats .NodeStats ;
15
15
import org .elasticsearch .action .admin .indices .stats .CommonStatsFlags ;
16
+ import org .elasticsearch .cluster .node .DiscoveryNode ;
17
+ import org .elasticsearch .cluster .node .VersionInformation ;
16
18
import org .elasticsearch .common .component .AbstractLifecycleComponent ;
19
+ import org .elasticsearch .common .transport .TransportAddress ;
17
20
import org .elasticsearch .common .util .SingleObjectCache ;
18
21
import org .elasticsearch .core .TimeValue ;
19
22
import org .elasticsearch .index .stats .IndexingPressureStats ;
24
27
import org .elasticsearch .telemetry .metric .MeterRegistry ;
25
28
26
29
import java .io .IOException ;
30
+ import java .net .InetAddress ;
27
31
import java .util .ArrayList ;
28
32
import java .util .List ;
33
+ import java .util .Map ;
29
34
import java .util .Optional ;
35
+ import java .util .Set ;
30
36
31
37
/**
32
38
* NodeMetrics monitors various statistics of an Elasticsearch node and exposes them as metrics through
@@ -744,10 +750,38 @@ protected void doClose() throws IOException {
744
750
* refresh() is called, cache is updated and the new instance returned.
745
751
*/
746
752
private class NodeStatsCache extends SingleObjectCache <NodeStats > {
753
+ private static final NodeStats MISSING_NODE_STATS = new NodeStats (
754
+ new DiscoveryNode (
755
+ "_na" ,
756
+ "_na" ,
757
+ new TransportAddress (InetAddress .getLoopbackAddress (), 0 ),
758
+ Map .of (),
759
+ Set .of (),
760
+ VersionInformation .CURRENT
761
+ ),
762
+ 0 ,
763
+ null ,
764
+ null ,
765
+ null ,
766
+ null ,
767
+ null ,
768
+ null ,
769
+ null ,
770
+ null ,
771
+ null ,
772
+ null ,
773
+ null ,
774
+ null ,
775
+ null ,
776
+ null ,
777
+ null ,
778
+ null ,
779
+ null
780
+ );
747
781
private boolean refresh ;
748
782
749
783
NodeStatsCache (TimeValue interval ) {
750
- super (interval , getNodeStats () );
784
+ super (interval , MISSING_NODE_STATS );
751
785
this .refresh = true ;
752
786
}
753
787
@@ -756,6 +790,11 @@ protected NodeStats refresh() {
756
790
return refresh ? getNodeStats () : getNoRefresh ();
757
791
}
758
792
793
+ @ Override
794
+ protected boolean needsRefresh () {
795
+ return getNoRefresh () == MISSING_NODE_STATS || super .needsRefresh ();
796
+ }
797
+
759
798
public void stopRefreshing () {
760
799
this .refresh = false ;
761
800
}
0 commit comments