Skip to content
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

Improve the logs when the heartbeat response indicates failure #1303

Merged
merged 40 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
11dba5e
com.alibaba.csp.sentinel.node.StatisticNode#curThreadNum
May 9, 2019
362f326
reformat the code according to Alibaba Java Coding Guideline
May 11, 2019
50d2a5a
reformat the code according to Alibaba Java Coding Guideline
May 11, 2019
509ecf2
Merge pull request #1 from alibaba/master
linlinisme May 25, 2019
01bda6b
Remove the one redundant space....
May 28, 2019
ce717e9
fix issue 62 : Support customized log directory and configuration pro…
May 31, 2019
b8e66b8
use System.getProperty to get the property
May 31, 2019
5c6600d
Merge pull request #2 from alibaba/master
linlinisme Jun 14, 2019
9999154
merge master latest code
Jun 14, 2019
8f9339b
using SentinelConfigLocator to load sentinel-core config, LogConfigLo…
Jun 19, 2019
2f485b4
Merge pull request #3 from alibaba/master
linlinisme Jun 19, 2019
c6dd24d
merge remote master
Jun 19, 2019
810d40a
fix typo
Jun 19, 2019
3f98b62
add null judge
Jun 19, 2019
23244e9
Reorganize the code
Jun 20, 2019
bd8a481
Reorganize the code
Jun 20, 2019
e6bbf79
add config test cases
Jun 25, 2019
c91b963
ConfigUtil.loadPropertiesFromFile when file not exist return null
Jun 25, 2019
d401c2f
rename classname and method name
Jun 27, 2019
85173a5
rename classname and method name
Jun 27, 2019
4510234
using File.separator to replace "/"
Jun 27, 2019
c068edd
support retrieve properties from classpath file
Jun 27, 2019
9af06c9
support retrieve properties from classpath file
Jun 27, 2019
014cda3
add feature support : retrieve properties from relative file
Jul 1, 2019
a899dc6
reformat code
Jul 1, 2019
419d97f
Merge pull request #4 from alibaba/master
linlinisme Jul 1, 2019
80f283e
Merge remote-tracking branch 'remotes/origin/master' into 20190531-fi…
Jul 1, 2019
14a1d5b
Revert "rename classname and method name"
Jul 5, 2019
ea18020
add copy right doc
Jul 5, 2019
c562474
reset commit
Jul 6, 2019
c71759f
remove unused code
Jul 6, 2019
d387b47
merge alibaba master
Jul 10, 2019
56d5df0
Merge pull request #6 from alibaba/master
linlinisme Jul 24, 2019
22cafd2
Merge pull request #7 from alibaba/master
linlinisme Aug 22, 2019
7a0c6b7
Merge pull request #8 from alibaba/master
linlinisme Sep 10, 2019
7a4391d
Improve the logs when the heartbeat response indicates failure (#1194)
Feb 24, 2020
654d73a
Merge branch 'master' into log-heartbeat-response
linlinisme Feb 24, 2020
3b0f07d
Merge pull request #9 from alibaba/master
linlinisme Feb 24, 2020
f3a32dd
HttpHeartbeatSender remove duplicate host port check
Feb 24, 2020
d39d090
simply HeartBeatSender log and fix SimpleHttpResponse.toString() NPE …
Feb 25, 2020
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 @@ -15,15 +15,15 @@
*/
package com.alibaba.csp.sentinel.transport.config;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.log.RecordLog;
import com.alibaba.csp.sentinel.util.HostNameUtil;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.util.function.Tuple2;

import java.util.ArrayList;
import java.util.List;

/**
* @author leyou
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,26 @@
*/
package com.alibaba.csp.sentinel.transport.heartbeat;

import java.util.List;

import com.alibaba.csp.sentinel.Constants;
import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.log.RecordLog;
import com.alibaba.csp.sentinel.spi.SpiOrder;
import com.alibaba.csp.sentinel.transport.HeartbeatSender;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
import com.alibaba.csp.sentinel.log.RecordLog;
import com.alibaba.csp.sentinel.util.AppNameUtil;
import com.alibaba.csp.sentinel.util.HostNameUtil;
import com.alibaba.csp.sentinel.transport.HeartbeatSender;
import com.alibaba.csp.sentinel.util.PidUtil;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.util.function.Tuple2;

import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.util.List;

/**
* @author Eric Zhao
* @author leyou
Expand All @@ -45,6 +44,9 @@ public class HttpHeartbeatSender implements HeartbeatSender {

private final CloseableHttpClient client;

private static final int OK_STATUS = 200;


private final int timeoutMs = 3000;
private final RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(timeoutMs)
Expand Down Expand Up @@ -89,11 +91,43 @@ public boolean sendHeartbeat() throws Exception {
// Send heartbeat request.
CloseableHttpResponse response = client.execute(request);
response.close();
return true;
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == OK_STATUS) {
return true;
} else if (clientErrorCode(statusCode) || serverErrorCode(statusCode)) {
RecordLog.warn("[HttpHeartbeatSender] Failed to send heartbeat to "
+ consoleHost + ":" + consolePort + ", http status code: {0}", statusCode);
}

return false;


}

@Override
public long intervalMs() {
return 5000;
}

/**
* 4XX Client Error
*
* @param code
* @return
*/
private boolean clientErrorCode(int code) {
return code > 399 && code < 500;
}

/**
* 5XX Server Error
*
* @param code
* @return
*/
private boolean serverErrorCode(int code) {
return code > 499 && code < 600;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
*/
package com.alibaba.csp.sentinel.transport.heartbeat;

import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.csp.sentinel.log.RecordLog;
import com.alibaba.csp.sentinel.transport.HeartbeatSender;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpClient;
import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpRequest;
import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpResponse;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.util.function.Tuple2;

import java.net.InetSocketAddress;
import java.util.List;

/**
* The heartbeat sender provides basic API for sending heartbeat request to provided target.
* This implementation is based on a trivial HTTP client.
Expand Down Expand Up @@ -73,6 +71,8 @@ public boolean sendHeartbeat() throws Exception {
SimpleHttpResponse response = httpClient.post(request);
if (response.getStatusCode() == OK_STATUS) {
return true;
} else if (clientErrorCode(response.getStatusCode()) || serverErrorCode(response.getStatusCode())) {
RecordLog.warn("[SimpleHttpHeartbeatSender] Failed to send heartbeat to " + addr + ", http status code: {0}", response.getStatusCode());
}
} catch (Exception e) {
RecordLog.warn("[SimpleHttpHeartbeatSender] Failed to send heartbeat to " + addr, e);
Expand All @@ -96,4 +96,24 @@ private Tuple2<String, Integer> getAvailableAddress() {
return addressList.get(index);
}


/**
* 4XX Client Error
*
* @param code
* @return
*/
private boolean clientErrorCode(int code) {
return code > 399 && code < 500;
}

/**
* 5XX Server Error
*
* @param code
* @return
*/
private boolean serverErrorCode(int code) {
return code > 499 && code < 600;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package com.alibaba.csp.sentinel.transport.heartbeat.client;

import com.alibaba.csp.sentinel.config.SentinelConfig;

import java.nio.charset.Charset;
import java.util.Map;

import com.alibaba.csp.sentinel.config.SentinelConfig;

/**
* Simple HTTP response representation.
*
Expand Down Expand Up @@ -112,10 +112,12 @@ public String getBodyAsString() {
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(statusLine)
.append("\r\n");
for (Map.Entry<String, String> entry : headers.entrySet()) {
buf.append(entry.getKey()).append(": ").append(entry.getValue())
.append("\r\n");
if (headers != null) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
buf.append(entry.getKey()).append(": ").append(entry.getValue())
.append("\r\n");
}
}
buf.append("\r\n");
buf.append(getBodyAsString());
Expand Down