-
Notifications
You must be signed in to change notification settings - Fork 210
/
SubscriptionHealthProblem.java
96 lines (79 loc) · 3.29 KB
/
SubscriptionHealthProblem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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);
}
}