|
|
@@ -19,6 +19,7 @@ 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.ShardsAvailabilityHealthIndicatorService;
|
|
|
import org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorServiceTests;
|
|
|
import org.elasticsearch.cluster.service.ClusterService;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
@@ -28,6 +29,7 @@ import org.elasticsearch.common.scheduler.SchedulerEngine;
|
|
|
import org.elasticsearch.common.settings.ClusterSettings;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.core.TimeValue;
|
|
|
+import org.elasticsearch.health.node.DiskHealthIndicatorService;
|
|
|
import org.elasticsearch.telemetry.TelemetryProvider;
|
|
|
import org.elasticsearch.telemetry.metric.LongGaugeMetric;
|
|
|
import org.elasticsearch.telemetry.metric.MeterRegistry;
|
|
|
@@ -51,9 +53,12 @@ import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.function.BiConsumer;
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
+import static org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorService.PRIMARY_UNASSIGNED_IMPACT_ID;
|
|
|
+import static org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorService.REPLICA_UNASSIGNED_IMPACT_ID;
|
|
|
import static org.elasticsearch.health.HealthStatus.GREEN;
|
|
|
import static org.elasticsearch.health.HealthStatus.RED;
|
|
|
import static org.elasticsearch.health.HealthStatus.YELLOW;
|
|
|
+import static org.elasticsearch.health.node.DiskHealthIndicatorService.IMPACT_INGEST_UNAVAILABLE_ID;
|
|
|
import static org.elasticsearch.test.ClusterServiceUtils.createClusterService;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
@@ -125,9 +130,9 @@ public class HealthPeriodicLoggerTests extends ESTestCase {
|
|
|
|
|
|
Map<String, Object> loggerResults = HealthPeriodicLogger.convertToLoggedFields(results);
|
|
|
|
|
|
- // 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));
|
|
|
+ // verify that the number of fields is the number of indicators + 7
|
|
|
+ // (for overall and for message, plus details for the two yellow indicators, plus three impact)
|
|
|
+ assertThat(loggerResults.size(), equalTo(results.size() + 7));
|
|
|
|
|
|
// test indicator status
|
|
|
assertThat(loggerResults.get(makeHealthStatusString("master_is_stable")), equalTo("green"));
|
|
|
@@ -165,6 +170,17 @@ public class HealthPeriodicLoggerTests extends ESTestCase {
|
|
|
equalTo(String.format(Locale.ROOT, "health=%s [disk,shards_availability]", overallStatus.xContentValue()))
|
|
|
);
|
|
|
|
|
|
+ // test impact
|
|
|
+ assertThat(loggerResults.get(makeHealthImpactString(DiskHealthIndicatorService.NAME, IMPACT_INGEST_UNAVAILABLE_ID)), equalTo(true));
|
|
|
+ assertThat(
|
|
|
+ loggerResults.get(makeHealthImpactString(ShardsAvailabilityHealthIndicatorService.NAME, PRIMARY_UNASSIGNED_IMPACT_ID)),
|
|
|
+ equalTo(true)
|
|
|
+ );
|
|
|
+ assertThat(
|
|
|
+ loggerResults.get(makeHealthImpactString(ShardsAvailabilityHealthIndicatorService.NAME, REPLICA_UNASSIGNED_IMPACT_ID)),
|
|
|
+ equalTo(true)
|
|
|
+ );
|
|
|
+
|
|
|
// test empty results
|
|
|
{
|
|
|
List<HealthIndicatorResult> empty = new ArrayList<>();
|
|
|
@@ -793,7 +809,15 @@ public class HealthPeriodicLoggerTests extends ESTestCase {
|
|
|
1
|
|
|
)
|
|
|
),
|
|
|
- null,
|
|
|
+ List.of(
|
|
|
+ new HealthIndicatorImpact(
|
|
|
+ DiskHealthIndicatorService.NAME,
|
|
|
+ IMPACT_INGEST_UNAVAILABLE_ID,
|
|
|
+ 2,
|
|
|
+ "description",
|
|
|
+ List.of(ImpactArea.INGEST)
|
|
|
+ )
|
|
|
+ ),
|
|
|
null
|
|
|
);
|
|
|
var shardsAvailable = new HealthIndicatorResult(
|
|
|
@@ -801,7 +825,22 @@ public class HealthPeriodicLoggerTests extends ESTestCase {
|
|
|
YELLOW,
|
|
|
null,
|
|
|
new SimpleHealthIndicatorDetails(ShardsAvailabilityHealthIndicatorServiceTests.addDefaults(Map.of())),
|
|
|
- null,
|
|
|
+ List.of(
|
|
|
+ new HealthIndicatorImpact(
|
|
|
+ ShardsAvailabilityHealthIndicatorService.NAME,
|
|
|
+ PRIMARY_UNASSIGNED_IMPACT_ID,
|
|
|
+ 2,
|
|
|
+ "description",
|
|
|
+ List.of(ImpactArea.SEARCH)
|
|
|
+ ),
|
|
|
+ new HealthIndicatorImpact(
|
|
|
+ ShardsAvailabilityHealthIndicatorService.NAME,
|
|
|
+ REPLICA_UNASSIGNED_IMPACT_ID,
|
|
|
+ 2,
|
|
|
+ "description",
|
|
|
+ List.of(ImpactArea.SEARCH)
|
|
|
+ )
|
|
|
+ ),
|
|
|
null
|
|
|
);
|
|
|
|
|
|
@@ -846,6 +885,10 @@ public class HealthPeriodicLoggerTests extends ESTestCase {
|
|
|
return String.format(Locale.ROOT, "%s.%s.details", HealthPeriodicLogger.HEALTH_FIELD_PREFIX, key);
|
|
|
}
|
|
|
|
|
|
+ private String makeHealthImpactString(String indicatorName, String impact) {
|
|
|
+ return String.format(Locale.ROOT, "%s.%s.%s.impacted", HealthPeriodicLogger.HEALTH_FIELD_PREFIX, indicatorName, impact);
|
|
|
+ }
|
|
|
+
|
|
|
private HealthPeriodicLogger createAndInitHealthPeriodicLogger(
|
|
|
ClusterService clusterService,
|
|
|
HealthService testHealthService,
|