From ecb238740c48fc7a775abf3af5ac318511344868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Fri, 16 Oct 2020 13:39:49 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20#1?= =?UTF-8?q?934=20=E6=89=80=E6=9C=89=E6=9C=8D=E5=8A=A1=E9=83=BD=E6=8E=A5?= =?UTF-8?q?=E5=85=A5=E5=88=B0=20Spring=20Boot=20Admin=20=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit :sparkles: Introducing new features. #1934 所有服务都接入到 Spring Boot Admin 监控 --- pigx-register/src/main/resources/application.yml | 15 +++++++++++++++ pigx-visual/pigx-sentinel-dashboard/pom.xml | 5 +++++ .../auth/LoginAuthenticationFilter.java | 16 +++++++++------- .../src/main/resources/application.yml | 15 +++++++++++---- .../src/main/resources/bootstrap.yml | 15 +++++++++++++++ 5 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 pigx-visual/pigx-sentinel-dashboard/src/main/resources/bootstrap.yml diff --git a/pigx-register/src/main/resources/application.yml b/pigx-register/src/main/resources/application.yml index 133e2ef95..231bc2613 100755 --- a/pigx-register/src/main/resources/application.yml +++ b/pigx-register/src/main/resources/application.yml @@ -21,15 +21,30 @@ nacos: urls: /,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/** spring: + application: + name: @artifactId@ datasource: platform: mysql security: enabled: true + boot: # 接入 spring boot admin + admin: + client: + url: http://pigx-monitor:5001 + username: pigx + password: pigx useAddressServer: true # 关闭监控埋点采集 management: + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: always metrics: export: elastic: diff --git a/pigx-visual/pigx-sentinel-dashboard/pom.xml b/pigx-visual/pigx-sentinel-dashboard/pom.xml index 28da71160..cfd74c39d 100755 --- a/pigx-visual/pigx-sentinel-dashboard/pom.xml +++ b/pigx-visual/pigx-sentinel-dashboard/pom.xml @@ -13,6 +13,11 @@ jar + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + com.alibaba.csp sentinel-core diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/LoginAuthenticationFilter.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/LoginAuthenticationFilter.java index aab3a5112..cd2c2243d 100644 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/LoginAuthenticationFilter.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/LoginAuthenticationFilter.java @@ -20,16 +20,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import org.springframework.util.AntPathMatcher; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; +import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import java.io.IOException; import java.util.List; @@ -59,6 +54,8 @@ public class LoginAuthenticationFilter implements Filter { private static final String URL_SUFFIX_DOT = "."; + private static final AntPathMatcher PATH_MATCHER = new AntPathMatcher(); + /** * Some urls which needn't auth, such as /auth/login, /registry/machine and so on. */ @@ -90,6 +87,10 @@ public class LoginAuthenticationFilter implements Filter { String servletPath = httpRequest.getServletPath(); // Exclude the urls which needn't auth + if (authFilterExcludeUrls.stream().anyMatch(s -> PATH_MATCHER.match(s,servletPath))){ + chain.doFilter(request, response); + return; + } if (authFilterExcludeUrls.contains(servletPath)) { chain.doFilter(request, response); return; @@ -106,6 +107,7 @@ public class LoginAuthenticationFilter implements Filter { authFilterExcludeUrlSuffix = URL_SUFFIX_DOT + authFilterExcludeUrlSuffix; } + if (servletPath.endsWith(authFilterExcludeUrlSuffix)) { chain.doFilter(request, response); return; diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/resources/application.yml b/pigx-visual/pigx-sentinel-dashboard/src/main/resources/application.yml index d85b338e5..8cea8bd13 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/resources/application.yml +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/resources/application.yml @@ -1,10 +1,17 @@ server: port: 5020 - -spring: - http: + servlet: encoding: force: true + +management: + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: ALWAYS logging: level: org: @@ -19,7 +26,7 @@ auth: username: sentinel password: sentinel filter: - exclude-urls: /,/auth/login,/auth/logout,/registry/machine,/version + exclude-urls: /,/auth/login,/auth/logout,/registry/machine,/version,/actuator/**,/details exclude-url-suffixes: htm,html,js,css,map,ico,ttf,woff,png sentinel: diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/resources/bootstrap.yml b/pigx-visual/pigx-sentinel-dashboard/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..0e47b57b1 --- /dev/null +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/resources/bootstrap.yml @@ -0,0 +1,15 @@ +server: + port: 5020 + servlet: + encoding: + force: true + +spring: + application: + name: @artifactId@ + cloud: + nacos: + discovery: + server-addr: ${NACOS_HOST:pigx-register}:${NACOS_PORT:8848} + profiles: + active: @profiles.active@ \ No newline at end of file