Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

통합 테스트(프론트 + api) 모니터링용 설정 적용 #125

Closed
cotchan opened this issue Jul 17, 2022 · 0 comments
Closed

통합 테스트(프론트 + api) 모니터링용 설정 적용 #125

cotchan opened this issue Jul 17, 2022 · 0 comments
Assignees
Labels
BE backend documentation Improvements or additions to documentation done

Comments

@cotchan
Copy link
Collaborator

cotchan commented Jul 17, 2022

작업내용

  • 배포 환경에서 클라이언트(프론트)가 기능 검증을 위해 API 테스트 할 때, 추가 요구사항 외에도 이슈가 되는 부분이 있는지 확인하고자 적용

PR

목차

  1. 슬로우 쿼리 로그 활성화
  2. 스프링부트 actuator 적용
  3. 프로메테우스 & grafana 적용

슬로우 쿼리 로그 활성화

  • my.cnf에 슬로우 쿼리(2초) 로그 활성화 옵션 적용
[mysqld]
# 슬로우 쿼리를 FILE로 출력
log_output = FILE
# 출력할 파일 위치를 설정
slow_query_log_file = /var/log/mysql/mysql-slow.log

# 슬로우 쿼리 활성화
slow_query_log = 1

# 아래 변수에 지정된 초(seconds)이상 쿼리가 수행되면 슬로우 쿼리에 기록
long_query_time = 2
mysql> SHOW VARIABLES WHERE 
    -> Variable_Name LIKE 'slow_query_log' OR 
    -> Variable_Name LIKE 'long_query_time' OR
    -> Variable_Name LIKE 'log_output';
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| log_output      | FILE     |
| long_query_time | 2.000000 |
| slow_query_log  | ON       |
+-----------------+----------+
3 rows in set (0.00 sec)
  • 기능 정상 동작 테스트
# cat mysql-slow.log

# Time: 2022-07-17T20:37:27.320818Z
# User@Host: root[root] @ localhost []  Id:     2
# Query_time: 3.000273  Lock_time: 0.000000 Rows_sent: 1  Rows_examined: 0
SET timestamp=1658090247;
select sleep(3);

스프링부트 actuator 적용

  • 애플리케이션 상태 확인을 위해 스프링부트 actuator 적용
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
}
  • actuator Endpoint를 healthprometheus만 열어놓음
  • application.yml
management:
  endpoints:
    web:
      exposure:
        include: health,prometheus
  metrics:
    export:
      prometheus:
        enabled: true

프로메테우스 & grafana 적용

프로메테우스

  • spring actuator endpoint로부터 데이터를 받을 수 있도록 prometheus.yml 수정
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
  
  #...

  - job_name: daangn_server_node
    metrics_path: /actuator/prometheus
    static_configs:
      - targets: ['localhost:8081','localhost:8881','localhost:9081']

스크린샷 2022-07-18 오전 6 36 19

grafana

  • Dashboard 템플릿으로는 JVM (Micrometer) 적용

스크린샷 2022-07-18 오전 6 55 35


@cotchan cotchan self-assigned this Jul 17, 2022
cotchan added a commit that referenced this issue Jul 17, 2022
add, update: actuator 설정 추가 및 Security 설정 변경
cotchan added a commit that referenced this issue Jul 17, 2022
fix: actuator path 예외 설정
@cotchan cotchan changed the title 프로메테우스 연동 프론트 테스트 모니터링용 설정 적용 Jul 17, 2022
@cotchan cotchan added documentation Improvements or additions to documentation BE backend labels Jul 17, 2022
@cotchan cotchan changed the title 프론트 테스트 모니터링용 설정 적용 통합 테스트(프론트 + api) 모니터링용 설정 적용 Jul 17, 2022
@cotchan cotchan closed this as completed Jul 17, 2022
@cotchan cotchan added the done label Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE backend documentation Improvements or additions to documentation done
Projects
None yet
Development

No branches or pull requests

1 participant