@@ -84,27 +84,27 @@ public class FileSettingsService extends MasterNodeFileWatchingService implement
8484
8585 private final Path watchedFile ;
8686 private final ReservedClusterStateService stateService ;
87- private final FileSettingsHealthIndicatorService healthIndicatorService ;
87+ private final FileSettingsHealthTracker healthIndicatorTracker ;
8888
8989 /**
9090 * Constructs the {@link FileSettingsService}
9191 *
9292 * @param clusterService so we can register ourselves as a cluster state change listener
9393 * @param stateService an instance of the immutable cluster state controller, so we can perform the cluster state changes
9494 * @param environment we need the environment to pull the location of the config and operator directories
95- * @param healthIndicatorService tracks the success or failure of file-based settings
95+ * @param healthIndicatorTracker tracks the success or failure of file-based settings operations
9696 */
9797 @ SuppressWarnings ("this-escape" )
9898 public FileSettingsService (
9999 ClusterService clusterService ,
100100 ReservedClusterStateService stateService ,
101101 Environment environment ,
102- FileSettingsHealthIndicatorService healthIndicatorService
102+ FileSettingsHealthTracker healthIndicatorTracker
103103 ) {
104104 super (clusterService , environment .configDir ().toAbsolutePath ().resolve (OPERATOR_DIRECTORY ));
105105 this .watchedFile = watchedFileDir ().resolve (SETTINGS_FILE_NAME );
106106 this .stateService = stateService ;
107- this .healthIndicatorService = healthIndicatorService ;
107+ this .healthIndicatorTracker = healthIndicatorTracker ;
108108 }
109109
110110 protected Logger logger () {
@@ -115,8 +115,8 @@ public Path watchedFile() {
115115 return watchedFile ;
116116 }
117117
118- public FileSettingsHealthIndicatorService healthIndicatorService () {
119- return healthIndicatorService ;
118+ public FileSettingsHealthTracker healthIndicatorService () {
119+ return healthIndicatorTracker ;
120120 }
121121
122122 /**
@@ -152,14 +152,14 @@ public void handleSnapshotRestore(ClusterState clusterState, Metadata.Builder md
152152
153153 @ Override
154154 protected void doStart () {
155- healthIndicatorService .startOccurred ();
155+ healthIndicatorTracker .startOccurred ();
156156 super .doStart ();
157157 }
158158
159159 @ Override
160160 protected void doStop () {
161161 super .doStop ();
162- healthIndicatorService .stopOccurred ();
162+ healthIndicatorTracker .stopOccurred ();
163163 }
164164
165165 /**
@@ -202,7 +202,7 @@ protected void processFile(Path file, boolean startup) throws IOException, Execu
202202 logger ().debug ("Received notification for unknown file {}" , file );
203203 } else {
204204 logger ().info ("processing path [{}] for [{}]{}" , watchedFile , NAMESPACE , startup ? " on service start" : "" );
205- healthIndicatorService .changeOccurred ();
205+ healthIndicatorTracker .changeOccurred ();
206206 processFileChanges (startup ? HIGHER_OR_SAME_VERSION : HIGHER_VERSION_ONLY );
207207 }
208208 }
@@ -222,15 +222,15 @@ private void processFileChanges(ReservedStateVersionCheck versionCheck) throws I
222222 protected void completeProcessing (Exception e , PlainActionFuture <Void > completion ) {
223223 try {
224224 if (e != null ) {
225- healthIndicatorService .failureOccurred (e .toString ());
225+ healthIndicatorTracker .failureOccurred (e .toString ());
226226 completion .onFailure (e );
227227 } else {
228228 completion .onResponse (null );
229- healthIndicatorService .successOccurred ();
229+ healthIndicatorTracker .successOccurred ();
230230 }
231231 } finally {
232232 logger ().debug ("Publishing to health node" );
233- healthIndicatorService .publish ();
233+ healthIndicatorTracker .publish ();
234234 }
235235 }
236236
@@ -304,6 +304,9 @@ public FileSettingsHealthInfo failed(String failureDescription) {
304304 }
305305 }
306306
307+ /**
308+ * Stateless service that maps a {@link FileSettingsHealthInfo} to a {@link HealthIndicatorResult}.
309+ */
307310 public static class FileSettingsHealthIndicatorService implements HealthIndicatorService {
308311 static final String NAME = "file_settings" ;
309312 static final String INACTIVE_SYMPTOM = "File-based settings are inactive" ;
@@ -321,6 +324,43 @@ public static class FileSettingsHealthIndicatorService implements HealthIndicato
321324 )
322325 );
323326
327+ @ Override
328+ public String name () {
329+ return NAME ;
330+ }
331+
332+ @ Override
333+ public synchronized HealthIndicatorResult calculate (boolean verbose , int maxAffectedResourcesCount , HealthInfo healthInfo ) {
334+ return calculate (healthInfo .fileSettingsHealthInfo ());
335+ }
336+
337+ public HealthIndicatorResult calculate (FileSettingsHealthInfo info ) {
338+ if (info .isActive () == false ) {
339+ return createIndicator (GREEN , INACTIVE_SYMPTOM , HealthIndicatorDetails .EMPTY , List .of (), List .of ());
340+ }
341+ if (0 == info .changeCount ()) {
342+ return createIndicator (GREEN , NO_CHANGES_SYMPTOM , HealthIndicatorDetails .EMPTY , List .of (), List .of ());
343+ }
344+ if (0 == info .failureStreak ()) {
345+ return createIndicator (GREEN , SUCCESS_SYMPTOM , HealthIndicatorDetails .EMPTY , List .of (), List .of ());
346+ } else {
347+ return createIndicator (
348+ YELLOW ,
349+ FAILURE_SYMPTOM ,
350+ new SimpleHealthIndicatorDetails (
351+ Map .of ("failure_streak" , info .failureStreak (), "most_recent_failure" , info .mostRecentFailure ())
352+ ),
353+ STALE_SETTINGS_IMPACT ,
354+ List .of ()
355+ );
356+ }
357+ }
358+ }
359+
360+ /**
361+ * Houses the current {@link FileSettingsHealthInfo} and provides a means to <i>publish</i> it to the health node.
362+ */
363+ public static class FileSettingsHealthTracker {
324364 /**
325365 * We want a length limit so we don't blow past the indexing limit in the case of a long description string.
326366 * This is an {@code OperatorDynamic} setting so that if the truncation hampers troubleshooting efforts,
@@ -338,11 +378,15 @@ public static class FileSettingsHealthIndicatorService implements HealthIndicato
338378 private final FileSettingsHealthIndicatorPublisher publisher ;
339379 private FileSettingsHealthInfo currentInfo = FileSettingsHealthInfo .INDETERMINATE ;
340380
341- public FileSettingsHealthIndicatorService (Settings settings , FileSettingsHealthIndicatorPublisher publisher ) {
381+ public FileSettingsHealthTracker (Settings settings , FileSettingsHealthIndicatorPublisher publisher ) {
342382 this .settings = settings ;
343383 this .publisher = publisher ;
344384 }
345385
386+ public FileSettingsHealthInfo getCurrentInfo () {
387+ return currentInfo ;
388+ }
389+
346390 public synchronized void startOccurred () {
347391 currentInfo = FileSettingsHealthInfo .INITIAL_ACTIVE ;
348392 }
@@ -372,6 +416,9 @@ private String limitLength(String description) {
372416 }
373417 }
374418
419+ /**
420+ * Sends the current health info to the health node.
421+ */
375422 public void publish () {
376423 publisher .publish (
377424 currentInfo ,
@@ -381,42 +428,6 @@ public void publish() {
381428 )
382429 );
383430 }
384-
385- @ Override
386- public String name () {
387- return NAME ;
388- }
389-
390- @ Override
391- public synchronized HealthIndicatorResult calculate (boolean verbose , int maxAffectedResourcesCount , HealthInfo healthInfo ) {
392- return calculate (healthInfo .fileSettingsHealthInfo ());
393- }
394-
395- public HealthIndicatorResult calculateFromCurrentInfo () {
396- return calculate (currentInfo );
397- }
398-
399- private HealthIndicatorResult calculate (FileSettingsHealthInfo info ) {
400- if (info .isActive () == false ) {
401- return createIndicator (GREEN , INACTIVE_SYMPTOM , HealthIndicatorDetails .EMPTY , List .of (), List .of ());
402- }
403- if (0 == info .changeCount ()) {
404- return createIndicator (GREEN , NO_CHANGES_SYMPTOM , HealthIndicatorDetails .EMPTY , List .of (), List .of ());
405- }
406- if (0 == info .failureStreak ()) {
407- return createIndicator (GREEN , SUCCESS_SYMPTOM , HealthIndicatorDetails .EMPTY , List .of (), List .of ());
408- } else {
409- return createIndicator (
410- YELLOW ,
411- FAILURE_SYMPTOM ,
412- new SimpleHealthIndicatorDetails (
413- Map .of ("failure_streak" , info .failureStreak (), "most_recent_failure" , info .mostRecentFailure ())
414- ),
415- STALE_SETTINGS_IMPACT ,
416- List .of ()
417- );
418- }
419- }
420431 }
421432
422433 public static class FileSettingsHealthIndicatorPublisherImpl implements FileSettingsHealthIndicatorPublisher {
0 commit comments