|
19 | 19 | import org.elasticsearch.cluster.node.DiscoveryNode; |
20 | 20 | import org.elasticsearch.cluster.node.DiscoveryNodeRole; |
21 | 21 | import org.elasticsearch.cluster.node.DiscoveryNodeUtils; |
| 22 | +import org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorService; |
22 | 23 | import org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorServiceTests; |
23 | 24 | import org.elasticsearch.cluster.service.ClusterService; |
24 | 25 | import org.elasticsearch.common.Strings; |
|
28 | 29 | import org.elasticsearch.common.settings.ClusterSettings; |
29 | 30 | import org.elasticsearch.common.settings.Settings; |
30 | 31 | import org.elasticsearch.core.TimeValue; |
| 32 | +import org.elasticsearch.health.node.DiskHealthIndicatorService; |
31 | 33 | import org.elasticsearch.telemetry.TelemetryProvider; |
32 | 34 | import org.elasticsearch.telemetry.metric.LongGaugeMetric; |
33 | 35 | import org.elasticsearch.telemetry.metric.MeterRegistry; |
|
51 | 53 | import java.util.function.BiConsumer; |
52 | 54 | import java.util.function.Consumer; |
53 | 55 |
|
| 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; |
54 | 58 | import static org.elasticsearch.health.HealthStatus.GREEN; |
55 | 59 | import static org.elasticsearch.health.HealthStatus.RED; |
56 | 60 | import static org.elasticsearch.health.HealthStatus.YELLOW; |
| 61 | +import static org.elasticsearch.health.node.DiskHealthIndicatorService.IMPACT_INGEST_UNAVAILABLE_ID; |
57 | 62 | import static org.elasticsearch.test.ClusterServiceUtils.createClusterService; |
58 | 63 | import static org.hamcrest.Matchers.equalTo; |
59 | 64 | import static org.mockito.ArgumentMatchers.any; |
@@ -125,9 +130,9 @@ public void testConvertToLoggedFields() { |
125 | 130 |
|
126 | 131 | Map<String, Object> loggerResults = HealthPeriodicLogger.convertToLoggedFields(results); |
127 | 132 |
|
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)); |
131 | 136 |
|
132 | 137 | // test indicator status |
133 | 138 | assertThat(loggerResults.get(makeHealthStatusString("master_is_stable")), equalTo("green")); |
@@ -165,6 +170,17 @@ public void testConvertToLoggedFields() { |
165 | 170 | equalTo(String.format(Locale.ROOT, "health=%s [disk,shards_availability]", overallStatus.xContentValue())) |
166 | 171 | ); |
167 | 172 |
|
| 173 | + // test impact |
| 174 | + assertThat(loggerResults.get(makeHealthImpactString(DiskHealthIndicatorService.NAME, IMPACT_INGEST_UNAVAILABLE_ID)), equalTo(true)); |
| 175 | + assertThat( |
| 176 | + loggerResults.get(makeHealthImpactString(ShardsAvailabilityHealthIndicatorService.NAME, PRIMARY_UNASSIGNED_IMPACT_ID)), |
| 177 | + equalTo(true) |
| 178 | + ); |
| 179 | + assertThat( |
| 180 | + loggerResults.get(makeHealthImpactString(ShardsAvailabilityHealthIndicatorService.NAME, REPLICA_UNASSIGNED_IMPACT_ID)), |
| 181 | + equalTo(true) |
| 182 | + ); |
| 183 | + |
168 | 184 | // test empty results |
169 | 185 | { |
170 | 186 | List<HealthIndicatorResult> empty = new ArrayList<>(); |
@@ -793,15 +809,38 @@ private List<HealthIndicatorResult> getTestIndicatorResults() { |
793 | 809 | 1 |
794 | 810 | ) |
795 | 811 | ), |
796 | | - null, |
| 812 | + List.of( |
| 813 | + new HealthIndicatorImpact( |
| 814 | + DiskHealthIndicatorService.NAME, |
| 815 | + IMPACT_INGEST_UNAVAILABLE_ID, |
| 816 | + 2, |
| 817 | + "description", |
| 818 | + List.of(ImpactArea.INGEST) |
| 819 | + ) |
| 820 | + ), |
797 | 821 | null |
798 | 822 | ); |
799 | 823 | var shardsAvailable = new HealthIndicatorResult( |
800 | 824 | "shards_availability", |
801 | 825 | YELLOW, |
802 | 826 | null, |
803 | 827 | new SimpleHealthIndicatorDetails(ShardsAvailabilityHealthIndicatorServiceTests.addDefaults(Map.of())), |
804 | | - null, |
| 828 | + List.of( |
| 829 | + new HealthIndicatorImpact( |
| 830 | + ShardsAvailabilityHealthIndicatorService.NAME, |
| 831 | + PRIMARY_UNASSIGNED_IMPACT_ID, |
| 832 | + 2, |
| 833 | + "description", |
| 834 | + List.of(ImpactArea.SEARCH) |
| 835 | + ), |
| 836 | + new HealthIndicatorImpact( |
| 837 | + ShardsAvailabilityHealthIndicatorService.NAME, |
| 838 | + REPLICA_UNASSIGNED_IMPACT_ID, |
| 839 | + 2, |
| 840 | + "description", |
| 841 | + List.of(ImpactArea.SEARCH) |
| 842 | + ) |
| 843 | + ), |
805 | 844 | null |
806 | 845 | ); |
807 | 846 |
|
@@ -846,6 +885,10 @@ private String makeHealthDetailsString(String key) { |
846 | 885 | return String.format(Locale.ROOT, "%s.%s.details", HealthPeriodicLogger.HEALTH_FIELD_PREFIX, key); |
847 | 886 | } |
848 | 887 |
|
| 888 | + private String makeHealthImpactString(String indicatorName, String impact) { |
| 889 | + return String.format(Locale.ROOT, "%s.%s.%s.impacted", HealthPeriodicLogger.HEALTH_FIELD_PREFIX, indicatorName, impact); |
| 890 | + } |
| 891 | + |
849 | 892 | private HealthPeriodicLogger createAndInitHealthPeriodicLogger( |
850 | 893 | ClusterService clusterService, |
851 | 894 | HealthService testHealthService, |
|
0 commit comments