Skip to content

Commit 5f87329

Browse files
committed
Add logs for SLM health indicator missing snapshot
1 parent 05a2003 commit 5f87329

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

server/src/main/java/org/elasticsearch/health/HealthPeriodicLogger.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.List;
4343
import java.util.Locale;
4444
import java.util.Map;
45+
import java.util.Optional;
4546
import java.util.Set;
4647
import java.util.concurrent.Semaphore;
4748
import java.util.concurrent.TimeUnit;
@@ -52,16 +53,20 @@
5253
import static org.elasticsearch.health.HealthStatus.RED;
5354

5455
/**
55-
* This class periodically logs the results of the Health API to the standard Elasticsearch server log file. It a lifecycle
56-
* aware component because it health depends on other lifecycle aware components. This means:
56+
* This class periodically logs the results of the Health API to the standard Elasticsearch server log file. It is a lifecycle
57+
* aware component because it depends on other lifecycle aware components. This means:
5758
* - We do not schedule any jobs until the lifecycle state is STARTED
58-
* - When the lifecycle state becomes STOPPED, do not schedule any more runs, but we do let the current one finish
59+
* - When the lifecycle state becomes STOPPED, we do not schedule any more runs, but we do let the current one finish
5960
* - When the lifecycle state becomes CLOSED, we will interrupt the current run as well.
6061
*/
6162
public class HealthPeriodicLogger extends AbstractLifecycleComponent implements ClusterStateListener, SchedulerEngine.Listener {
6263
public static final String HEALTH_FIELD_PREFIX = "elasticsearch.health";
6364
public static final String MESSAGE_FIELD = "message";
6465

66+
// duplicated from SlmHealthIndicatorService since x-pack not accessible
67+
private static final String SLM_HEALTH_INDICATOR_SERVICE_NAME = "slm";
68+
private static final String SLM_HEALTH_INDICATOR_SERVICE_IMPACT_ID_MISSING_SNAPSHOT = "missing_snapshot";
69+
6570
/**
6671
* Valid modes of output for this logger
6772
*/
@@ -361,11 +366,25 @@ static Map<String, Object> convertToLoggedFields(List<HealthIndicatorResult> ind
361366
String.format(Locale.ROOT, "%s.%s.status", HEALTH_FIELD_PREFIX, indicatorResult.name()),
362367
indicatorResult.status().xContentValue()
363368
);
364-
if (GREEN.equals(indicatorResult.status()) == false && indicatorResult.details() != null) {
365-
result.put(
366-
String.format(Locale.ROOT, "%s.%s.details", HEALTH_FIELD_PREFIX, indicatorResult.name()),
367-
Strings.toString(indicatorResult.details())
368-
);
369+
if (GREEN.equals(indicatorResult.status()) == false) {
370+
if (indicatorResult.details() != null) {
371+
result.put(
372+
String.format(Locale.ROOT, "%s.%s.details", HEALTH_FIELD_PREFIX, indicatorResult.name()),
373+
Strings.toString(indicatorResult.details())
374+
);
375+
}
376+
377+
// output the SLM health indicator missing snapshot impact, so it can be specifically identified when occur
378+
if (SLM_HEALTH_INDICATOR_SERVICE_NAME.equals(indicatorResult.name())) {
379+
Optional<HealthIndicatorImpact> impactMissingSnapshot = indicatorResult.impacts()
380+
.stream()
381+
.filter(impact -> SLM_HEALTH_INDICATOR_SERVICE_IMPACT_ID_MISSING_SNAPSHOT.equals(impact.id()))
382+
.findFirst();
383+
impactMissingSnapshot.ifPresent(impact -> result.put(
384+
String.format(Locale.ROOT, "%s.%s.%s", HEALTH_FIELD_PREFIX, indicatorResult.name(), impact.id()),
385+
true
386+
));
387+
}
369388
}
370389
});
371390

0 commit comments

Comments
 (0)