Skip to content

Commit

Permalink
[BSVR-185] spring actuator, prometheus, loki 의존성 및 설정 (#103)
Browse files Browse the repository at this point in the history
* build: prometheus, spring actuator, loki dependency 추가

* feat: actuator endpoint 활성화 및 white list 등록

* feat: exposure 설정 변경

* feat: actuator port 변경

* feat: health detail 추가

* feat: loki appender 추가
  • Loading branch information
EunjiShin authored Aug 3, 2024
1 parent 7564cb1 commit 01787da
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 28 deletions.
18 changes: 12 additions & 6 deletions application/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class SecurityConfig {
"/api-docs/**",
"/swagger-ui.html",
"/favicon.ico/**",
"/api/v1/members/**"
"/api/v1/members/**",
"/actuator/**"
};

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
"/swagger-ui.html",
"/favicon.ico",
"/api/v1/members",
"/actuator",
"/api/v1/levelUpConditions",
};

Expand Down
17 changes: 17 additions & 0 deletions application/src/main/resources/appenders/console-appender.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,21 @@
<appender name="SENTRY_APPENDER" class="io.sentry.logback.SentryAppender">
<minimumEventLevel>ERROR</minimumEventLevel>
</appender>

<appender name="LOKI_APPENDER" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<!-- TODO: Loki 인스턴스 세팅 후 URL 변경 필요 -->
<url>http://localhost:3100/loki/api/v1/push</url>
</http>
<format>
<label>
<pattern>app=${name},host=${HOSTNAME},level=%level</pattern>
<readMarkers>true</readMarkers>
</label>
<message>
<pattern>%highlight([%-5level]) %d{yy-MM-dd HH:mm:ss.SSS} %green([%thread]) %yellow([traceId=%X{traceId}]) %cyan([%logger{0}:%line])-%message%n</pattern>
</message>
<sortByTime>true</sortByTime>
</format>
</appender>
</included>
54 changes: 34 additions & 20 deletions application/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -59,5 +73,5 @@ decorator:
enable-logging: false

springdoc:
swagger-ui:
enabled: false
swagger-ui:
enabled: false
1 change: 1 addition & 0 deletions application/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<root level="ERROR">
<appender-ref ref="CONSOLE_APPENDER"/>
<appender-ref ref="SENTRY_APPENDER"/>
<appender-ref ref="LOKI_APPENDER"/>
</root>
</springProfile>
</configuration>
12 changes: 11 additions & 1 deletion versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit 01787da

Please sign in to comment.