본문 바로가기
IT & Tech 정보

122. Data Mesh Governance as Code

by 지식과 지혜의 나무 2025. 5. 29.
반응형


Apache Atlas + LakeFS + OpenLineage + OPA Gatekeeper + Argo CD 기반으로, **데이터 제품(Data Product)**의 메타데이터·버전·계보(Lineage)·정책을 모두 코드로 선언·자동화하는 차세대 데이터 거버넌스 파이프라인을 구축합니다.



🎯 목표
1. Git에 데이터 제품 정의(DataProduct CRD) 및 스키마·카탈로그 매니페스트 선언
2. Argo CD Sync → LakeFS에 데이터 레이크 버전 브랜치 생성·관리
3. Atlas Hook으로 GitOps로 선언된 메타데이터·스키마를 Atlas에 자동 등록
4. OpenLineage 에이전트로 ETL·ML 파이프라인 이벤트 수집 → 계보(Lineage) 캡처
5. OPA Gatekeeper로 데이터 제품별 접근·보존·품질 정책 사전 검증
6. Argo CD Self-Heal로 메타데이터·브랜치·정책 불일치 시 자동 복구
7. Prometheus + Grafana 대시보드로 데이터 제품별 품질·사용량·거버넌스 지표 모니터링



⚙️ 핵심 구성 요소

역할 도구/CRD 설명
데이터 버전 관리 LakeFS 레이크하우스 테이블·파케이 파일에 브랜치·태그 개념 제공
메타데이터 카탈로그 Apache Atlas DataProduct CRD 기반 스키마·샘플·Owners 정보 카탈로그 등록
계보(Lineage) 수집 OpenLineage + FlameLens Airflow/DBT/KF Pipelines 이벤트 → Dataset·Job lineage 자동 생성
정책 검증 OPA Gatekeeper 보존 기간·민감데이터 마스킹·데이터 소유권 정책 검증
GitOps 배포·복구 Argo CD Application & Self-Heal DataProduct·LakeFS 브랜치·Policy CR 자동 Sync·검증·복구
모니터링 Prometheus + Grafana 데이터 신선도·품질 검증 결과·파이프라인 성공률 지표 시각화




🏗️ 파이프라인 워크플로우

flowchart TD
  A[Git Push: data-products/, lakefs-config/, policies/]
    --> B[Argo CD Sync DataProduct CRDs & LakeFS Config]
  
  subgraph Version Management
    B --> C[LakeFS: create branch `data-prod/v1.0`]
    C --> D[LakeFS: tag `stable` after validation]
  end

  subgraph Metadata Catalog
    B --> E[Atlas Hook Operator]
    E --> F[Apache Atlas: register DataProduct, schema, owners]
  end

  subgraph Lineage Capture
    G[ETL/ML Pipelines w/ OpenLineage Hook]
      --> H[OpenLineage Collector → Lineage Store]
  end

  subgraph Policy Enforcement
    B --> I[OPA Gatekeeper: validate DataProduct & LakeFS Config]
    I -- Violation --> J[Admission Reject + Slack Alert]
    I -- OK        --> K[Proceed]
  end

  subgraph Monitoring & Healing
    H & D & F --> L[Prometheus scrape: lineage_events_total, data_freshness_seconds]
    L --> M[Grafana Dashboard & Alerts]
    B --> N[Argo CD Self-Heal: drift DataProduct/Policy → auto-correct]
  end




🧪 주요 매니페스트 예시

1) DataProduct CRD & Sample CR

# crd/data-product-crd.yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: dataproducts.example.com
spec:
  group: example.com
  names:
    kind: DataProduct
    plural: dataproducts
  scope: Namespaced
  versions:
  - name: v1
    schema:
      openAPIV3Schema:
        properties:
          spec:
            properties:
              name: { type: string }
              schema: { type: object }
              owners:
                type: array
                items: { type: string }
              retentionDays: { type: integer }

# data-products/customer_churn.yaml
apiVersion: example.com/v1
kind: DataProduct
metadata:
  name: customer-churn
spec:
  name: customer_churn
  schema:
    type: object
    properties:
      customer_id: { type: string }
      churned:     { type: boolean }
      last_login:  { type: string, format: date-time }
  owners:
    - analytics-team@example.com
  retentionDays: 90

2) LakeFS Branch Config (GitOps)

# lakefs-config/branches.yaml
apiVersion: lakefs.io/v1alpha1
kind: Branch
metadata:
  name: data-prod-v1.0
spec:
  repository: main-data-repo
  sourceBranch: master
  description: "Initial release for customer_churn product"

3) OPA Gatekeeper ConstraintTemplate (Retention Policy)

package datamesh.retention

violation[{"msg": msg}] {
  dp := input.review.object.spec
  dp.retentionDays < 30
  msg := sprintf("DataProduct '%v'의 보존 기간(%v일)이 최소 30일 미만입니다.", [input.review.object.metadata.name, dp.retentionDays])
}

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: RetentionPolicy
metadata:
  name: enforce-min-retention
spec:
  match:
    kinds:
      - apiGroups: ["example.com"]
        kinds: ["DataProduct"]

4) Argo CD Application for LakeFS + DataProduct

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: data-mesh-app
spec:
  project: datamesh
  source:
    repoURL: https://github.com/org/data-mesh
    path: .
  destination:
    server: https://kubernetes.default.svc
    namespace: datamesh
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - Validate=true




✅ 기대 효과
• 데이터 제품 수명주기(설계→버전→등록→배포→거버넌스) 전 단계 GitOps 코드화
• 스키마·소유권 카탈로그의 자동 등록과 Lineage 시각화로 신뢰도·투명성 강화
• 정책 사전 검증(보존 기간·민감데이터 등)으로 컴플라이언스 자동화
• 버전 브랜치 관리로 실험·검증·프로덕션 데이터 분리 운영
• 자가 치유: drift된 메타데이터·브랜치·정책 CR을 Argo CD가 자동 복구

반응형