diff --git a/.env.example b/.env.example index 120c9de..70971de 100644 --- a/.env.example +++ b/.env.example @@ -12,4 +12,5 @@ HOSTNAME=localhost GPR_USER=GitHub_ID GPR_TOKEN=GitHub_Personal_Access_Token(PAT) -EUREKA_SERVER_URL=http://localhost:8761/eureka/ \ No newline at end of file +EUREKA_SERVER_URL=http://localhost:8761/eureka/ +ZIPKIN_ENDPOINT=http://localhost:9411/api/v2/spans \ No newline at end of file diff --git a/.github/actions/deploy-vm/action.yaml b/.github/actions/deploy-vm/action.yaml index a51a749..a4ce2f3 100644 --- a/.github/actions/deploy-vm/action.yaml +++ b/.github/actions/deploy-vm/action.yaml @@ -75,6 +75,12 @@ runs: --zone="${{ inputs.zone }}" \ --project="${{ inputs.gcp_project }}" \ --tunnel-through-iap + + gcloud compute scp deploy/promtail-config.yml \ + ${{ inputs.vm }}:/tmp/promtail-config.yml \ + --zone="${{ inputs.zone }}" \ + --project="${{ inputs.gcp_project }}" \ + --tunnel-through-iap - name: Deploy and verify id: deploy_run @@ -94,7 +100,13 @@ runs: sudo mkdir -p ${{ inputs.work_dir }} sudo mv /tmp/docker-compose.prod.yaml ${{ inputs.work_dir }}/docker-compose.prod.yaml + sudo mv /tmp/promtail-config.yml ${{ inputs.work_dir }}/promtail-config.yml cd ${{ inputs.work_dir }} + + if ! sudo docker network inspect pgsg-network > /dev/null 2>&1; then + echo 'pgsg-network not found. Creating...' + sudo docker network create pgsg-network + fi sudo env IMAGE_TAG=\"${{ inputs.image_tag }}\" AR_IMAGE_PATH=\"${{ inputs.ar_image_path }}\" \ docker compose -f docker-compose.prod.yaml pull @@ -144,12 +156,12 @@ runs: sudo env IMAGE_TAG=\"${{ steps.rollback.outputs.tag }}\" AR_IMAGE_PATH=\"${{ inputs.ar_image_path }}\" \ docker compose -f docker-compose.prod.yaml up -d - for i in \$(seq 1 18); do + for i in \$(seq 1 ${{ inputs.health_retries }}); do if curl -sf http://localhost:8090/actuator/health | grep -q '\"status\":\"UP\"'; then echo \"Rollback container UP (attempt \$i)\" exit 0 fi - sleep 10 + sleep ${{ inputs.health_interval }} done echo 'Rollback container did not become healthy.' diff --git a/build.gradle b/build.gradle index dff3a95..32b1bba 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { dependencies { - implementation('org.pgsg:common:0.2.5-SNAPSHOT') { + implementation('org.pgsg:common:0.3.2-SNAPSHOT') { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-data-jpa' exclude group: 'com.querydsl', module: 'querydsl-jpa' } diff --git a/deploy/.env.template b/deploy/.env.template index def43c2..54e2f43 100644 --- a/deploy/.env.template +++ b/deploy/.env.template @@ -9,4 +9,7 @@ JWT_REFRESH_EXPIRATION= HOSTNAME= # Eureka 서버 주소 -EUREKA_CLIENT_SERVICEURL_DEFAULTZONE= \ No newline at end of file +EUREKA_SERVER_URL= + +LOKI_URL= +ZIPKIN_ENDPOINT= \ No newline at end of file diff --git a/deploy/docker-compose.prod.yaml b/deploy/docker-compose.prod.yaml index cb2f765..1b7ba93 100644 --- a/deploy/docker-compose.prod.yaml +++ b/deploy/docker-compose.prod.yaml @@ -6,4 +6,26 @@ services: ports: - "8090:8090" env_file: - - .env \ No newline at end of file + - .env + volumes: + - /opt/gateway/logs:/logs # 게이트웨이에서 생성한 로그 파일을 저장할 경로 + networks: + - pgsg-network + + promtail: + image: grafana/promtail:2.9.1 + container_name: promtail + restart: always + volumes: + - /opt/gateway/promtail-config.yml:/etc/promtail/config.yml + - /opt/gateway/logs:/logs # 로그 파일을 저장한 경로와 동일하게 지정 + # promtail 2.9.1 버전은 명시적으로 환경변수 플래그를 지정해야 promtail-config.yml에 설정한 환경변수값 적용 가능 + command: -config.file=/etc/promtail/config.yml -config.expand-env=true + env_file: + - .env + networks: + - pgsg-network + +networks: + pgsg-network: + external: true \ No newline at end of file diff --git a/deploy/promtail-config.yml b/deploy/promtail-config.yml new file mode 100644 index 0000000..05284bc --- /dev/null +++ b/deploy/promtail-config.yml @@ -0,0 +1,14 @@ +server: + http_listen_port: 9080 + +clients: + - url: ${LOKI_URL:-http://loki:3100/loki/api/v1/push} + +scrape_configs: + - job_name: gateway-server + static_configs: + - targets: + - localhost + labels: + job: gateway-server + __path__: /logs/*.log \ No newline at end of file diff --git a/src/main/java/org/pgsg/gateway/filter/JwtGatewayFilter.java b/src/main/java/org/pgsg/gateway/filter/JwtGatewayFilter.java index b01b641..ab8fc30 100644 --- a/src/main/java/org/pgsg/gateway/filter/JwtGatewayFilter.java +++ b/src/main/java/org/pgsg/gateway/filter/JwtGatewayFilter.java @@ -44,7 +44,11 @@ public class JwtGatewayFilter extends OncePerRequestFilter { "/api/v1/auth/reissue", "/actuator/health", "/actuator/health/**", - "/actuator/info" + "/actuator/info", + "/actuator/prometheus", + "/actuator/prometheus/**", + "/actuator/metrics", + "/actuator/metrics/**" ); private final Tracer tracer; diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 70d5cc6..ec75bb3 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -27,4 +27,12 @@ eureka: defaultZone: ${EUREKA_SERVER_URL:http://localhost:8761/eureka/} server: - port: 8090 \ No newline at end of file + port: 8090 + +management: + tracing: + sampling: + probability: 0.1 + zipkin: + tracing: + endpoint: ${ZIPKIN_ENDPOINT:http://localhost:9411/api/v2/spans}