Skip to content

Commit 05f80fc

Browse files
yu199195xiaoyu137
andauthored
add shenyu actuator endpoint (#4637)
Co-authored-by: xiaoyu137 <[email protected]>
1 parent 3ee258a commit 05f80fc

4 files changed

Lines changed: 147 additions & 7 deletions

File tree

‎shenyu-bootstrap/src/main/resources/application.yml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,17 @@ eureka:
6262

6363
management:
6464
health:
65-
defaults:
65+
redis:
6666
enabled: false
67+
endpoint:
68+
health:
69+
enabled: true
70+
show-details: always
71+
endpoints:
72+
web:
73+
exposure:
74+
include: "*" # or health,info
75+
6776

6877
shenyu:
6978
matchCache:
@@ -249,7 +258,7 @@ shenyu:
249258
- /fallback/resilience4j
250259
- /fallback/sentinel
251260
health:
252-
enabled: false
261+
enabled: true
253262
paths:
254263
- /actuator
255264
- /health_check

‎shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/BaseDataCache.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,34 @@ public void cleanRuleDataSelf(final List<RuleData> ruleDataList) {
231231
public List<RuleData> obtainRuleData(final String selectorId) {
232232
return RULE_MAP.get(selectorId);
233233
}
234+
235+
/**
236+
* Gets plugin map.
237+
*
238+
* @return the plugin map
239+
*/
240+
public ConcurrentMap<String, PluginData> getPluginMap() {
241+
return PLUGIN_MAP;
242+
}
243+
244+
/**
245+
* Gets selector map.
246+
*
247+
* @return the selector map
248+
*/
249+
public ConcurrentMap<String, List<SelectorData>> getSelectorMap() {
250+
return SELECTOR_MAP;
251+
}
252+
253+
/**
254+
* Gets rule map.
255+
*
256+
* @return the rule map
257+
*/
258+
public ConcurrentMap<String, List<RuleData>> getRuleMap() {
259+
return RULE_MAP;
260+
}
261+
234262

235263
/**
236264
* cache rule data.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shenyu.web.endpoint;
19+
20+
import org.apache.shenyu.common.dto.PluginData;
21+
import org.apache.shenyu.common.dto.RuleData;
22+
import org.apache.shenyu.common.dto.SelectorData;
23+
import org.apache.shenyu.plugin.api.ShenyuPlugin;
24+
import org.apache.shenyu.plugin.base.cache.BaseDataCache;
25+
import org.apache.shenyu.web.handler.ShenyuWebHandler;
26+
import org.springframework.http.MediaType;
27+
import org.springframework.web.bind.annotation.GetMapping;
28+
import org.springframework.web.bind.annotation.RequestMapping;
29+
import org.springframework.web.bind.annotation.RestController;
30+
import reactor.core.publisher.Flux;
31+
32+
import java.util.List;
33+
import java.util.Map;
34+
import java.util.stream.Collectors;
35+
36+
/**
37+
* The type Shenyu controller endpoint.
38+
*/
39+
@RestController
40+
@RequestMapping(value = "/actuator", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
41+
public class ShenyuControllerEndpoint {
42+
43+
private final ShenyuWebHandler webHandler;
44+
45+
/**
46+
* Instantiates a new Shenyu controller endpoint.
47+
*
48+
* @param webHandler the web handler
49+
*/
50+
public ShenyuControllerEndpoint(final ShenyuWebHandler webHandler) {
51+
this.webHandler = webHandler;
52+
}
53+
54+
/**
55+
* Plugins flux.
56+
*
57+
* @return the flux
58+
*/
59+
@GetMapping("/plugins")
60+
public Flux<Map<String, Integer>> plugins() {
61+
List<ShenyuPlugin> plugins = webHandler.getPlugins();
62+
return Flux.just(plugins.stream().collect(Collectors.toMap(ShenyuPlugin::toString, ShenyuPlugin::getOrder)));
63+
}
64+
65+
/**
66+
* Plugin datas flux.
67+
*
68+
* @return the flux
69+
*/
70+
@GetMapping("/pluginData")
71+
public Flux<Map<String, PluginData>> pluginDatas() {
72+
return Flux.just(BaseDataCache.getInstance().getPluginMap());
73+
}
74+
75+
/**
76+
* Selector data flux.
77+
*
78+
* @return the flux
79+
*/
80+
@GetMapping("/selectorData")
81+
public Flux<Map<String, List<SelectorData>>> selectorData() {
82+
return Flux.just(BaseDataCache.getInstance().getSelectorMap());
83+
}
84+
85+
/**
86+
* Rule data flux.
87+
*
88+
* @return the flux
89+
*/
90+
@GetMapping("/ruleData")
91+
public Flux<Map<String, List<RuleData>>> ruleData() {
92+
return Flux.just(BaseDataCache.getInstance().getRuleMap());
93+
}
94+
}

‎shenyu-web/src/main/java/org/apache/shenyu/web/handler/ShenyuWebHandler.java‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ public final class ShenyuWebHandler implements WebHandler, ApplicationListener<P
6767
private final boolean scheduled;
6868

6969
private Scheduler scheduler;
70-
70+
7171
/**
7272
* Instantiates a new shenyu web handler.
7373
*
74-
* @param plugins the plugins
74+
* @param plugins the plugins
7575
* @param shenyuLoaderService shenyuLoaderService
76-
* @param shenyuConfig plugins config
76+
* @param shenyuConfig plugins config
7777
*/
7878
public ShenyuWebHandler(final List<ShenyuPlugin> plugins, final ShenyuLoaderService shenyuLoaderService, final ShenyuConfig shenyuConfig) {
7979
this.sourcePlugins = new ArrayList<>(plugins);
@@ -104,7 +104,16 @@ public Mono<Void> handle(@NonNull final ServerWebExchange exchange) {
104104
}
105105
return execute;
106106
}
107-
107+
108+
/**
109+
* Gets plugins.
110+
*
111+
* @return the plugins
112+
*/
113+
public List<ShenyuPlugin> getPlugins() {
114+
return plugins;
115+
}
116+
108117
/**
109118
* Put ext plugins.
110119
*
@@ -224,7 +233,7 @@ private static class DefaultShenyuPluginChain implements ShenyuPluginChain {
224233
private int index;
225234

226235
private final List<ShenyuPlugin> plugins;
227-
236+
228237
/**
229238
* Instantiates a new Default shenyu plugin chain.
230239
*

0 commit comments

Comments
 (0)