From 1cc03c7cd18339d4402474191511cb2e592d1940 Mon Sep 17 00:00:00 2001 From: zhangqy Date: Mon, 6 Nov 2023 10:15:46 +0800 Subject: [PATCH] =?UTF-8?q?[test]=E6=B5=8B=E8=AF=95skywalking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/modules/user/deploy/deploy.yaml | 21 ++++- iot-modules/iot-box-user-api/pom.xml | 24 +++++- .../fliter/TraceResponseFilter.java | 25 ++++++ .../src/main/resources/logback-dev.xml | 84 ------------------- .../src/main/resources/logback-prod.xml | 84 ------------------- .../src/main/resources/logback-spring.xml | 82 ++++++++++++++++++ .../src/main/resources/logback-test.xml | 84 ------------------- 7 files changed, 149 insertions(+), 255 deletions(-) create mode 100644 iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/controller/fliter/TraceResponseFilter.java delete mode 100644 iot-modules/iot-box-user-api/src/main/resources/logback-dev.xml delete mode 100644 iot-modules/iot-box-user-api/src/main/resources/logback-prod.xml create mode 100644 iot-modules/iot-box-user-api/src/main/resources/logback-spring.xml delete mode 100644 iot-modules/iot-box-user-api/src/main/resources/logback-test.xml diff --git a/docker/modules/user/deploy/deploy.yaml b/docker/modules/user/deploy/deploy.yaml index 5c0f200..b356def 100644 --- a/docker/modules/user/deploy/deploy.yaml +++ b/docker/modules/user/deploy/deploy.yaml @@ -21,10 +21,25 @@ spec: labels: app: iot-box-user-api spec: + initContainers: + - name: agent-container + image: apache/skywalking-java-agent:8.7.0-alpine + volumeMounts: + - name: skywalking-agent + mountPath: /agent + command: [ "/bin/sh" ] + args: [ "-c", "cp -R /skywalking/agent /agent/" ] imagePullSecrets: - name: aliyun-hub-register #提前在项目下配置访问阿里云的账号密码 containers: - image: $REGISTRY/$DOCKERHUB_NAMESPACE/qiuguo-iot:iot-box-user-api-SNAPSHOT-v1.0.0 + env: + - name: JAVA_TOOL_OPTIONS + value: "-javaagent:/skywalking/agent/skywalking-agent.jar" + - name: SW_AGENT_NAME + value: "iot-box-user-api" + - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES + value: "skywalking-node.skywalking:8080" readinessProbe: httpGet: path: /actuator/health @@ -39,14 +54,14 @@ spec: protocol: TCP resources: requests: #资源请求的设置 - cpu: 0m #Cpu请求,容器启动的初始可用数量 memory: 600Mi #内存清楚,容器启动的初始可用数量 limits: - cpu: 80m memory: 600Mi volumeMounts: - mountPath: /home/qiuguo/logs name: iot-logs + - name: skywalking-agent + mountPath: /skywalking terminationMessagePath: /nfs/data/qiuguo/iot/logs terminationMessagePolicy: File dnsPolicy: ClusterFirst @@ -56,6 +71,8 @@ spec: - name: iot-logs hostPath: path: /nfs/data/qiuguo/iot/logs + - name: skywalking-agent + emptyDir: { } --- apiVersion: v1 kind: Service diff --git a/iot-modules/iot-box-user-api/pom.xml b/iot-modules/iot-box-user-api/pom.xml index 40c6cf7..59c6b9a 100644 --- a/iot-modules/iot-box-user-api/pom.xml +++ b/iot-modules/iot-box-user-api/pom.xml @@ -70,8 +70,30 @@ reactor-test test - + + org.apache.skywalking + apm-toolkit-trace + 8.7.0 + + + org.apache.skywalking + apm-toolkit-logback-1.x + 8.7.0 + + + + org.springframework + spring-web + + + org.springframework + spring-context + + + javax.servlet + javax.servlet-api + cn.hutool diff --git a/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/controller/fliter/TraceResponseFilter.java b/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/controller/fliter/TraceResponseFilter.java new file mode 100644 index 0000000..11775b3 --- /dev/null +++ b/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/controller/fliter/TraceResponseFilter.java @@ -0,0 +1,25 @@ +package com.qiuguo.iot.user.api.controller.fliter; + +import org.apache.skywalking.apm.toolkit.trace.TraceContext; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Component +public class TraceResponseFilter extends OncePerRequestFilter { + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + try{ + //设置skywalking的traceId + response.addHeader("traceId", TraceContext.traceId()); + }catch (Exception e){ + + } + filterChain.doFilter(request, response); + } +} diff --git a/iot-modules/iot-box-user-api/src/main/resources/logback-dev.xml b/iot-modules/iot-box-user-api/src/main/resources/logback-dev.xml deleted file mode 100644 index 258fc25..0000000 --- a/iot-modules/iot-box-user-api/src/main/resources/logback-dev.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - ${log.pattern} - UTF-8 - - - - - - ${log.path}/info.log - - - - ${log.path}/info.%d{yyyy-MM-dd}.log - - 60 - - - ${log.pattern} - UTF-8 - - - - INFO - - - - - - - ${log.path}/warn.log - - - - ${log.path}/wran.%d{yyyy-MM-dd}.log - - 60 - - - ${log.pattern} - UTF-8 - - - - WARN - - - - - ${log.path}/error.log - - - - ${log.path}/error.%d{yyyy-MM-dd}.log - - 60 - - - ${log.pattern} - UTF-8 - - - - ERROR - - - - - - - - - - - - \ No newline at end of file diff --git a/iot-modules/iot-box-user-api/src/main/resources/logback-prod.xml b/iot-modules/iot-box-user-api/src/main/resources/logback-prod.xml deleted file mode 100644 index 907eab0..0000000 --- a/iot-modules/iot-box-user-api/src/main/resources/logback-prod.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - ${log.pattern} - UTF-8 - - - - - - ${log.path}/info.log - - - - ${log.path}/info.%d{yyyy-MM-dd}.log - - 60 - - - ${log.pattern} - UTF-8 - - - - INFO - - - - - - - ${log.path}/warn.log - - - - ${log.path}/wran.%d{yyyy-MM-dd}.log - - 60 - - - ${log.pattern} - UTF-8 - - - - WARN - - - - - ${log.path}/error.log - - - - ${log.path}/error.%d{yyyy-MM-dd}.log - - 60 - - - ${log.pattern} - UTF-8 - - - - ERROR - - - - - - - - - - - - \ No newline at end of file diff --git a/iot-modules/iot-box-user-api/src/main/resources/logback-spring.xml b/iot-modules/iot-box-user-api/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..44e8b12 --- /dev/null +++ b/iot-modules/iot-box-user-api/src/main/resources/logback-spring.xml @@ -0,0 +1,82 @@ + + + ${HOSTNAME} + + + + + + + + + + + ${LOG_PATH}/application.${HOSTNAME}.log + + ${PATTERN} + + + ${LOG_PATH}/application.%d{yyyy-MM-dd}.${HOSTNAME}.log + + 30 + + + + + ${LOG_PATH}/sql.${HOSTNAME}.log + + ${PATTERN} + + + ${LOG_PATH}/sql.%d{yyyy-MM-dd}.${HOSTNAME}.log + + 3 + + + + + + + ${PATTERN} + + + + + + + + + ${SKY_PATTERN} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iot-modules/iot-box-user-api/src/main/resources/logback-test.xml b/iot-modules/iot-box-user-api/src/main/resources/logback-test.xml deleted file mode 100644 index 907eab0..0000000 --- a/iot-modules/iot-box-user-api/src/main/resources/logback-test.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - ${log.pattern} - UTF-8 - - - - - - ${log.path}/info.log - - - - ${log.path}/info.%d{yyyy-MM-dd}.log - - 60 - - - ${log.pattern} - UTF-8 - - - - INFO - - - - - - - ${log.path}/warn.log - - - - ${log.path}/wran.%d{yyyy-MM-dd}.log - - 60 - - - ${log.pattern} - UTF-8 - - - - WARN - - - - - ${log.path}/error.log - - - - ${log.path}/error.%d{yyyy-MM-dd}.log - - 60 - - - ${log.pattern} - UTF-8 - - - - ERROR - - - - - - - - - - - - \ No newline at end of file