Skip to content

fix: Loki 서비스명 및 Alloy relabel 설정 완료 (#49)#50

Merged
doup2001 merged 2 commits intomainfrom
fix/#49
Apr 10, 2026
Merged

fix: Loki 서비스명 및 Alloy relabel 설정 완료 (#49)#50
doup2001 merged 2 commits intomainfrom
fix/#49

Conversation

@doup2001
Copy link
Copy Markdown
Member

@doup2001 doup2001 commented Apr 10, 2026

📌 작업한 내용

  • Loki 서비스명 분류: 서비스 및 포트 별칭 설정으로 로그 라벨링 정상화
  • Alloy relabel 수정: Alloy 서비스 로그가 정상 출력되도록 라벨 재설정

🔍 참고 사항

  • Grafana Loki에서 Service 라벨 정상 분류로 로그 탐색 가능
  • Alloy 로그 수집 파이프라인 안정화, unknown_service 문제 해결
  • relabel_configs를 통한 서비스별 로그 구분 및 포트 매핑 적용
  • PinHouse_CLOUD 환경의 로그 관찰성 완성

🖼️ 스크린샷

  • X

🔗 관련 이슈

#49 (Grafana Loki Service명 분류 문제)

✅ 체크리스트

  • 로컬에서 빌드 및 테스트 완료
  • 코드 리뷰 반영 완료
  • 문서화 필요 여부 확인

Summary by CodeRabbit

릴리스 노트

  • 기타 업데이트
    • 백엔드 애플리케이션 모니터링 설정 추가
    • 컨테이너 포트 명시 및 프로토콜 지정
    • 모니터링 및 로깅 구성 최적화

@doup2001 doup2001 self-assigned this Apr 10, 2026
@doup2001 doup2001 added the fix 기능 수정 및 버그 픽스 label Apr 10, 2026
@doup2001 doup2001 linked an issue Apr 10, 2026 that may be closed by this pull request
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 10, 2026

Walkthrough

모니터링과 서비스 디스커버리를 위한 Kubernetes 설정을 업데이트합니다. Loki 라벨링 규칙을 변경하고, 백엔드와 프론트엔드 배포에서 명명된 포트를 추가하며, 새로운 백엔드 PodMonitor를 생성하고 프론트엔드 서비스 포트 매핑을 업데이트합니다.

Changes

Cohort / File(s) Summary
Loki 라벨링 규칙
k8s-helm/releases/monitoring-alloy/values.yaml
__meta_kubernetes_pod_label_app에서 service 라벨을 소싱하도록 변경하고, 네임스페이스와 앱 라벨을 결합한 job 라벨을 설정하는 새로운 규칙 추가
백엔드 배포 포트 설정
k8s-kustomize/base/backend/deployment.yaml
컨테이너 포트를 명명된 포트 http로 정의하고 프로토콜을 명시적으로 TCP로 설정
백엔드 모니터링
k8s-kustomize/base/backend/podmonitor.yaml
Prometheus 스크래핑을 위한 새로운 PodMonitor 리소스 생성, /actuator/prometheus 경로를 30초 간격으로 모니터링
프론트엔드 배포 및 서비스
k8s-kustomize/base/frontend/deployment.yaml, k8s-kustomize/base/frontend/service.yaml
배포 포트를 명명된 포트 http로 설정하고, 서비스의 targetPort를 포트 번호 대신 포트 이름으로 참조하도록 변경

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 포트를 이름 지어주고
모니터링을 깔끔하게 정리하니
라벨은 춤을 추고
서비스는 명확해졌어요
쿠버네티스 세상도 예뻐졌네! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 Loki 서비스명 및 Alloy relabel 설정 완료를 명확히 설명하며, 변경사항의 핵심을 정확하게 반영하고 있습니다.
Description check ✅ Passed PR 설명은 필수 섹션(작업 내용, 참고 사항, 관련 이슈, 체크리스트)을 모두 완성했으며, 변경사항에 대한 충분한 맥락을 제공하고 있습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/#49

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
k8s-kustomize/base/frontend/deployment.yaml (1)

33-42: ⚠️ Potential issue | 🟠 Major

보안 컨텍스트 미설정으로 권한이 과도합니다.

Line 33-42에서 파드/컨테이너 securityContext가 없어 기본(root/권한상승 가능) 상태로 배포됩니다. 정적 분석 결과와 동일하게 하드닝이 필요합니다.

🔒 권장 수정안
 spec:
   replicas: 2
@@
   template:
@@
     spec:
+      securityContext:
+        runAsNonRoot: true
+        seccompProfile:
+          type: RuntimeDefault
       containers:
         - name: pinhouse-fe
@@
           image: REPLACE_ME
+          securityContext:
+            allowPrivilegeEscalation: false
+            readOnlyRootFilesystem: true
+            capabilities:
+              drop: ["ALL"]
           ports:
             - name: http
               containerPort: 3000
               protocol: TCP
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@k8s-kustomize/base/frontend/deployment.yaml` around lines 33 - 42, The pod is
deploying the container "pinhouse-fe" without any securityContext so it runs as
root and can escalate privileges; add a securityContext for the container (and
optionally a pod-level securityContext) on the "pinhouse-fe" container to
enforce least privilege: set runAsNonRoot: true and a non-root runAsUser UID,
set allowPrivilegeEscalation: false, drop all Linux capabilities (e.g., drop:
["ALL"]), and enable readOnlyRootFilesystem: true (and consider setting
seccomp/profile or fsGroup at pod-level) so the container cannot run as root or
gain extra privileges.
🧹 Nitpick comments (1)
k8s-helm/releases/monitoring-alloy/values.yaml (1)

143-151: service 라벨 단일 소스 의존은 누락 라벨 파드에서 빈 값을 만들 수 있습니다.

Line 143-151은 app 라벨이 없는 파드에서 service/job가 비거나 분류가 약해질 수 있습니다. app.kubernetes.io/name 또는 container 기반 fallback을 추가하면 unknown/empty 라벨을 더 줄일 수 있습니다.

♻️ fallback 포함 예시
         loki.relabel "pod_logs" {
@@
           rule {
             source_labels = ["__meta_kubernetes_pod_label_app"]
             target_label  = "service"
           }
+
+          rule {
+            source_labels = ["service", "__meta_kubernetes_pod_label_app_kubernetes_io_name"]
+            regex         = "^;(.+)$"
+            replacement   = "$1"
+            target_label  = "service"
+          }
+
+          rule {
+            source_labels = ["service", "__meta_kubernetes_pod_container_name"]
+            regex         = "^;(.+)$"
+            replacement   = "$1"
+            target_label  = "service"
+          }
 
           rule {
-            source_labels = ["__meta_kubernetes_namespace", "__meta_kubernetes_pod_label_app"]
+            source_labels = ["__meta_kubernetes_namespace", "service"]
             separator     = "/"
             target_label  = "job"
           }
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@k8s-helm/releases/monitoring-alloy/values.yaml` around lines 143 - 151, 현재
rule 블록들에서 source_labels가 단일 항목("__meta_kubernetes_pod_label_app")에만 의존해 app 라벨이
없는 파드에서 빈값이 생성될 수 있으니, service와 job 라벨 규칙 모두에 대해 source_labels 배열에 우선순위가 높은 대체
라벨들을 추가하도록 수정하세요; 예를 들어 service 규칙의 source_labels에
"__meta_kubernetes_pod_label_app",
"__meta_kubernetes_pod_label_app_kubernetes_io_name",
"__meta_kubernetes_pod_container_name" 등을 순서대로 넣어 fallback을 제공하고, job 규칙에서도
"__meta_kubernetes_namespace", "__meta_kubernetes_pod_label_app",
"__meta_kubernetes_pod_label_app_kubernetes_io_name",
"__meta_kubernetes_pod_container_name" 같은 추가 항목을 포함해 target_label ("service"와
"job")이 가능한 한 비지 않도록 보장하세요.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@k8s-kustomize/base/frontend/deployment.yaml`:
- Around line 33-42: The pod is deploying the container "pinhouse-fe" without
any securityContext so it runs as root and can escalate privileges; add a
securityContext for the container (and optionally a pod-level securityContext)
on the "pinhouse-fe" container to enforce least privilege: set runAsNonRoot:
true and a non-root runAsUser UID, set allowPrivilegeEscalation: false, drop all
Linux capabilities (e.g., drop: ["ALL"]), and enable readOnlyRootFilesystem:
true (and consider setting seccomp/profile or fsGroup at pod-level) so the
container cannot run as root or gain extra privileges.

---

Nitpick comments:
In `@k8s-helm/releases/monitoring-alloy/values.yaml`:
- Around line 143-151: 현재 rule 블록들에서 source_labels가 단일
항목("__meta_kubernetes_pod_label_app")에만 의존해 app 라벨이 없는 파드에서 빈값이 생성될 수 있으니,
service와 job 라벨 규칙 모두에 대해 source_labels 배열에 우선순위가 높은 대체 라벨들을 추가하도록 수정하세요; 예를 들어
service 규칙의 source_labels에 "__meta_kubernetes_pod_label_app",
"__meta_kubernetes_pod_label_app_kubernetes_io_name",
"__meta_kubernetes_pod_container_name" 등을 순서대로 넣어 fallback을 제공하고, job 규칙에서도
"__meta_kubernetes_namespace", "__meta_kubernetes_pod_label_app",
"__meta_kubernetes_pod_label_app_kubernetes_io_name",
"__meta_kubernetes_pod_container_name" 같은 추가 항목을 포함해 target_label ("service"와
"job")이 가능한 한 비지 않도록 보장하세요.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 87975004-5dd4-4919-ac39-2a789b94b34e

📥 Commits

Reviewing files that changed from the base of the PR and between 0995233 and df618aa.

📒 Files selected for processing (5)
  • k8s-helm/releases/monitoring-alloy/values.yaml
  • k8s-kustomize/base/backend/deployment.yaml
  • k8s-kustomize/base/backend/podmonitor.yaml
  • k8s-kustomize/base/frontend/deployment.yaml
  • k8s-kustomize/base/frontend/service.yaml

@doup2001 doup2001 merged commit 7a24cae into main Apr 10, 2026
1 check passed
@doup2001 doup2001 deleted the fix/#49 branch April 10, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 기능 수정 및 버그 픽스

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Grafana Loki Service명 분류안되는 문제 발생

1 participant