Skip to content

Add support for impact_areas to health impacts #85830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/85830.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 85830
summary: Add support for `impact_areas` to health impacts
area: Health
type: feature
issues:
- 85829
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.health.HealthIndicatorResult;
import org.elasticsearch.health.HealthIndicatorService;
import org.elasticsearch.health.HealthStatus;
import org.elasticsearch.health.ImpactArea;
import org.elasticsearch.health.SimpleHealthIndicatorDetails;

import java.util.ArrayList;
Expand Down Expand Up @@ -241,7 +242,7 @@ public List<HealthIndicatorImpact> getImpacts() {
primaries.indicesWithUnavailableShards.size() == 1 ? "index" : "indices",
getTruncatedIndicesString(primaries.indicesWithUnavailableShards, clusterMetadata)
);
impacts.add(new HealthIndicatorImpact(1, impactDescription));
impacts.add(new HealthIndicatorImpact(1, impactDescription, List.of(ImpactArea.INGEST, ImpactArea.SEARCH)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the use case for the impact areas is, but do "ingest" and "search" capture the impact areas of a missing primary? Should there be one like "cluster instability" or "data loss"? Calling missing data a search problem might not alert users enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll iterate on this as we go along (and keep track with the UI development). For now I think this would suffice (and we need to keep the language high level as it's impacts related)

}
/*
* It is possible that we're working with an intermediate cluster state, and that for an index we have no primary but a replica
Expand All @@ -258,7 +259,7 @@ public List<HealthIndicatorImpact> getImpacts() {
indicesWithUnavailableReplicasOnly.size() == 1 ? "index" : "indices",
getTruncatedIndicesString(indicesWithUnavailableReplicasOnly, clusterMetadata)
);
impacts.add(new HealthIndicatorImpact(3, impactDescription));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the priority an intentional change? The description of #84773 has unassigned replicas as a 3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The description was not updated to reflect that we ended up having only 2 impacts.

impacts.add(new HealthIndicatorImpact(2, impactDescription, List.of(ImpactArea.SEARCH)));
}
return impacts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,37 @@

package org.elasticsearch.health;

import org.elasticsearch.common.Strings;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Objects;
import java.util.List;

public record HealthIndicatorImpact(int severity, String impactDescription) implements ToXContentObject {
public record HealthIndicatorImpact(int severity, String impactDescription, List<ImpactArea> impactAreas) implements ToXContentObject {

public HealthIndicatorImpact {
if (severity < 0) {
throw new IllegalArgumentException("Severity cannot be less than 0");
}
Objects.requireNonNull(impactDescription);
if (Strings.isEmpty(impactDescription)) {
throw new IllegalArgumentException("Impact description must be provided");
}
if (impactAreas == null || impactAreas.isEmpty()) {
throw new IllegalArgumentException("At least one impact area must be provided");
}
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field("severity", severity);
builder.field("description", impactDescription);
builder.startArray("impact_areas");
for (ImpactArea impactArea : impactAreas) {
builder.value(impactArea.displayValue());
}
builder.endArray();
builder.endObject();
return builder;
}
Expand Down
24 changes: 24 additions & 0 deletions server/src/main/java/org/elasticsearch/health/ImpactArea.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.health;

public enum ImpactArea {
SEARCH("search"),
INGEST("ingest");

private final String displayValue;

ImpactArea(String displayValue) {
this.displayValue = displayValue;
}

public String displayValue() {
return displayValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.health.HealthIndicatorImpact;
import org.elasticsearch.health.HealthIndicatorResult;
import org.elasticsearch.health.HealthStatus;
import org.elasticsearch.health.ImpactArea;
import org.elasticsearch.health.SimpleHealthIndicatorDetails;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId;
Expand Down Expand Up @@ -115,8 +116,9 @@ public void testShouldBeYellowWhenThereAreUnassignedReplicas() {
),
List.of(
new HealthIndicatorImpact(
3,
"Searches might return slower than usual. Fewer redundant copies of the data exist on 1 index [yellow-index]."
2,
"Searches might return slower than usual. Fewer redundant copies of the data exist on 1 index [yellow-index].",
List.of(ImpactArea.SEARCH)
)
)
)
Expand All @@ -139,7 +141,11 @@ public void testShouldBeRedWhenThereAreUnassignedPrimariesAndAssignedReplicas()
"This cluster has 1 unavailable primary.",
Map.of("unassigned_primaries", 1, "started_replicas", 1),
List.of(
new HealthIndicatorImpact(1, "Cannot add data to 1 index [red-index]. Searches might return incomplete results.")
new HealthIndicatorImpact(
1,
"Cannot add data to 1 index [red-index]. Searches might return incomplete results.",
List.of(ImpactArea.INGEST, ImpactArea.SEARCH)
)
)
)
)
Expand All @@ -158,7 +164,11 @@ public void testShouldBeRedWhenThereAreUnassignedPrimariesAndNoReplicas() {
"This cluster has 1 unavailable primary.",
Map.of("unassigned_primaries", 1),
List.of(
new HealthIndicatorImpact(1, "Cannot add data to 1 index [red-index]. Searches might return incomplete results.")
new HealthIndicatorImpact(
1,
"Cannot add data to 1 index [red-index]. Searches might return incomplete results.",
List.of(ImpactArea.INGEST, ImpactArea.SEARCH)
)
)
)
)
Expand All @@ -178,7 +188,11 @@ public void testShouldBeRedWhenThereAreUnassignedPrimariesAndUnassignedReplicasO
assertEquals(1, result.impacts().size());
assertEquals(
result.impacts().get(0),
new HealthIndicatorImpact(1, "Cannot add data to 1 index [red-index]. Searches might return incomplete results.")
new HealthIndicatorImpact(
1,
"Cannot add data to 1 index [red-index]. Searches might return incomplete results.",
List.of(ImpactArea.INGEST, ImpactArea.SEARCH)
)
);
}

Expand All @@ -203,16 +217,21 @@ public void testShouldBeRedWhenThereAreUnassignedPrimariesAndUnassignedReplicasO
assertEquals(2, result.impacts().size());
assertEquals(
result.impacts().get(0),
new HealthIndicatorImpact(1, "Cannot add data to 1 index [red-index]. Searches might return incomplete results.")
new HealthIndicatorImpact(
1,
"Cannot add data to 1 index [red-index]. Searches might return incomplete results.",
List.of(ImpactArea.INGEST, ImpactArea.SEARCH)
)
);
// yellow-index-2 has the higher priority so it ought to be listed first:
assertThat(
result.impacts().get(1),
equalTo(
new HealthIndicatorImpact(
3,
2,
"Searches might return slower than usual. Fewer redundant copies of the data exist on 2 indices [yellow-index-2, "
+ "yellow-index-1]."
+ "yellow-index-1].",
List.of(ImpactArea.SEARCH)
)
)
);
Expand Down Expand Up @@ -241,9 +260,10 @@ public void testSortByIndexPriority() {
result.impacts().get(0),
equalTo(
new HealthIndicatorImpact(
3,
2,
"Searches might return slower than usual. Fewer redundant copies of the data exist on 3 indices [index-2, "
+ "index-1, index-3]."
+ "index-1, index-3].",
List.of(ImpactArea.SEARCH)
)
)
);
Expand Down Expand Up @@ -317,9 +337,10 @@ public void testShouldBeYellowWhenRestartingReplicasReachedAllocationDelay() {
Map.of("started_primaries", 1, "unassigned_replicas", 1),
List.of(
new HealthIndicatorImpact(
3,
2,
"Searches might return slower than usual. Fewer redundant copies of the data exist on 1 index "
+ "[restarting-index]."
+ "[restarting-index].",
List.of(ImpactArea.SEARCH)
)
)
)
Expand Down Expand Up @@ -389,7 +410,8 @@ public void testShouldBeRedWhenRestartingPrimariesReachedAllocationDelayAndNoRep
List.of(
new HealthIndicatorImpact(
1,
"Cannot add data to 1 index [restarting-index]. Searches might return incomplete results."
"Cannot add data to 1 index [restarting-index]. Searches might return incomplete results.",
List.of(ImpactArea.INGEST, ImpactArea.SEARCH)
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public void testToXContent() throws Exception {
List<HealthIndicatorImpact> impacts = new ArrayList<>();
int impact1Severity = randomIntBetween(1, 5);
String impact1Description = randomAlphaOfLength(30);
impacts.add(new HealthIndicatorImpact(impact1Severity, impact1Description));
ImpactArea firstImpactArea = randomFrom(ImpactArea.values());
impacts.add(new HealthIndicatorImpact(impact1Severity, impact1Description, List.of(firstImpactArea)));
int impact2Severity = randomIntBetween(1, 5);
String impact2Description = randomAlphaOfLength(30);
impacts.add(new HealthIndicatorImpact(impact2Severity, impact2Description));
ImpactArea secondImpactArea = randomFrom(ImpactArea.values());
impacts.add(new HealthIndicatorImpact(impact2Severity, impact2Description, List.of(secondImpactArea)));
HealthIndicatorResult result = new HealthIndicatorResult(name, component, status, summary, details, impacts);
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
result.toXContent(builder, ToXContent.EMPTY_PARAMS);
Expand All @@ -47,9 +49,11 @@ public void testToXContent() throws Exception {
Map<String, Object> expectedImpact1 = new HashMap<>();
expectedImpact1.put("severity", impact1Severity);
expectedImpact1.put("description", impact1Description);
expectedImpact1.put("impact_areas", List.of(firstImpactArea.displayValue()));
Map<String, Object> expectedImpact2 = new HashMap<>();
expectedImpact2.put("severity", impact2Severity);
expectedImpact2.put("description", impact2Description);
expectedImpact2.put("impact_areas", List.of(secondImpactArea.displayValue()));
expectedImpacts.add(expectedImpact1);
expectedImpacts.add(expectedImpact2);
assertEquals(expectedImpacts, xContentMap.get("impacts"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ public void testImpactsOrderAndLimit() {
HealthStatus status = randomFrom(HealthStatus.RED, HealthStatus.YELLOW, HealthStatus.GREEN);
Set<HealthIndicatorImpact> impacts = new HashSet<>();
for (int i = 0; i < 10; i++) {
impacts.add(new HealthIndicatorImpact(randomIntBetween(5, 20), randomAlphaOfLength(20)));
impacts.add(
new HealthIndicatorImpact(randomIntBetween(5, 20), randomAlphaOfLength(20), List.of(randomFrom(ImpactArea.values())))
);
}
HealthIndicatorImpact impact1 = new HealthIndicatorImpact(1, randomAlphaOfLength(20));
HealthIndicatorImpact impact2 = new HealthIndicatorImpact(2, randomAlphaOfLength(20));
HealthIndicatorImpact impact3 = new HealthIndicatorImpact(3, randomAlphaOfLength(20));
HealthIndicatorImpact impact1 = new HealthIndicatorImpact(1, randomAlphaOfLength(20), List.of(randomFrom(ImpactArea.values())));
HealthIndicatorImpact impact2 = new HealthIndicatorImpact(2, randomAlphaOfLength(20), List.of(randomFrom(ImpactArea.values())));
HealthIndicatorImpact impact3 = new HealthIndicatorImpact(3, randomAlphaOfLength(20), List.of(randomFrom(ImpactArea.values())));
impacts.add(impact2);
impacts.add(impact1);
impacts.add(impact3);
for (int i = 0; i < 10; i++) {
impacts.add(new HealthIndicatorImpact(randomIntBetween(5, 20), randomAlphaOfLength(20)));
impacts.add(
new HealthIndicatorImpact(randomIntBetween(5, 20), randomAlphaOfLength(20), List.of(randomFrom(ImpactArea.values())))
);
}
HealthIndicatorResult result = service.createIndicator(status, randomAlphaOfLength(20), HealthIndicatorDetails.EMPTY, impacts);
List<HealthIndicatorImpact> outputImpacts = result.impacts();
Expand Down