You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by be...@apache.org on 2022/11/10 14:10:28 UTC
[incubator-streampark] branch dev updated: [Feature] Add probes for liveness check. (#1953)
This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
The following commit(s) were added to refs/heads/dev by this push:
new 8687f56f0 [Feature] Add probes for liveness check. (#1953)
8687f56f0 is described below
commit 8687f56f0a5edb4888ed395eb13457f9b49ce5db
Author: lvshaokang <lv...@hotmail.com>
AuthorDate: Thu Nov 10 22:10:22 2022 +0800
[Feature] Add probes for liveness check. (#1953)
* [Feature] Add probes for liveness check
* code format
---
.../streampark-console-service/pom.xml | 5 +++
.../console/base/config/SwaggerConfig.java | 44 ++++++++++++++++++++++
.../console/system/authentication/ShiroConfig.java | 1 +
.../src/main/resources/application.yml | 8 +++-
4 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/streampark-console/streampark-console-service/pom.xml b/streampark-console/streampark-console-service/pom.xml
index b484e857b..8ce559f52 100644
--- a/streampark-console/streampark-console-service/pom.xml
+++ b/streampark-console/streampark-console-service/pom.xml
@@ -155,6 +155,11 @@
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SwaggerConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SwaggerConfig.java
index 2fbbba8a3..2a43798e6 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SwaggerConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SwaggerConfig.java
@@ -19,9 +19,23 @@ package org.apache.streampark.console.base.config;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
+import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
+import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
+import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
+import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
+import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
+import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
+import org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint;
+import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier;
+import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
+import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
+import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+import org.springframework.util.StringUtils;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
@@ -35,7 +49,10 @@ import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContextBuilder;
import springfox.documentation.spring.web.plugins.Docket;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.List;
@Configuration
@EnableOpenApi
@@ -76,4 +93,31 @@ public class SwaggerConfig implements WebMvcConfigurer {
.build();
}
+ /**
+ * Streampark used `ant_path_matcher` as default matching-strategy in the springboot 2.6+ version,
+ * but actuator endpoint used `PathPattern` based URL matching.
+ * So rewrite webEndpointServletHandlerMapping @Bean for resolve springfox and actuator conflicts.
+ */
+ @Bean
+ public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
+ WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier,
+ ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes,
+ CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
+ List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
+ Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
+ allEndpoints.addAll(webEndpoints);
+ allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
+ allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
+ String basePath = webEndpointProperties.getBasePath();
+ EndpointMapping endpointMapping = new EndpointMapping(basePath);
+ boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
+ return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
+ corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath),
+ shouldRegisterLinksMapping, null);
+ }
+
+ private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
+ return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
+ }
+
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroConfig.java
index 07dcd181e..367a8837e 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroConfig.java
@@ -41,6 +41,7 @@ public class ShiroConfig {
shiroFilterFactoryBean.setFilters(filters);
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
+ filterChainDefinitionMap.put("/actuator/**", "anon");
filterChainDefinitionMap.put("/doc.html", "anon");
filterChainDefinitionMap.put("/swagger-ui/**", "anon");
filterChainDefinitionMap.put("/swagger-resources", "anon");
diff --git a/streampark-console/streampark-console-service/src/main/resources/application.yml b/streampark-console/streampark-console-service/src/main/resources/application.yml
index 4cb829ce5..33bab5c75 100644
--- a/streampark-console/streampark-console-service/src/main/resources/application.yml
+++ b/streampark-console/streampark-console-service/src/main/resources/application.yml
@@ -63,7 +63,13 @@ management:
endpoints:
web:
exposure:
- include: [ 'httptrace', 'metrics' ]
+ include: [ 'health', 'httptrace', 'metrics' ]
+ endpoint:
+ health:
+ enabled: true
+ show-details: always
+ probes:
+ enabled: true
# mybatis plus setting
mybatis-plus: