Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,14 @@ public boolean isCut() {
return cut;
}

public void setCut(boolean cut) {
private void setCut(boolean cut) {
this.cut = cut;
}

public AtomicLong getPassCount() {
return passCount;
}

public void setPassCount(AtomicLong passCount) {
this.passCount = passCount;
}

public int getTimeWindow() {
return timeWindow;
}
Expand Down Expand Up @@ -143,12 +139,6 @@ public boolean equals(Object o) {
if (grade != that.grade) {
return false;
}
// if (cut != that.cut) { return false; }
//// AtomicLong dose not Override equals()
// if ((passCount == null && that.passCount != null)
// || (passCount.get() != that.passCount.get())) {
// return false;
// }
return true;
}

Expand All @@ -158,9 +148,6 @@ public int hashCode() {
result = 31 * result + new Double(count).hashCode();
result = 31 * result + timeWindow;
result = 31 * result + grade;
// result = 31 * result + (cut ? 1 : 0);
// result = 31 * result + (passCount != null ? (int)passCount.get() :
// 0);
return result;
}

Expand All @@ -179,6 +166,7 @@ public boolean passCheck(Context context, DefaultNode node, int acquireCount, Ob
if (grade == RuleConstant.DEGRADE_GRADE_RT) {
double rt = clusterNode.avgRt();
if (rt < this.count) {
passCount.set(0);
return true;
}

Expand All @@ -189,11 +177,17 @@ public boolean passCheck(Context context, DefaultNode node, int acquireCount, Ob
} else {
double exception = clusterNode.exceptionQps();
double success = clusterNode.successQps();
if (success == 0) {
long total = clusterNode.totalQps();
// if total qps less than RT_MAX_EXCEED_N, pass.
if (total < RT_MAX_EXCEED_N) {
return true;
}

if (exception / success < count) {
if (success == 0) {
return exception < RT_MAX_EXCEED_N;
}

if (exception / (success + exception) < count) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,29 @@ public void testExceptionRatioModeDegrade() throws Throwable {
String key = "test_degrade_exception_ratio";
ClusterNode cn = mock(ClusterNode.class);
when(cn.exceptionQps()).thenReturn(2L);
// Indicates that there are QPS more than min threshold.
when(cn.totalQps()).thenReturn(12L);
ClusterBuilderSlot.getClusterNodeMap().put(new StringResourceWrapper(key, EntryType.IN), cn);

Context context = mock(Context.class);
DefaultNode node = mock(DefaultNode.class);
when(node.getClusterNode()).thenReturn(cn);

DegradeRule rule = new DegradeRule();
rule.setCount(0.5);
rule.setCount(0.15);
rule.setResource(key);
rule.setTimeWindow(5);
rule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION);

when(cn.successQps()).thenReturn(4L);
when(cn.successQps()).thenReturn(8L);

// Will fail.
assertFalse(rule.passCheck(context, node, 1));

// Restore from the degrade timeout.
TimeUnit.SECONDS.sleep(6);

when(cn.successQps()).thenReturn(7L);
when(cn.successQps()).thenReturn(20L);
// Will pass.
assertTrue(rule.passCheck(context, node, 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static String getConsoleServer() {
return SentinelConfig.getConfig(CONSOLE_SERVER);
}

public static int getRuntimePort() {
return runtimePort;
}

/**
* Get Server port of this HTTP server.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ public void run() {
}
}

if (success) {
tmpPort = port;
} else {
if (!success) {
tmpPort = PORT_UNINITIALIZED;
}
TransportConfig.setRuntimePort(tmpPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class SimpleHttpHeartbeatSender implements HeartbeatSender {
public SimpleHttpHeartbeatSender() {
// Retrieve the list of default addresses.
List<InetSocketAddress> newAddrs = getDefaultConsoleIps();
RecordLog.info("Default console address list retrieved: " + newAddrs);
RecordLog.info("[SimpleHttpHeartbeatSender] Default console address list retrieved: " + newAddrs);
this.addressList = newAddrs;
// Set interval config.
String interval = System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS, String.valueOf(DEFAULT_INTERVAL));
Expand All @@ -61,6 +61,10 @@ public SimpleHttpHeartbeatSender() {

@Override
public boolean sendHeartbeat() throws Exception {
if (TransportConfig.getRuntimePort() <= 0) {
RecordLog.info("[SimpleHttpHeartbeatSender] Runtime port not initialized, won't send heartbeat");
return false;
}
InetSocketAddress addr = getAvailableAddress();
if (addr == null) {
return false;
Expand Down