Skip to content

Commit 0b5a197

Browse files
committed
chore: modify return value format
1 parent 3dd8c7a commit 0b5a197

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

mse-simple-demo/A/src/main/java/com/alibabacloud/mse/demo/a/AController.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ public String a() throws ExecutionException, InterruptedException {
8484
//这是rpc调用的方式
8585
String result = restTemplate.getForObject("http://sc-B/b", String.class);
8686

87-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
87+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
8888
"[config=" + configValue + "]" + " -> " + result;
8989
}
9090

9191
@ApiOperation(value = "HTTP 全链路灰度入口 a调用b和c", tags = {"入口应用"})
9292
@GetMapping("/a2bc")
9393
public String a2bc() throws ExecutionException, InterruptedException {
9494

95-
String resultB = "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
95+
String resultB = "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
9696
"[config=" + configValue + "]" + " -> " + restTemplate.getForObject("http://sc-B/b", String.class);
97-
String resultA = "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
97+
String resultA = "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
9898
"[config=" + configValue + "]" + " -> " + restTemplate.getForObject("http://sc-C/c", String.class);
9999

100100
return resultA + "\n" + resultB;
@@ -106,7 +106,7 @@ public String aByFeign() throws ExecutionException, InterruptedException {
106106

107107
String result = feignClient.bByFeign("test");
108108

109-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
109+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
110110
"[config=" + configValue + "]" + " -> " + result;
111111
}
112112

@@ -118,7 +118,7 @@ public String flow() throws ExecutionException, InterruptedException {
118118
HttpStatus status = responseEntity.getStatusCode();
119119
String result = responseEntity.getBody() + " code:" + status.value();
120120

121-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
121+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
122122
"[config=" + configValue + "]" + " -> " + result;
123123
}
124124

@@ -131,7 +131,7 @@ public String params(@PathVariable("hot") String hot) throws ExecutionException,
131131
HttpStatus status = responseEntity.getStatusCode();
132132
String result = responseEntity.getBody() + " code:" + status.value();
133133

134-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
134+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
135135
"[config=" + configValue + "]" + " params:" + hot + " -> " + result;
136136
}
137137

@@ -143,7 +143,7 @@ public String isolate() throws ExecutionException, InterruptedException {
143143
HttpStatus status = responseEntity.getStatusCode();
144144
String result = responseEntity.getBody() + " code:" + status.value();
145145

146-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
146+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
147147
"[config=" + configValue + "]" + " -> " + result;
148148
}
149149

@@ -158,50 +158,50 @@ public String sql(@RequestParam Map<String, String> allRequestParams) throws Uns
158158
url.append("&");
159159
}
160160
String result = restTemplate.getForObject(url.toString(), String.class);
161-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
161+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
162162
"[config=" + configValue + "]" + " -> " + result;
163163
}
164164

165165
@ApiOperation(value = "HTTP 全链路灰度入口", tags = {"入口应用"})
166166
@GetMapping("/a-zone")
167167
public String aZone() {
168-
return "A" + serviceTag + "[" + currentZone + "]" + " -> " +
168+
return "A[tag=" + serviceTag + "][" + currentZone + "]" + " -> " +
169169
restTemplate.getForObject("http://sc-B/b-zone", String.class);
170170
}
171171

172172
@ApiOperation(value = "Dubbo 全链路灰度入口", tags = {"入口应用"})
173173
@GetMapping("/dubbo")
174174
public String dubbo(@RequestParam(required = false) String param) {
175-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
175+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
176176
helloServiceB.hello(param);
177177
}
178178

179179

180180
@ApiOperation(value = "Dubbo 全链路灰度入口", tags = {"入口应用"})
181181
@GetMapping("/dubbo2")
182182
public String dubbo2(@RequestParam Map<String,String> allRequestParams) {
183-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
183+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
184184
helloServiceBTwo.hello2(JSON.toJSONString(allRequestParams));
185185
}
186186

187187
@ApiOperation(value = "Dubbo 限流测试", tags = {"入口应用"})
188188
@GetMapping("/dubbo-flow")
189189
public String dubbo_flow() {
190-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
190+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
191191
helloServiceB.hello("A");
192192
}
193193

194194
@ApiOperation(value = "Dubbo 热点测试", tags = {"入口应用"})
195195
@GetMapping("/dubbo-params/{hot}")
196196
public String dubbo_params(@PathVariable("hot") String hot) {
197-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " params:" + hot + " -> " +
197+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " params:" + hot + " -> " +
198198
helloServiceB.hello(hot);
199199
}
200200

201201
@ApiOperation(value = "Dubbo 隔离测试", tags = {"入口应用"})
202202
@GetMapping("/dubbo-isolate")
203203
public String dubbo_isolate() {
204-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
204+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
205205
helloServiceB.hello("isolate");
206206
}
207207

@@ -211,7 +211,7 @@ public String circuit_breaker_rt() throws ExecutionException, InterruptedExcepti
211211

212212
String result = feignClient.circuit_breaker_rt_b();
213213

214-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
214+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
215215
"[config=" + configValue + "]" + " -> " + result;
216216
}
217217

@@ -220,7 +220,7 @@ public String circuit_breaker_rt() throws ExecutionException, InterruptedExcepti
220220
public String circuit_breaker_exception() throws ExecutionException, InterruptedException {
221221
String result = feignClient.circuit_breaker_exception_b();
222222

223-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
223+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
224224
"[config=" + configValue + "]" + " -> " + result;
225225
}
226226

@@ -235,7 +235,7 @@ public String swagger(@ApiParam(name = "name", value = "我是姓名", required
235235
@ApiOperation(value = "Dubbo rt 熔断测试", tags = {"入口应用"})
236236
@GetMapping("/dubbo-circuit-breaker-rt")
237237
public String dubbo_circuit_breaker_rt() {
238-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
238+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
239239
helloServiceB.slow();
240240
}
241241

@@ -252,6 +252,6 @@ public String dubbo_circuit_breaker_exception() {
252252
response = "Service is in abnormal status and throws exception by itself!";
253253
}
254254
}
255-
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " + response;
255+
return "A[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " + response;
256256
}
257257
}

mse-simple-demo/B/src/main/java/com/alibabacloud/mse/demo/b/BController.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,34 +69,34 @@ public String flow() throws ExecutionException, InterruptedException {
6969
long sleepTime = 5 + RANDOM.nextInt(5);
7070
silentSleep(sleepTime);
7171
String result = restTemplate.getForObject("http://sc-C/flow", String.class);
72-
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime + " -> " + result;
72+
return "B[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime + " -> " + result;
7373
}
7474

7575
@GetMapping("/params/{hot}")
7676
public String params(@PathVariable("hot") String hot) throws ExecutionException, InterruptedException {
7777
long sleepTime = 5 + RANDOM.nextInt(5);
7878
silentSleep(sleepTime);
7979
String result = restTemplate.getForObject("http://sc-C/params/" + hot, String.class);
80-
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime + " params:" + hot + " -> " + result;
80+
return "B[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime + " params:" + hot + " -> " + result;
8181
}
8282

8383
@GetMapping("/isolate")
8484
public String isolate() throws ExecutionException, InterruptedException {
8585
long sleepTime = 500 + RANDOM.nextInt(5);
8686
silentSleep(sleepTime);
8787
String result = restTemplate.getForObject("http://sc-C/isolate", String.class);
88-
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime + " -> " + result;
88+
return "B[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime + " -> " + result;
8989
}
9090

9191
@GetMapping("/b")
9292
public String b() {
93-
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
93+
return "B[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
9494
restTemplate.getForObject("http://sc-C/c", String.class);
9595
}
9696

9797
@GetMapping("/bByFeign")
9898
public String bByFeign(String s) {
99-
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]";
99+
return "B[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]";
100100
}
101101

102102
@GetMapping("/circuit-breaker-rt-b")
@@ -112,7 +112,7 @@ public String circuit_breaker_rt_b() {
112112

113113
String slowMessage = isSlowRequest ? " RT:" + rt : "";
114114

115-
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + slowMessage;
115+
return "B[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + slowMessage;
116116
}
117117

118118
@GetMapping("/circuit-breaker-exception-b")
@@ -122,12 +122,12 @@ public String circuit_breaker_exception_b() {
122122
if (isExceptionRequest) {
123123
throw new RuntimeException("TestCircuitBreakerException");
124124
}
125-
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]";
125+
return "B[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]";
126126
}
127127

128128
@GetMapping("/b-zone")
129129
public String bZone() {
130-
return "B" + serviceTag + "[" + currentZone + "]" + " -> " +
130+
return "B[tag=" + serviceTag + "][" + currentZone + "]" + " -> " +
131131
restTemplate.getForObject("http://sc-C/c-zone", String.class);
132132
}
133133

@@ -162,7 +162,7 @@ public String sql(@RequestParam Map<String, String> allRequestParams) {
162162
List<User> list = user.selectAll();
163163
result = JSON.toJSONString(list);
164164
}
165-
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " result:" + result;
165+
return "B[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " result:" + result;
166166
}
167167

168168
@GetMapping("/set-traffic-attribute")

mse-simple-demo/C/src/main/java/com/alibabacloud/mse/demo/c/CController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public String c() {
6868
try (Entry entry1 = SphU.entry("HelloWorld-c-1", EntryType.IN)) {
6969
// 具体的业务逻辑
7070
try {
71-
return "C" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]";
71+
return "C[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]";
7272
} catch (Throwable e) {
7373
// 标记此次资源调用失败
7474
entry1.setError(e);
@@ -88,7 +88,7 @@ public String cZone() {
8888
try (Entry entry2 = SphU.entry("HelloWorld-c-2", EntryType.IN)) {
8989
try {
9090
log.debug("Hello Sentinel!2");
91-
return "C" + serviceTag + "[" + currentZone + "]";
91+
return "C[tag=" + serviceTag + "][" + currentZone + "]";
9292
} catch (Throwable e) {
9393
entry2.setError(e);
9494
throw e;
@@ -100,7 +100,7 @@ public String cZone() {
100100

101101
@GetMapping("/spring_boot")
102102
public String spring_boot() {
103-
return "C" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]";
103+
return "C[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]";
104104
}
105105

106106
@GetMapping("/flow")
@@ -112,7 +112,7 @@ public String flow() {
112112
try {
113113
long sleepTime = 5 + RANDOM.nextInt(5);
114114
silentSleep(sleepTime);
115-
return "C" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime;
115+
return "C[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime;
116116
} catch (Throwable throwable) {
117117
entry2.setError(throwable);
118118
entry1.setError(throwable);
@@ -130,14 +130,14 @@ public String flow() {
130130
public String params(@PathVariable("hot") String hot) throws ExecutionException, InterruptedException {
131131
long sleepTime = 5 + RANDOM.nextInt(5);
132132
silentSleep(sleepTime);
133-
return "C" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime + " params:" + hot;
133+
return "C[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime + " params:" + hot;
134134
}
135135

136136
@GetMapping("/isolate")
137137
public String isolate() throws ExecutionException, InterruptedException {
138138
long sleepTime = 5 + RANDOM.nextInt(5);
139139
silentSleep(sleepTime);
140-
return "C" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime;
140+
return "C[tag=" + serviceTag + "][" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime;
141141
}
142142

143143
private void silentSleep(long ms) {

0 commit comments

Comments
 (0)