ソースを参照

:recycle: 重构代码。 gateway 降级获取原请求 ,docker-compose优化,日志优化

冷冷 6 年 前
コミット
02846103cd

+ 0 - 35
docker-compose.yml

@@ -5,14 +5,12 @@ services:
     ports:
       - 2181:2181
     restart: always
-    container_name: pigx-zookeeper
 
   pigx-redis:
     image: redis:4.0.10
     ports:
       - 6379:6379
     restart: always
-    container_name: pigx-redis
 
   pigx-eureka:
     build:
@@ -21,88 +19,56 @@ services:
     restart: always
     ports:
       - 1025:1025
-    container_name: pigx-eureka
 
   pigx-config:
-    links:
-      - pigx-eureka
     build:
       context: ./
       dockerfile: ./pigx-config/Dockerfile
     restart: always
-    container_name: pigx-config
 
   pigx-gateway:
-    links:
-      - pigx-eureka
-      - pigx-redis
     build:
       context: ./
       dockerfile: ./pigx-gateway/Dockerfile
     restart: always
     ports:
       - 9999:9999
-    container_name: pigx-gateway
 
   pigx-auth:
-    links:
-      - pigx-eureka
-      - pigx-redis
     build:
       context: ./
       dockerfile: ./pigx-auth/Dockerfile
     restart: always
-    container_name: pigx-auth
 
   pigx-upms:
-    links:
-      - pigx-eureka
-      - pigx-redis
-      - pigx-gateway
     build:
       context: ./
       dockerfile: ./pigx-upms/pigx-upms-biz/Dockerfile
     restart: always
-    container_name: pigx-upms
 
   pigx-monitor:
-    links:
-      - pigx-eureka
-      - pigx-redis
     build:
       context: ./
       dockerfile: ./pigx-visual/pigx-monitor/Dockerfile
     restart: always
     ports:
       - 5001:5001
-    container_name: pigx-monitor
 
   pigx-daemon:
-    links:
-      - pigx-eureka
-      - pigx-redis
     build:
       context: ./
       dockerfile: ./pigx-visual/pigx-daemon/Dockerfile
     restart: always
     ports:
       - 5002:5002
-    container_name: pigx-daemon
 
   pigx-codegen:
-    links:
-      - pigx-eureka
-      - pigx-redis
     build:
       context: ./
       dockerfile: ./pigx-visual/pigx-codegen/Dockerfile
     restart: always
-    container_name: pigx-codegen
 
   pigx-tx-manager:
-    links:
-      - pigx-eureka
-      - pigx-redis
     build:
       context: ./
       dockerfile: ./pigx-visual/pigx-tx-manager/Dockerfile
@@ -110,4 +76,3 @@ services:
     ports:
       - 5004:5004
       - 9998:9998
-    container_name: pigx-tx-manager

+ 1 - 1
pigx-common/pigx-common-core/src/main/resources/logback-spring.xml

@@ -21,7 +21,7 @@
 	<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
 		<file>${log.path}/debug.log</file>
 		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
-			<fileNamePattern>${log.path}/%d{yyyy-MM}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
+			<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
 			<maxFileSize>50MB</maxFileSize>
 			<maxHistory>30</maxHistory>
 		</rollingPolicy>

+ 2 - 2
pigx-config/src/main/resources/logback-spring.xml

@@ -21,7 +21,7 @@
 	<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
 		<file>${log.path}/debug.log</file>
 		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
-			<fileNamePattern>${log.path}/%d{yyyy-MM}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
+			<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
 			<maxFileSize>50MB</maxFileSize>
 			<maxHistory>30</maxHistory>
 		</rollingPolicy>
@@ -34,7 +34,7 @@
 	<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
 		<file>${log.path}/error.log</file>
 		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
-			<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
+			<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
 			<maxFileSize>50MB</maxFileSize>
 			<maxHistory>30</maxHistory>
 		</rollingPolicy>

+ 1 - 1
pigx-eureka/src/main/resources/logback-spring.xml

@@ -21,7 +21,7 @@
 	<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
 		<file>${log.path}/debug.log</file>
 		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
-			<fileNamePattern>${log.path}/%d{yyyy-MM}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
+			<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
 			<maxFileSize>50MB</maxFileSize>
 			<maxHistory>30</maxHistory>
 		</rollingPolicy>

+ 8 - 1
pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handler/HystrixFallbackHandler.java

@@ -27,6 +27,10 @@ import org.springframework.web.reactive.function.server.ServerRequest;
 import org.springframework.web.reactive.function.server.ServerResponse;
 import reactor.core.publisher.Mono;
 
+import java.util.Optional;
+
+import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR;
+
 /**
  * @author lengleng
  * @date 2018/7/5
@@ -37,7 +41,10 @@ import reactor.core.publisher.Mono;
 public class HystrixFallbackHandler implements HandlerFunction<ServerResponse> {
 	@Override
 	public Mono<ServerResponse> handle(ServerRequest serverRequest) {
-		log.error("网关执行请求:{}失败,hystrix服务降级处理", serverRequest.uri());
+		Optional<Object> originalUris = serverRequest.attribute(GATEWAY_ORIGINAL_REQUEST_URL_ATTR);
+
+		originalUris.ifPresent(originalUri -> log.error("网关执行请求:{}失败,hystrix服务降级处理", originalUri));
+
 		return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
 			.contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromObject("服务异常"));
 	}