|
|
@@ -18,7 +18,9 @@ import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
|
|
|
+import org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorServiceTests;
|
|
|
import org.elasticsearch.cluster.service.ClusterService;
|
|
|
+import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.component.Lifecycle;
|
|
|
import org.elasticsearch.common.logging.ESLogMessage;
|
|
|
import org.elasticsearch.common.scheduler.SchedulerEngine;
|
|
|
@@ -122,13 +124,36 @@ public class HealthPeriodicLoggerTests extends ESTestCase {
|
|
|
|
|
|
Map<String, Object> loggerResults = HealthPeriodicLogger.convertToLoggedFields(results);
|
|
|
|
|
|
- // verify that the number of fields is the number of indicators + 2 (for overall and for message)
|
|
|
- assertThat(loggerResults.size(), equalTo(results.size() + 2));
|
|
|
+ // verify that the number of fields is the number of indicators + 4
|
|
|
+ // (for overall and for message, plus details for the two yellow indicators)
|
|
|
+ assertThat(loggerResults.size(), equalTo(results.size() + 4));
|
|
|
|
|
|
// test indicator status
|
|
|
assertThat(loggerResults.get(makeHealthStatusString("master_is_stable")), equalTo("green"));
|
|
|
assertThat(loggerResults.get(makeHealthStatusString("disk")), equalTo("yellow"));
|
|
|
+ assertThat(
|
|
|
+ loggerResults.get(makeHealthDetailsString("disk")),
|
|
|
+ equalTo(
|
|
|
+ getTestIndicatorResults().stream()
|
|
|
+ .filter(i -> i.name().equals("disk"))
|
|
|
+ .findFirst()
|
|
|
+ .map(HealthIndicatorResult::details)
|
|
|
+ .map(Strings::toString)
|
|
|
+ .orElseThrow()
|
|
|
+ )
|
|
|
+ );
|
|
|
assertThat(loggerResults.get(makeHealthStatusString("shards_availability")), equalTo("yellow"));
|
|
|
+ assertThat(
|
|
|
+ loggerResults.get(makeHealthDetailsString("shards_availability")),
|
|
|
+ equalTo(
|
|
|
+ getTestIndicatorResults().stream()
|
|
|
+ .filter(i -> i.name().equals("shards_availability"))
|
|
|
+ .findFirst()
|
|
|
+ .map(HealthIndicatorResult::details)
|
|
|
+ .map(Strings::toString)
|
|
|
+ .orElseThrow()
|
|
|
+ )
|
|
|
+ );
|
|
|
|
|
|
// test calculated overall status
|
|
|
assertThat(loggerResults.get(makeHealthStatusString("overall")), equalTo(overallStatus.xContentValue()));
|
|
|
@@ -751,8 +776,35 @@ public class HealthPeriodicLoggerTests extends ESTestCase {
|
|
|
|
|
|
private List<HealthIndicatorResult> getTestIndicatorResults() {
|
|
|
var networkLatency = new HealthIndicatorResult("master_is_stable", GREEN, null, null, null, null);
|
|
|
- var slowTasks = new HealthIndicatorResult("disk", YELLOW, null, null, null, null);
|
|
|
- var shardsAvailable = new HealthIndicatorResult("shards_availability", YELLOW, null, null, null, null);
|
|
|
+ var slowTasks = new HealthIndicatorResult(
|
|
|
+ "disk",
|
|
|
+ YELLOW,
|
|
|
+ null,
|
|
|
+ new SimpleHealthIndicatorDetails(
|
|
|
+ Map.of(
|
|
|
+ "indices_with_readonly_block",
|
|
|
+ 0,
|
|
|
+ "nodes_with_enough_disk_space",
|
|
|
+ 1,
|
|
|
+ "nodes_with_unknown_disk_status",
|
|
|
+ 0,
|
|
|
+ "nodes_over_high_watermark",
|
|
|
+ 0,
|
|
|
+ "nodes_over_flood_stage_watermark",
|
|
|
+ 1
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ null,
|
|
|
+ null
|
|
|
+ );
|
|
|
+ var shardsAvailable = new HealthIndicatorResult(
|
|
|
+ "shards_availability",
|
|
|
+ YELLOW,
|
|
|
+ null,
|
|
|
+ new SimpleHealthIndicatorDetails(ShardsAvailabilityHealthIndicatorServiceTests.addDefaults(Map.of())),
|
|
|
+ null,
|
|
|
+ null
|
|
|
+ );
|
|
|
|
|
|
return List.of(networkLatency, slowTasks, shardsAvailable);
|
|
|
}
|
|
|
@@ -760,7 +812,14 @@ public class HealthPeriodicLoggerTests extends ESTestCase {
|
|
|
private List<HealthIndicatorResult> getTestIndicatorResultsAllGreen() {
|
|
|
var networkLatency = new HealthIndicatorResult("master_is_stable", GREEN, null, null, null, null);
|
|
|
var slowTasks = new HealthIndicatorResult("disk", GREEN, null, null, null, null);
|
|
|
- var shardsAvailable = new HealthIndicatorResult("shards_availability", GREEN, null, null, null, null);
|
|
|
+ var shardsAvailable = new HealthIndicatorResult(
|
|
|
+ "shards_availability",
|
|
|
+ GREEN,
|
|
|
+ null,
|
|
|
+ new SimpleHealthIndicatorDetails(ShardsAvailabilityHealthIndicatorServiceTests.addDefaults(Map.of())),
|
|
|
+ null,
|
|
|
+ null
|
|
|
+ );
|
|
|
|
|
|
return List.of(networkLatency, slowTasks, shardsAvailable);
|
|
|
}
|
|
|
@@ -768,7 +827,14 @@ public class HealthPeriodicLoggerTests extends ESTestCase {
|
|
|
private List<HealthIndicatorResult> getTestIndicatorResultsWithRed() {
|
|
|
var networkLatency = new HealthIndicatorResult("master_is_stable", GREEN, null, null, null, null);
|
|
|
var slowTasks = new HealthIndicatorResult("disk", GREEN, null, null, null, null);
|
|
|
- var shardsAvailable = new HealthIndicatorResult("shards_availability", RED, null, null, null, null);
|
|
|
+ var shardsAvailable = new HealthIndicatorResult(
|
|
|
+ "shards_availability",
|
|
|
+ RED,
|
|
|
+ null,
|
|
|
+ new SimpleHealthIndicatorDetails(ShardsAvailabilityHealthIndicatorServiceTests.addDefaults(Map.of("unassigned_primaries", 1))),
|
|
|
+ null,
|
|
|
+ null
|
|
|
+ );
|
|
|
|
|
|
return List.of(networkLatency, slowTasks, shardsAvailable);
|
|
|
}
|
|
|
@@ -777,6 +843,10 @@ public class HealthPeriodicLoggerTests extends ESTestCase {
|
|
|
return String.format(Locale.ROOT, "%s.%s.status", HealthPeriodicLogger.HEALTH_FIELD_PREFIX, key);
|
|
|
}
|
|
|
|
|
|
+ private String makeHealthDetailsString(String key) {
|
|
|
+ return String.format(Locale.ROOT, "%s.%s.details", HealthPeriodicLogger.HEALTH_FIELD_PREFIX, key);
|
|
|
+ }
|
|
|
+
|
|
|
private HealthPeriodicLogger createAndInitHealthPeriodicLogger(
|
|
|
ClusterService clusterService,
|
|
|
HealthService testHealthService,
|