From 1f99ac4444edfcbc8dd0b84f1722b40eca34de8b Mon Sep 17 00:00:00 2001 From: Bomin Kwon <101239440+pingowl@users.noreply.github.com> Date: Thu, 30 May 2024 14:37:23 +0900 Subject: [PATCH] Feat: monitoring setup (#28) --- build.gradle | 10 +++++++++ .../java/com/drugbox/DrugBoxApplication.java | 6 +++++ .../drugbox/common/config/SecurityConfig.java | 8 +++++++ src/main/resources/application.yml | 22 +++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/build.gradle b/build.gradle index ff21aa2..1167201 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '2.7.5' id 'io.spring.dependency-management' version '1.1.4' + id "com.gorylenko.gradle-git-properties" version "2.2.4" // actutator-git } group = 'com' @@ -26,6 +27,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + implementation 'org.springframework.boot:spring-boot-starter-actuator' // data implementation 'org.springframework.boot:spring-boot-starter-data-jdbc' @@ -46,6 +48,9 @@ dependencies { // Swagger implementation 'io.springfox:springfox-boot-starter:3.0.0' + // Prometheus + implementation 'io.micrometer:micrometer-registry-prometheus' + // Google Cloud Platform (GCP) implementation 'org.springframework.cloud:spring-cloud-gcp-starter:1.2.5.RELEASE' implementation 'com.google.api-client:google-api-client:1.32.1' @@ -77,3 +82,8 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + + +springBoot { + buildInfo() +} \ No newline at end of file diff --git a/src/main/java/com/drugbox/DrugBoxApplication.java b/src/main/java/com/drugbox/DrugBoxApplication.java index 0d327a8..6723495 100644 --- a/src/main/java/com/drugbox/DrugBoxApplication.java +++ b/src/main/java/com/drugbox/DrugBoxApplication.java @@ -1,7 +1,9 @@ package com.drugbox; import org.springframework.boot.SpringApplication; +import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @EnableJpaAuditing @@ -12,4 +14,8 @@ public static void main(String[] args) { SpringApplication.run(DrugBoxApplication.class, args); } + @Bean + public InMemoryHttpTraceRepository httpTraceRepository() { + return new InMemoryHttpTraceRepository(); + } } diff --git a/src/main/java/com/drugbox/common/config/SecurityConfig.java b/src/main/java/com/drugbox/common/config/SecurityConfig.java index 5b4174f..76db89b 100644 --- a/src/main/java/com/drugbox/common/config/SecurityConfig.java +++ b/src/main/java/com/drugbox/common/config/SecurityConfig.java @@ -11,6 +11,9 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.util.matcher.RequestMatcher; + +import javax.servlet.http.HttpServletRequest; @Configuration @RequiredArgsConstructor @@ -69,6 +72,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .addFilter(corsConfig.corsFilter()) .authorizeRequests() .antMatchers(WHITE_LIST).permitAll() + .requestMatchers(forPort(9292)).anonymous() // actuator .anyRequest().authenticated() // 나머지 API 는 전부 인증 필요 // JwtFilter 를 addFilterBefore 로 등록했던 JwtSecurityConfig 클래스를 적용 @@ -77,4 +81,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http.build(); } + + private RequestMatcher forPort(final int port) { + return (HttpServletRequest request) -> { return port == request.getLocalPort(); }; + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9b6b09c..73a4048 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -77,3 +77,25 @@ logging: jwt: secret: ${application.jwt.secret} secret_refresh: ${application.jwt.secret_refresh} + +management: + server: + port: 9292 + info: + java: + enabled: true + os: + enabled: true + env: + enabled: true + endpoint: + health: + show-details: always + endpoints: + web: + exposure: + include: "*" +info: + app: + name: drugbox + company: bk \ No newline at end of file