Skip to content

Commit 6df19e9

Browse files
committed
[alibaba#289]fix grpc-adapter bug
2 parents 6344523 + ad1d9f0 commit 6df19e9

File tree

7 files changed

+70
-17
lines changed

7 files changed

+70
-17
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ try {
7676
}
7777
```
7878

79-
So far the code modification is done.
79+
So far the code modification is done. We also provide [annotation support module](https://github.com/alibaba/Sentinel/blob/master/sentinel-extension/sentinel-annotation-aspectj/README.md) to define resource easier.
8080

8181
### 3. Define Rules
8282

@@ -93,6 +93,8 @@ rules.add(rule);
9393
FlowRuleManager.loadRules(rules);
9494
```
9595

96+
For more information, please refer to [How To Use](https://github.com/alibaba/Sentinel/wiki/How-to-Use).
97+
9698
### 4. Check the Result
9799

98100
After running the demo for a while, you can see the following records in `~/logs/csp/${appName}-metrics.log`.
@@ -144,3 +146,12 @@ These are only part of the companies using Sentinel, for reference only. If you
144146
![Taiping Renshou](http://www.cntaiping.com/tplresource/cms/www/taiping/img/home_new/tp_logo_img.png)
145147
![Shunfeng Technology](https://user-images.githubusercontent.com/9434884/48463502-2f48eb80-e817-11e8-984f-2f9b1b789e2d.png)
146148
![Mandao](https://user-images.githubusercontent.com/9434884/48463559-6cad7900-e817-11e8-87e4-42952b074837.png)
149+
![每日优鲜](https://home.missfresh.cn/statics/img/logo.png)
150+
![二维火](https://user-images.githubusercontent.com/9434884/49358468-bc43de00-f70d-11e8-97fe-0bf05865f29f.png)
151+
![文轩在线](http://static.winxuancdn.com/css/v2/images/logo.png)
152+
![客如云](https://www.keruyun.com/static/krynew/images/logo.png)
153+
![亲宝宝](https://stlib.qbb6.com/wclt/img/home_hd/version1/title_logo.png)
154+
![杭州光云科技](https://www.raycloud.com/images/logo.png)
155+
![金汇金融](https://res.jinhui365.com/r/images/logo2.png?v=1.527)
156+
![Vivo](https://user-images.githubusercontent.com/9434884/49355264-c6f87600-f701-11e8-8109-054cf91df868.png)
157+
![闪电购](http://cdn.52shangou.com/shandianbang/official-source/3.1.1/build/images/logo.png)

sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ angular.module('sentinelDashboardApp')
3333

3434
// toggle side bar
3535
$scope.click = function ($event) {
36-
let element = angular.element($event.target);
3736
let entry = angular.element($event.target).scope().entry;
38-
entry.active = !entry.active;
37+
entry.active = !entry.active;// toggle this clicked app bar
3938

40-
if (entry.active === false) {
41-
element.parent().children('ul').hide();
42-
} else {
43-
element.parent().parent().children('li').children('ul').hide();
44-
element.parent().children('ul').show();
45-
}
39+
$scope.apps.forEach(function (item) {// collapse other app bars
40+
if (item != entry) {
41+
item.active = false;
42+
}
43+
});
4644
};
4745

4846
/**

sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport/config/TransportConfig.java

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package com.alibaba.csp.sentinel.transport.config;
1717

1818
import com.alibaba.csp.sentinel.config.SentinelConfig;
19+
import com.alibaba.csp.sentinel.util.HostNameUtil;
20+
import com.alibaba.csp.sentinel.util.StringUtil;
1921

2022
/**
2123
* @author leyou
@@ -25,6 +27,7 @@ public class TransportConfig {
2527
public static final String CONSOLE_SERVER = "csp.sentinel.dashboard.server";
2628
public static final String SERVER_PORT = "csp.sentinel.api.port";
2729
public static final String HEARTBEAT_INTERVAL_MS = "csp.sentinel.heartbeat.interval.ms";
30+
public static final String HEARTBEAT_CLIENT_IP = "csp.sentinel.heartbeat.client.ip";
2831

2932
private static int runtimePort = -1;
3033

@@ -66,4 +69,18 @@ public static String getPort() {
6669
public static void setRuntimePort(int port) {
6770
runtimePort = port;
6871
}
72+
73+
/**
74+
* Get heartbeat client local ip.
75+
* If the client ip not configured,it will be the address of local host
76+
*
77+
* @return the local ip.
78+
*/
79+
public static String getHeartbeatClientIp() {
80+
String ip = SentinelConfig.getConfig(HEARTBEAT_CLIENT_IP);
81+
if (StringUtil.isBlank(ip)) {
82+
ip = HostNameUtil.getIp();
83+
}
84+
return ip;
85+
}
6986
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.alibaba.csp.sentinel.transport.config;
2+
3+
import com.alibaba.csp.sentinel.config.SentinelConfig;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.*;
7+
8+
public class TransportConfigTest {
9+
10+
@Test
11+
public void getClientIp() {
12+
//config heartbeat client ip
13+
System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP, "10.10.10.10");
14+
String ip = TransportConfig.getHeartbeatClientIp();
15+
16+
assertNotNull(ip);
17+
assertEquals(ip, "10.10.10.10");
18+
19+
//no heartbeat client ip
20+
SentinelConfig.setConfig(TransportConfig.HEARTBEAT_CLIENT_IP, "");
21+
ip = TransportConfig.getHeartbeatClientIp();
22+
assertNotNull(ip);
23+
24+
}
25+
}

sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSender.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public boolean sendHeartbeat() throws Exception {
8585
.setParameter("v", Constants.SENTINEL_VERSION)
8686
.setParameter("version", String.valueOf(System.currentTimeMillis()))
8787
.setParameter("hostname", HostNameUtil.getHostName())
88-
.setParameter("ip", HostNameUtil.getIp())
88+
.setParameter("ip", TransportConfig.getHeartbeatClientIp())
8989
.setParameter("port", TransportConfig.getPort())
9090
.setParameter("pid", String.valueOf(PidUtil.getPid()));
9191

sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
import java.net.ServerSocket;
2020
import java.net.Socket;
2121
import java.net.SocketException;
22-
import java.util.HashMap;
2322
import java.util.Map;
2423
import java.util.Map.Entry;
2524
import java.util.Set;
2625
import java.util.concurrent.ArrayBlockingQueue;
26+
import java.util.concurrent.ConcurrentHashMap;
2727
import java.util.concurrent.ExecutorService;
2828
import java.util.concurrent.Executors;
2929
import java.util.concurrent.RejectedExecutionException;
@@ -53,7 +53,7 @@ public class SimpleHttpCommandCenter implements CommandCenter {
5353
private static final int DEFAULT_PORT = 8719;
5454

5555
@SuppressWarnings("rawtypes")
56-
private static final Map<String, CommandHandler> handlerMap = new HashMap<String, CommandHandler>();
56+
private static final Map<String, CommandHandler> handlerMap = new ConcurrentHashMap<String, CommandHandler>();
5757

5858
private ExecutorService executor = Executors.newSingleThreadExecutor(
5959
new NamedThreadFactory("sentinel-command-center-executor"));
@@ -105,12 +105,14 @@ public void run() {
105105
executor.submit(new ServerThread(serverSocket));
106106
success = true;
107107
port = serverSocket.getLocalPort();
108+
} else {
109+
CommandCenterLog.info("[CommandCenter] chooses port fail, http command center will not work");
108110
}
109111

110112
if (!success) {
111113
port = PORT_UNINITIALIZED;
112114
}
113-
115+
114116
TransportConfig.setRuntimePort(port);
115117
executor.shutdown();
116118
}
@@ -119,11 +121,11 @@ public void run() {
119121

120122
new Thread(serverInitTask).start();
121123
}
122-
124+
123125
/**
124126
* Get a server socket from an available port from a base port.<br>
125127
* Increasing on port number will occur when the port has already been used.
126-
*
128+
*
127129
* @param basePort base port to start
128130
* @return new socket with available port
129131
*/
@@ -135,7 +137,7 @@ private static ServerSocket getServerSocketFromBasePort(int basePort) {
135137
server.setReuseAddress(true);
136138
return server;
137139
} catch (IOException e) {
138-
tryCount ++;
140+
tryCount++;
139141
try {
140142
TimeUnit.MILLISECONDS.sleep(30);
141143
} catch (InterruptedException e1) {

sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/HeartbeatMessage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class HeartbeatMessage {
3636

3737
public HeartbeatMessage() {
3838
message.put("hostname", HostNameUtil.getHostName());
39-
message.put("ip", HostNameUtil.getIp());
39+
message.put("ip", TransportConfig.getHeartbeatClientIp());
4040
message.put("app", AppNameUtil.getAppName());
4141
message.put("port", String.valueOf(TransportConfig.getPort()));
4242
}

0 commit comments

Comments
 (0)