26J30b1

Young-Kyoo Kim·2026년 6월 29일
"""
config.py (글로벌 파이프라인 설정 및 도메인 규칙 원부)
"""
import re
from pathlib import Path

# ── 📂 1. 글로벌 프로젝트 경로 정의 ──
BASE_DIR = Path(__file__).resolve().parent
RAW_DIR = BASE_DIR / "data" / "raw"
MERGED_DIR = BASE_DIR / "data" / "merged"
OUT_DIR = BASE_DIR / "data" / "output"

# ── 🌐 2. Thanos / Prometheus 코어 인프라 정보 ──
# 사내 타노스 쿼리 엔드포인트 기본값 (스크립트 실행 시 --url 옵션으로 오버라이드 가능)
DEFAULT_THANOS_URL = "http://thanos-query.internal.zone:9090"

# ── 🔍 3. 공통 노드 프리픽스 정규식 필터 변수 ──
NODE_PREFIX_PATTERN = r"name1wk\d+"

# ── 📈 4. [신규 이식] step1 전용 마스터 PromQL 쿼리 생성 매크로 ──
def get_finops_promql_queries(selector):
    """
    타노스 징수용 원천 PromQL 매크로 템플릿입니다.
    메트릭 사양이 바뀌면 파이프라인 코드를 고칠 필요 없이 여기만 수정하면 됩니다.
    """
    return {
        "cpu_request": f"kube_pod_container_resource_requests{selector.replace('container!=', 'resource=\"cpu\", container!=')}",
        "cpu_limit":   f"kube_pod_container_resource_limits{selector.replace('container!=', 'resource=\"cpu\", container!=')}",
        "cpu_usage":   f"rate(container_cpu_usage_seconds_total{selector}[1m])",
        "mem_request": f"kube_pod_container_resource_requests{selector.replace('container!=', 'resource=\"memory\", container!=')}",
        "mem_limit":   f"kube_pod_container_resource_limits{selector.replace('container!=', 'resource=\"memory\", container!=')}",
        "mem_usage":   f"container_memory_working_set_bytes{selector}",
        "oom_event":   f"kube_pod_container_status_terminated_reason{selector.replace('container!=', 'reason=\"OOMKilled\", container!=')}"
    }

# ── 🧩 5. step2 전용 기술 워크로드 도메인 분류 함수 ──
def get_workload_type(pod_name):
    p = str(pod_name).lower()
    if "spark" in p or "-exec-" in p or "-driver" in p:
        if "executor" in p or "-exec-" in p: return "SPARK_EXECUTOR"
        if "driver" in p or "-driver" in p: return "SPARK_DRIVER"
        return "SPARK_SYSTEM"
    if "airflow" in p or "statsd" in p:
        if "worker" in p: return "AIRFLOW_WORKER"
        if "scheduler" in p: return "AIRFLOW_SCHEDULER"
        if "dag-processor" in p: return "AIRFLOW_DAG_PROC"
        if "triggerer" in p: return "AIRFLOW_TRIGGERER"
        return "AIRFLOW_SYSTEM"
    if "starrocks" in p or "-be-" in p or "-fe-" in p or "-cn-" in p:
        if "-be" in p: return "STARROCKS_BE"
        if "-fe" in p: return "STARROCKS_FE"
        if "-cn" in p: return "STARROCKS_CN"
        return "STARROCKS_SYSTEM"
    if "postgres" in p or "pgpool" in p:
        if "postgresql-backup" in p: return "POSTGRES_BACKUP"
        if "pgpool" in p: return "POSTGRES_POOL"
        return "POSTGRESQL"
    if "hyperset" in p or "superset" in p or re.search(r"hyperset-\d{7,8}-redis", p):
        return "HYPERSET"
    if "jupyter" in p or "notebook" in p: return "JUPYTERLAB"
    if "minio" in p or "aistor" in p or "lake-pool" in p: return "MINIO_STORAGE"
    if "cilium" in p: return "CILIUM_CNI"
    return "GENERAL_APPS"

0개의 댓글