Skip to content

Commit

Permalink
Feat: monitoring setup (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
pingowl authored May 30, 2024
1 parent 6a149f7 commit 1f99ac4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -77,3 +82,8 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}


springBoot {
buildInfo()
}
6 changes: 6 additions & 0 deletions src/main/java/com/drugbox/DrugBoxApplication.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,4 +14,8 @@ public static void main(String[] args) {
SpringApplication.run(DrugBoxApplication.class, args);
}

@Bean
public InMemoryHttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/drugbox/common/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 클래스를 적용
Expand All @@ -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(); };
}
}
22 changes: 22 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1f99ac4

Please sign in to comment.