Skip to content

Commit 8e7ba91

Browse files
committed
Add indicator impact
1 parent 69b3a53 commit 8e7ba91

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,23 +367,21 @@ static Map<String, Object> convertToLoggedFields(List<HealthIndicatorResult> ind
367367
indicatorResult.status().xContentValue()
368368
);
369369
if (GREEN.equals(indicatorResult.status()) == false) {
370+
// indicator details
370371
if (indicatorResult.details() != null) {
371372
result.put(
372373
String.format(Locale.ROOT, "%s.%s.details", HEALTH_FIELD_PREFIX, indicatorResult.name()),
373374
Strings.toString(indicatorResult.details())
374375
);
375376
}
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-
));
377+
// indicator impact
378+
if (indicatorResult.impacts() != null) {
379+
indicatorResult.impacts().forEach(
380+
impact -> result.put(
381+
String.format(Locale.ROOT, "%s.%s.%s.impacted", HEALTH_FIELD_PREFIX, indicatorResult.name(), impact.id()),
382+
true
383+
)
384+
);
387385
}
388386
}
389387
});

server/src/main/java/org/elasticsearch/health/node/DiskHealthIndicatorService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public class DiskHealthIndicatorService implements HealthIndicatorService {
6666

6767
private static final Logger logger = LogManager.getLogger(DiskHealthIndicatorService.class);
6868

69-
private static final String IMPACT_INGEST_UNAVAILABLE_ID = "ingest_capability_unavailable";
69+
// VisibleForTesting
70+
public static final String IMPACT_INGEST_UNAVAILABLE_ID = "ingest_capability_unavailable";
7071
private static final String IMPACT_INGEST_AT_RISK_ID = "ingest_capability_at_risk";
7172
private static final String IMPACT_CLUSTER_STABILITY_AT_RISK_ID = "cluster_stability_at_risk";
7273
private static final String IMPACT_CLUSTER_FUNCTIONALITY_UNAVAILABLE_ID = "cluster_functionality_unavailable";

server/src/test/java/org/elasticsearch/health/HealthPeriodicLoggerTests.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.cluster.node.DiscoveryNode;
2020
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
2121
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
22+
import org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorService;
2223
import org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorServiceTests;
2324
import org.elasticsearch.cluster.service.ClusterService;
2425
import org.elasticsearch.common.Strings;
@@ -28,6 +29,7 @@
2829
import org.elasticsearch.common.settings.ClusterSettings;
2930
import org.elasticsearch.common.settings.Settings;
3031
import org.elasticsearch.core.TimeValue;
32+
import org.elasticsearch.health.node.DiskHealthIndicatorService;
3133
import org.elasticsearch.telemetry.TelemetryProvider;
3234
import org.elasticsearch.telemetry.metric.LongGaugeMetric;
3335
import org.elasticsearch.telemetry.metric.MeterRegistry;
@@ -51,9 +53,12 @@
5153
import java.util.function.BiConsumer;
5254
import java.util.function.Consumer;
5355

56+
import static org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorService.PRIMARY_UNASSIGNED_IMPACT_ID;
57+
import static org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorService.REPLICA_UNASSIGNED_IMPACT_ID;
5458
import static org.elasticsearch.health.HealthStatus.GREEN;
5559
import static org.elasticsearch.health.HealthStatus.RED;
5660
import static org.elasticsearch.health.HealthStatus.YELLOW;
61+
import static org.elasticsearch.health.node.DiskHealthIndicatorService.IMPACT_INGEST_UNAVAILABLE_ID;
5762
import static org.elasticsearch.test.ClusterServiceUtils.createClusterService;
5863
import static org.hamcrest.Matchers.equalTo;
5964
import static org.mockito.ArgumentMatchers.any;
@@ -125,9 +130,9 @@ public void testConvertToLoggedFields() {
125130

126131
Map<String, Object> loggerResults = HealthPeriodicLogger.convertToLoggedFields(results);
127132

128-
// verify that the number of fields is the number of indicators + 4
129-
// (for overall and for message, plus details for the two yellow indicators)
130-
assertThat(loggerResults.size(), equalTo(results.size() + 4));
133+
// verify that the number of fields is the number of indicators + 7
134+
// (for overall and for message, plus details for the two yellow indicators, plus three impact)
135+
assertThat(loggerResults.size(), equalTo(results.size() + 7));
131136

132137
// test indicator status
133138
assertThat(loggerResults.get(makeHealthStatusString("master_is_stable")), equalTo("green"));
@@ -165,6 +170,13 @@ public void testConvertToLoggedFields() {
165170
equalTo(String.format(Locale.ROOT, "health=%s [disk,shards_availability]", overallStatus.xContentValue()))
166171
);
167172

173+
// test impact
174+
assertThat(loggerResults.get(makeHealthImpactString(DiskHealthIndicatorService.NAME, IMPACT_INGEST_UNAVAILABLE_ID)), equalTo(true));
175+
assertThat(loggerResults.get(makeHealthImpactString(ShardsAvailabilityHealthIndicatorService.NAME, PRIMARY_UNASSIGNED_IMPACT_ID)),
176+
equalTo(true));
177+
assertThat(loggerResults.get(makeHealthImpactString(ShardsAvailabilityHealthIndicatorService.NAME, REPLICA_UNASSIGNED_IMPACT_ID)),
178+
equalTo(true));
179+
168180
// test empty results
169181
{
170182
List<HealthIndicatorResult> empty = new ArrayList<>();
@@ -793,15 +805,23 @@ private List<HealthIndicatorResult> getTestIndicatorResults() {
793805
1
794806
)
795807
),
796-
null,
808+
List.of(
809+
new HealthIndicatorImpact(DiskHealthIndicatorService.NAME, IMPACT_INGEST_UNAVAILABLE_ID, 2, "description",
810+
List.of(ImpactArea.INGEST))
811+
),
797812
null
798813
);
799814
var shardsAvailable = new HealthIndicatorResult(
800815
"shards_availability",
801816
YELLOW,
802817
null,
803818
new SimpleHealthIndicatorDetails(ShardsAvailabilityHealthIndicatorServiceTests.addDefaults(Map.of())),
804-
null,
819+
List.of(
820+
new HealthIndicatorImpact(ShardsAvailabilityHealthIndicatorService.NAME, PRIMARY_UNASSIGNED_IMPACT_ID, 2, "description",
821+
List.of(ImpactArea.SEARCH)),
822+
new HealthIndicatorImpact(ShardsAvailabilityHealthIndicatorService.NAME, REPLICA_UNASSIGNED_IMPACT_ID, 2, "description",
823+
List.of(ImpactArea.SEARCH))
824+
),
805825
null
806826
);
807827

@@ -846,6 +866,10 @@ private String makeHealthDetailsString(String key) {
846866
return String.format(Locale.ROOT, "%s.%s.details", HealthPeriodicLogger.HEALTH_FIELD_PREFIX, key);
847867
}
848868

869+
private String makeHealthImpactString(String indicatorName, String impact) {
870+
return String.format(Locale.ROOT, "%s.%s.%s.impacted", HealthPeriodicLogger.HEALTH_FIELD_PREFIX, indicatorName, impact);
871+
}
872+
849873
private HealthPeriodicLogger createAndInitHealthPeriodicLogger(
850874
ClusterService clusterService,
851875
HealthService testHealthService,

0 commit comments

Comments
 (0)