From 01787da6b2bc8eb44adb0333f5333acf3e184817 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EC=9A=B0=EB=94=94?=
<38103085+EunjiShin@users.noreply.github.com>
Date: Sat, 3 Aug 2024 20:53:34 +0900
Subject: [PATCH] =?UTF-8?q?[BSVR-185]=20spring=20actuator,=20prometheus,?=
=?UTF-8?q?=20loki=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EB=B0=8F=20=EC=84=A4?=
=?UTF-8?q?=EC=A0=95=20(#103)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* build: prometheus, spring actuator, loki dependency 추가
* feat: actuator endpoint 활성화 및 white list 등록
* feat: exposure 설정 변경
* feat: actuator port 변경
* feat: health detail 추가
* feat: loki appender 추가
---
application/build.gradle.kts | 18 ++++---
.../common/config/SecurityConfig.java | 3 +-
.../common/jwt/JwtAuthenticationFilter.java | 1 +
.../resources/appenders/console-appender.xml | 17 ++++++
.../src/main/resources/application.yaml | 54 ++++++++++++-------
.../src/main/resources/logback-spring.xml | 1 +
versions.properties | 12 ++++-
7 files changed, 78 insertions(+), 28 deletions(-)
diff --git a/application/build.gradle.kts b/application/build.gradle.kts
index 5d618750..929aa2c7 100644
--- a/application/build.gradle.kts
+++ b/application/build.gradle.kts
@@ -6,23 +6,29 @@ dependencies {
implementation(project(":infrastructure:ncp"))
// spring
+ implementation("org.springframework:spring-aspects")
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
- implementation("org.springframework.boot:spring-boot-starter-validation")
- implementation("org.springframework:spring-aspects")
implementation("org.springframework.boot:spring-boot-starter-data-jpa") // pageable
+ implementation("org.springframework.boot:spring-boot-starter-actuator") {
+ because("spring application의 metric 수집 및 모니터링을 위해 추가합니다.")
+ }
+ implementation("org.springframework.boot:spring-boot-starter-validation")
// security
implementation("org.springframework.boot:spring-boot-starter-security")
+ // prometheus
+ implementation("com.github.loki4j:loki-logback-appender:_")
+ runtimeOnly("io.micrometer:micrometer-registry-prometheus:_")
+
// swagger
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:_")
// jwt
-// implementation("io.jsonwebtoken:jjwt:_")
- implementation("io.jsonwebtoken:jjwt-api:0.11.5")
- implementation("io.jsonwebtoken:jjwt-impl:0.11.5")
- implementation("io.jsonwebtoken:jjwt-jackson:0.11.5")
+ implementation("io.jsonwebtoken:jjwt-api:_")
+ implementation("io.jsonwebtoken:jjwt-impl:_")
+ implementation("io.jsonwebtoken:jjwt-jackson:_")
// aop
implementation("org.springframework.boot:spring-boot-starter-aop")
diff --git a/application/src/main/java/org/depromeet/spot/application/common/config/SecurityConfig.java b/application/src/main/java/org/depromeet/spot/application/common/config/SecurityConfig.java
index 5c0f6fd7..f9bf30a1 100644
--- a/application/src/main/java/org/depromeet/spot/application/common/config/SecurityConfig.java
+++ b/application/src/main/java/org/depromeet/spot/application/common/config/SecurityConfig.java
@@ -28,7 +28,8 @@ public class SecurityConfig {
"/api-docs/**",
"/swagger-ui.html",
"/favicon.ico/**",
- "/api/v1/members/**"
+ "/api/v1/members/**",
+ "/actuator/**"
};
@Bean
diff --git a/application/src/main/java/org/depromeet/spot/application/common/jwt/JwtAuthenticationFilter.java b/application/src/main/java/org/depromeet/spot/application/common/jwt/JwtAuthenticationFilter.java
index 247d48ab..5165f51b 100644
--- a/application/src/main/java/org/depromeet/spot/application/common/jwt/JwtAuthenticationFilter.java
+++ b/application/src/main/java/org/depromeet/spot/application/common/jwt/JwtAuthenticationFilter.java
@@ -35,6 +35,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
"/swagger-ui.html",
"/favicon.ico",
"/api/v1/members",
+ "/actuator",
"/api/v1/levelUpConditions",
};
diff --git a/application/src/main/resources/appenders/console-appender.xml b/application/src/main/resources/appenders/console-appender.xml
index 980d0926..2722d120 100644
--- a/application/src/main/resources/appenders/console-appender.xml
+++ b/application/src/main/resources/appenders/console-appender.xml
@@ -10,4 +10,21 @@
ERROR
+
+
+
+
+ http://localhost:3100/loki/api/v1/push
+
+
+
+
+ %highlight([%-5level]) %d{yy-MM-dd HH:mm:ss.SSS} %green([%thread]) %yellow([traceId=%X{traceId}]) %cyan([%logger{0}:%line])-%message%n
+
+ true
+
+
diff --git a/application/src/main/resources/application.yaml b/application/src/main/resources/application.yaml
index e0deef2c..52dee6c6 100644
--- a/application/src/main/resources/application.yaml
+++ b/application/src/main/resources/application.yaml
@@ -7,22 +7,22 @@ spring:
profiles:
active: local
group:
- local:
- - jpa
- - ncp
- - jwt
- - kakao
- dev:
- - jpa
- - ncp
- - jwt
- - kakao
- prod:
- - jpa
- - ncp
- - jwt
- - kakao
- - sentry
+ local:
+ - jpa
+ - ncp
+ - jwt
+ - kakao
+ dev:
+ - jpa
+ - ncp
+ - jwt
+ - kakao
+ prod:
+ - jpa
+ - ncp
+ - jwt
+ - kakao
+ - sentry
servlet:
multipart:
max-file-size: 10MB
@@ -37,11 +37,25 @@ decorator:
datasource:
p6spy:
enable-logging: true
+
+# spring actuator
+management:
+ server:
+ port: 9292
+ endpoint:
+ health:
+ show-details: always
+ endpoints:
+ prometheus:
+ enabled: true
+ web:
+ exposure:
+ include: "*"
---
spring:
config:
- activate:
- on-profile: local
+ activate:
+ on-profile: local
---
spring:
config:
@@ -59,5 +73,5 @@ decorator:
enable-logging: false
springdoc:
- swagger-ui:
- enabled: false
\ No newline at end of file
+ swagger-ui:
+ enabled: false
\ No newline at end of file
diff --git a/application/src/main/resources/logback-spring.xml b/application/src/main/resources/logback-spring.xml
index 58b17b5d..ebd75254 100644
--- a/application/src/main/resources/logback-spring.xml
+++ b/application/src/main/resources/logback-spring.xml
@@ -18,6 +18,7 @@
+
diff --git a/versions.properties b/versions.properties
index 3e76312a..8ae08c43 100644
--- a/versions.properties
+++ b/versions.properties
@@ -39,4 +39,14 @@ version.org.springframework.boot..spring-boot-configuration-processor=3.0.1
version.io.sentry..sentry-logback=7.12.0
-version.io.sentry..sentry-spring-boot-starter-jakarta=7.12.0
\ No newline at end of file
+version.io.sentry..sentry-spring-boot-starter-jakarta=7.12.0
+
+version.io.jsonwebtoken..jjwt-api=0.11.5
+
+version.io.jsonwebtoken..jjwt-impl=0.11.5
+
+version.io.jsonwebtoken..jjwt-jackson=0.11.5
+
+version.com.github.loki4j..loki-logback-appender=1.4.2
+
+version.io.micrometer..micrometer-registry-prometheus=1.12.4
\ No newline at end of file