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
Improved subscription health problem indicators #972
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
81fc2ba
Adds endpoint returning description of unhealthy subscriptions
piotrrzysko f6b9c38
Applying review suggestions
piotrrzysko 248f246
Improved subscription health problem indicators
piotrrzysko 1b94207
PR fixes
piotrrzysko 6501bc0
Merge branch 'master' into problem-indicators-improvements
piotrrzysko 6afa920
Merge branch 'master' into problem-indicators-improvements
piotrrzysko bbc1dec
Merge branch 'master' into problem-indicators-improvements
piotrrzysko File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionHealthProblem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package pl.allegro.tech.hermes.api; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.Objects; | ||
|
||
import static java.lang.String.format; | ||
import static pl.allegro.tech.hermes.api.SubscriptionHealthProblem.ProblemCode.LAGGING; | ||
import static pl.allegro.tech.hermes.api.SubscriptionHealthProblem.ProblemCode.MALFUNCTIONING; | ||
import static pl.allegro.tech.hermes.api.SubscriptionHealthProblem.ProblemCode.RECEIVING_MALFORMED_MESSAGES; | ||
import static pl.allegro.tech.hermes.api.SubscriptionHealthProblem.ProblemCode.TIMING_OUT; | ||
import static pl.allegro.tech.hermes.api.SubscriptionHealthProblem.ProblemCode.UNREACHABLE; | ||
|
||
public class SubscriptionHealthProblem { | ||
|
||
public enum ProblemCode { | ||
LAGGING, UNREACHABLE, TIMING_OUT, MALFUNCTIONING, RECEIVING_MALFORMED_MESSAGES | ||
} | ||
|
||
private final ProblemCode code; | ||
private final String description; | ||
|
||
@JsonCreator | ||
private SubscriptionHealthProblem(@JsonProperty("code") ProblemCode code, | ||
@JsonProperty("description") String description) { | ||
this.code = code; | ||
this.description = description; | ||
} | ||
|
||
public static SubscriptionHealthProblem lagging(long subscriptionLag) { | ||
return new SubscriptionHealthProblem( | ||
LAGGING, | ||
format("Subscription lag is growing, current value is %d messages", subscriptionLag) | ||
); | ||
} | ||
|
||
public static SubscriptionHealthProblem malfunctioning(double code5xxErrorsRate) { | ||
return new SubscriptionHealthProblem( | ||
MALFUNCTIONING, | ||
format("Consuming service returns a lot of 5xx codes, currently %.0f 5xx/s", code5xxErrorsRate) | ||
); | ||
} | ||
|
||
public static SubscriptionHealthProblem receivingMalformedMessages(double code4xxErrorsRate) { | ||
return new SubscriptionHealthProblem( | ||
RECEIVING_MALFORMED_MESSAGES, | ||
format("Consuming service returns a lot of 4xx codes, currently %.0f 4xx/s", code4xxErrorsRate) | ||
); | ||
} | ||
|
||
public static SubscriptionHealthProblem timingOut(double timeoutsRate) { | ||
return new SubscriptionHealthProblem( | ||
TIMING_OUT, | ||
format("Consuming service times out a lot, currently %.0f timeouts/s", timeoutsRate) | ||
); | ||
} | ||
|
||
public static SubscriptionHealthProblem unreachable(double otherErrorsRate) { | ||
return new SubscriptionHealthProblem( | ||
UNREACHABLE, | ||
format("Unable to connect to consuming service instances, current rate is %.0f failures/s", otherErrorsRate) | ||
); | ||
} | ||
|
||
public ProblemCode getCode() { | ||
return code; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return code.name(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(code, description); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
SubscriptionHealthProblem other = (SubscriptionHealthProblem) obj; | ||
return Objects.equals(this.code, other.code) | ||
&& Objects.equals(this.description, other.description); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
hermes-api/src/main/java/pl/allegro/tech/hermes/api/endpoints/UnhealthyEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
package pl.allegro.tech.hermes.api.endpoints; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
import pl.allegro.tech.hermes.api.UnhealthySubscription; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import java.util.List; | ||
import javax.ws.rs.core.Response; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
import static javax.ws.rs.core.MediaType.TEXT_PLAIN; | ||
|
||
@Path("unhealthy") | ||
public interface UnhealthyEndpoint { | ||
|
||
@GET | ||
@Produces(APPLICATION_JSON) | ||
@Produces({APPLICATION_JSON, TEXT_PLAIN}) | ||
@Path("/") | ||
List<UnhealthySubscription> listUnhealthy(@QueryParam("ownerSourceName") String ownerSourceName, | ||
@QueryParam("ownerId") String id, | ||
@QueryParam("respectMonitoringSeverity") boolean respectMonitoringSeverity); | ||
Response listUnhealthy(@QueryParam("ownerSourceName") String ownerSourceName, | ||
@QueryParam("ownerId") String id, | ||
@QueryParam("respectMonitoringSeverity") boolean respectMonitoringSeverity); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...legro/tech/hermes/management/api/writer/UnhealthySubscriptionListPlainTextBodyWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package pl.allegro.tech.hermes.management.api.writer; | ||
|
||
import pl.allegro.tech.hermes.api.SubscriptionHealthProblem; | ||
import pl.allegro.tech.hermes.api.UnhealthySubscription; | ||
|
||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.ext.MessageBodyWriter; | ||
import javax.ws.rs.ext.Provider; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
|
||
import static java.util.stream.Collectors.joining; | ||
import static javax.ws.rs.core.MediaType.TEXT_PLAIN; | ||
|
||
@Provider | ||
@Produces(TEXT_PLAIN) | ||
public class UnhealthySubscriptionListPlainTextBodyWriter implements MessageBodyWriter<List<UnhealthySubscription>> { | ||
|
||
@Override | ||
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { | ||
if (List.class.isAssignableFrom(type) && genericType instanceof ParameterizedType) { | ||
ParameterizedType parameterizedType = (ParameterizedType) genericType; | ||
Type[] actualTypeArgs = parameterizedType.getActualTypeArguments(); | ||
return actualTypeArgs.length == 1 && actualTypeArgs[0].equals(UnhealthySubscription.class); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public long getSize(List<UnhealthySubscription> unhealthySubscriptionList, | ||
Class<?> type, | ||
Type genericType, | ||
Annotation[] annotations, | ||
MediaType mediaType) { | ||
return -1; // According to JAX-RS 2.0 spec this method is deprecated and should return -1 | ||
} | ||
|
||
@Override | ||
public void writeTo(List<UnhealthySubscription> unhealthySubscriptionList, | ||
Class<?> type, | ||
Type genericType, | ||
Annotation[] annotations, | ||
MediaType mediaType, | ||
MultivaluedMap<String, Object> httpHeaders, | ||
OutputStream entityStream) throws IOException, WebApplicationException { | ||
String body = unhealthySubscriptionList.stream() | ||
.map(UnhealthySubscriptionListPlainTextBodyWriter::toPlainText) | ||
.collect(joining("\r\n")); | ||
entityStream.write(body.getBytes()); | ||
} | ||
|
||
private static String toPlainText(UnhealthySubscription unhealthySubscription) { | ||
String problemDescriptions = unhealthySubscription.getProblems().stream() | ||
.map(SubscriptionHealthProblem::getDescription) | ||
.collect(joining("; ")); | ||
return unhealthySubscription.getName() + " - " + problemDescriptions; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split into a separate lines please 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done