Skip to content

Commit 4f6102b

Browse files
committed
FileSettingsHealthTracker
1 parent bd5fed8 commit 4f6102b

File tree

7 files changed

+212
-164
lines changed

7 files changed

+212
-164
lines changed

server/src/main/java/org/elasticsearch/node/NodeConstruction.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
import org.elasticsearch.reservedstate.action.ReservedClusterSettingsAction;
194194
import org.elasticsearch.reservedstate.service.FileSettingsService;
195195
import org.elasticsearch.reservedstate.service.FileSettingsService.FileSettingsHealthIndicatorService;
196+
import org.elasticsearch.reservedstate.service.FileSettingsService.FileSettingsHealthTracker;
196197
import org.elasticsearch.reservedstate.service.FileSettingsServiceProvider;
197198
import org.elasticsearch.rest.action.search.SearchResponseMetrics;
198199
import org.elasticsearch.script.ScriptModule;
@@ -1112,11 +1113,11 @@ public Map<String, String> queryFields() {
11121113
actionModule.getReservedClusterStateService().installProjectStateHandler(new ReservedPipelineAction());
11131114

11141115
var fileSettingsHealthIndicatorPublisher = new FileSettingsService.FileSettingsHealthIndicatorPublisherImpl(clusterService, client);
1115-
var fileSettingsHealthIndicatorService = new FileSettingsHealthIndicatorService(settings, fileSettingsHealthIndicatorPublisher);
1116+
var fileSettingsHealthTracker = new FileSettingsHealthTracker(settings, fileSettingsHealthIndicatorPublisher);
11161117
FileSettingsService fileSettingsService = pluginsService.loadSingletonServiceProvider(
11171118
FileSettingsServiceProvider.class,
11181119
() -> FileSettingsService::new
1119-
).construct(clusterService, actionModule.getReservedClusterStateService(), environment, fileSettingsHealthIndicatorService);
1120+
).construct(clusterService, actionModule.getReservedClusterStateService(), environment, fileSettingsHealthTracker);
11201121

11211122
RestoreService restoreService = new RestoreService(
11221123
clusterService,
@@ -1200,8 +1201,7 @@ public Map<String, String> queryFields() {
12001201
transportService,
12011202
threadPool,
12021203
telemetryProvider,
1203-
repositoriesService,
1204-
fileSettingsHealthIndicatorService
1204+
repositoriesService
12051205
)
12061206
);
12071207

@@ -1372,8 +1372,7 @@ private Module loadDiagnosticServices(
13721372
TransportService transportService,
13731373
ThreadPool threadPool,
13741374
TelemetryProvider telemetryProvider,
1375-
RepositoriesService repositoriesService,
1376-
FileSettingsHealthIndicatorService fileSettingsHealthIndicatorService
1375+
RepositoriesService repositoriesService
13771376
) {
13781377

13791378
MasterHistoryService masterHistoryService = new MasterHistoryService(transportService, threadPool, clusterService);
@@ -1389,7 +1388,7 @@ private Module loadDiagnosticServices(
13891388
new RepositoryIntegrityHealthIndicatorService(clusterService),
13901389
new DiskHealthIndicatorService(clusterService),
13911390
new ShardsCapacityHealthIndicatorService(clusterService),
1392-
fileSettingsHealthIndicatorService
1391+
new FileSettingsHealthIndicatorService()
13931392
);
13941393
var pluginHealthIndicatorServices = pluginsService.filterPlugins(HealthPlugin.class)
13951394
.flatMap(plugin -> plugin.getHealthIndicatorServices().stream());

server/src/main/java/org/elasticsearch/reservedstate/service/FileSettingsHealthIndicatorPublisher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
import org.elasticsearch.action.ActionListener;
1313
import org.elasticsearch.action.support.master.AcknowledgedResponse;
14-
import org.elasticsearch.reservedstate.service.FileSettingsService.FileSettingsHealthIndicatorService;
14+
import org.elasticsearch.reservedstate.service.FileSettingsService.FileSettingsHealthTracker;
1515

1616
/**
17-
* Used by {@link FileSettingsHealthIndicatorService} to send health info to the health node.
17+
* Used by {@link FileSettingsHealthTracker} to send health info to the health node.
1818
*/
1919
public interface FileSettingsHealthIndicatorPublisher {
2020
void publish(FileSettingsService.FileSettingsHealthInfo info, ActionListener<AcknowledgedResponse> actionListener);

server/src/main/java/org/elasticsearch/reservedstate/service/FileSettingsService.java

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

server/src/main/java/org/elasticsearch/reservedstate/service/FileSettingsServiceProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ FileSettingsService construct(
1717
ClusterService clusterService,
1818
ReservedClusterStateService stateService,
1919
Environment environment,
20-
FileSettingsService.FileSettingsHealthIndicatorService healthIndicatorService
20+
FileSettingsService.FileSettingsHealthTracker healthIndicatorService
2121
);
2222
}

0 commit comments

Comments
 (0)