Skip to content

Commit 53d8d35

Browse files
authored
✨ feat: 프로메테우스 적용 (#120)
1 parent 407f4f2 commit 53d8d35

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

backend/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,22 @@ repositories {
2424
}
2525

2626
dependencies {
27+
/* SPRING BOOT STARTER */
2728
implementation 'org.springframework.boot:spring-boot-starter-validation'
2829
implementation 'org.springframework.boot:spring-boot-starter-web'
2930
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
3031
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
3132
implementation 'org.springframework.boot:spring-boot-starter-websocket'
3233
implementation 'org.springframework.boot:spring-boot-starter-security'
3334
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
35+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
3436

3537
/* DATABASE */
3638
runtimeOnly 'com.mysql:mysql-connector-j'
3739

40+
/* MONITORING */
41+
implementation 'io.micrometer:micrometer-registry-prometheus'
42+
3843
/* TEST */
3944
testImplementation 'org.springframework.boot:spring-boot-starter-test'
4045
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

backend/src/main/java/io/f1/backend/global/config/SecurityConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import lombok.RequiredArgsConstructor;
1212

13+
import org.springframework.beans.factory.annotation.Value;
1314
import org.springframework.context.annotation.Bean;
1415
import org.springframework.context.annotation.Configuration;
1516
import org.springframework.http.HttpMethod;
@@ -32,6 +33,9 @@ public class SecurityConfig {
3233
private final AdminLoginSuccessHandler adminLoginSuccessHandler;
3334
private final AdminLoginFailureHandler adminLoginFailureHandler;
3435

36+
@Value("${management.endpoints.web.base-path:/actuator}")
37+
private String actuatorBasePath;
38+
3539
@Bean
3640
public SecurityFilterChain userFilterChain(HttpSecurity http) throws Exception {
3741
http.csrf(AbstractHttpConfigurer::disable)
@@ -66,6 +70,8 @@ public SecurityFilterChain userFilterChain(HttpSecurity http) throws Exception {
6670
.hasAnyRole("USER", "ADMIN")
6771
.requestMatchers("/questions/**")
6872
.hasAnyRole("USER", "ADMIN")
73+
.requestMatchers(actuatorBasePath + "/**")
74+
.hasRole("PROMETHEUS")
6975
.anyRequest()
7076
.authenticated())
7177
.formLogin(

backend/src/main/resources/application.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,26 @@ server:
6464
secure: true
6565
http-only: true
6666
timeout: ${SESSION_TIMEOUT}
67+
---
68+
spring:
69+
config:
70+
activate:
71+
on-profile: prod
72+
73+
security:
74+
user:
75+
name: ${PROM_NAME}
76+
password: ${PROM_PASSWORD}
77+
roles: PROMETHEUS
6778

79+
management:
80+
server:
81+
port: ${ACTUATOR_PORT}
82+
endpoints:
83+
web:
84+
exposure:
85+
include: "prometheus"
86+
base-path: ${ACTUATOR_BASE_PATH}
87+
endpoint:
88+
prometheus:
89+
access: read_only

0 commit comments

Comments
 (0)