Skip to content

Chore/apply metrix monitoring#25

Merged
lsh2613 merged 2 commits intodevfrom
chore/apply-metrix-monitoring
Aug 29, 2025
Merged

Chore/apply metrix monitoring#25
lsh2613 merged 2 commits intodevfrom
chore/apply-metrix-monitoring

Conversation

@lsh2613
Copy link
Copy Markdown
Owner

@lsh2613 lsh2613 commented Aug 29, 2025

⭐ Related issue

#24


📌 Tasks

  • docker-compose를 통한 prometheus, grafana 서비스 설정
  • metric 수집 endpont에 대한 Basic auth 설정

📢 To Reviewers

Actuator 정보를 그대로 노출시키면 보안적 이슈가 발생할 수 있어, metrix endpoint에 대해 Basic Auth 검증 적용
prometheus에서 metrix 수집 시 basic auth를 설정하기 위한 프로퍼티(username, password)를 숨기기 위해 envsubst를 활용하려 했지만, prom/prometheus 이미지는 Prometheus 실행에 필요한 핵심 바이너리만 포함된 매우 경량화된 형태로 envsubst 설치가 안됨
따라서 alpine 이미지를 통해 리눅스 환경에서 직접 prometheus와 envsubst를 설치하여 적용.

Bearer Auth 검증을 하는 기존 API에 대한 jwtFilterChain 앞에 Metrix API의 Basic Auth를 검증하기 위한 actuatorFilterChain 추가됨.
아래 코드처럼 http.securityMatcher() 깔끔하게 처리하면 좋겠지만, 기존 API의 /api/** 처럼 prefix가 존재하지 않기 떄문에 우선 metrix api도 jwtFilterChain을 타게 설정되어 있음.

@Bean
@Order(1)
public SecurityFilterChain actuatorFilterChain( ... ) throws Exception {
    http.securityMatcher("/actuator/**");
    ...
    return http.build();
}

@Bean
@Order(2)
public SecurityFilterChain jwtFilterChain(HttpSecurity http) throws Exception {
    http.securityMatcher("/api/**");
    ...
    return http.build();
}

대신 JwtAuthenticationFilter에서 metrix api endpoint를 검증. 여기서 if문으로 검증하지 않으면 jwt 추출 시도하여 에러 발생

public class JwtAuthenticationFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain) throws ServletException, IOException {
        if (isMetricRequest(request) || isAnonymousRequest(request)) {
            filterChain.doFilter(request, response);
            return;
        }
    }
    ...

추후 더 좋은 방법 생각나면 개선하는 걸로.


📃 Reference

micrometer 활용하면 api에 대한 시간 및 횟수 등을 metrix에 추가할 수 있음

- docker-compose 서비스(prometheus, grafana) 설정
- metric 수집 endpoint에 대한 basic auth 설정
@lsh2613 lsh2613 added the ⚙️ Chore 기타 작업 label Aug 29, 2025
@lsh2613
Copy link
Copy Markdown
Owner Author

lsh2613 commented Aug 29, 2025

📊 Test Coverage Report

Overall Project 69.41%
File Coverage
UserDetailServiceImpl.java 0%

@lsh2613 lsh2613 merged commit 8236ac0 into dev Aug 29, 2025
2 checks passed
@lsh2613 lsh2613 mentioned this pull request Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚙️ Chore 기타 작업

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant