코인원 지표저장소의 현재 상태를 살펴본다.

Overview

  1. 요청자는 슬랙 혹은 지라 티켓을 통해 지표 생성을 요청한다.
  2. 데이터셀에서 지표를 개발한다.
    1. dbt-metric repository 에서 작업한다.
    2. dbt 패키지인 dbt_utils 스펙에 맞게 Yaml 파일을 수정한다.
      • 상황에 따라 staging, prep 모델을 생성한다.
    3. dev/main 브랜치에 머지하며 지표가 정상적으로 생성되었는지 확인한다.
  3. 지표를 요청자에게 전달한다. (lightdash 대시보드 등)

Step-by-Step,

flowchart TD
    subgraph git[Github Action]
    dbt[dbt-metric]
    cicd[CICD]
    end
    
    subgraph dw[DW]
    model[dbt Models]
    metric[Metric Tables]
    end

    subgraph users[Users]
    ae[Analytics Engineer]
    eu[End Users]
    end

    eu -->|request| ae
    ae -->|develop| dbt
    dbt -->|run| cicd
    cicd -->|write| metric
    cicd -->|write| model
    eu -->|read| dw

dbt 사용자(데이터셀)가 작업하는 상세 내용은 다음과 같다.

  1. {모델}.yaml metrics 추가

    • 참조할 모델.yaml 에 metrics 키를 추가하고, 어떠한 메트릭을 사용할지 property 를 정의한다.
    • 한 가지 예시를 같이 살펴보면,
      metrics:
        - name: executed_trade_volume
          label: 체결 거래 대금
          model: ref("prep_trade")
          description: '{{ doc("executed_trade_volume") }}'
          calculation_method: sum
          expression: volume
          timestamp: created_at_kst
          time_grains:
            - day
            - month
          filters:
            - field: bid_orderer_channel
              operator: is not
              value: 'null'
            - field: ask_orderer_channel
              operator: is not
              value: 'null'
      
      • executed_trade_volume 이라는 메트릭 이름으로 prep_trade 모델을 참조한다.
      • 일/월별(time_grains) volume(expression) 합계(calculation_method)를 계산한다.
        • 단, bid_orderer_channel 와 ask_orderer_channel 이 null 이 아닌 볼륨만 필터링한다.
  2. metric_generator 스크립트 실행

    • 스크립트를 실행하면, 설정한 metrics 키값을 기반으로 dbt_metrics 가 컴파일 할 수 있는 형태로 SQL 파일을 생성한다.
      • 생성한 파일명은 다음 규칙에 따라 생성된다.
      • metric_{time_grains}_{metrics.name}
        • day → daily
        • week → weekly
        • month → monthly
    • 생성한 SQL 파일은 models/metric/base 폴더에 쌓이고, compile 혹은 run 커맨드를 실행하면 dbt_metrics 패키지를 이용해 컴파일된다. 컴파일된 SQL 문을 로컬({root_dir{/target/compiled/)에서 확인할 수 있다.
    • 작업 과정은 다음과 같다.
      • dbt-metric 저장소의 루트 디렉토리에서 아래 명령어를 실행한다.
      • python src/metric_generator.py
      • repo_root_dir/models/metric/base 폴더 내 선언한 지표 SQL 파일이 생성되었는지 확인한다.
  3. dbt cli 로 빌드 & 확인

    • 사용자 profile 를 이용해 dbt run 커맨드로 지표 테이블을 생성한다.
      • ex. dbt run –select metric_daily_metric_name
      • 보통 지표 생성이 오면, prep 모델을 생성하고 이 모델을 이용해 지표를 추가한다. 혹은 기존에 있는 prep 모델에 지표를 추가한다. 따라서 아래 커맨드로 한 번에 빌드할 수 있다.
        • dbt run --select prep_model_name+ 혹은 dbt run --select +prep_model_name+
        • more Graph operators
  4. PR 생성

Pros and Cons

flowchart TD
    subgraph git[Github Action]
    dbt[dbt]
    cicd[CICD]
    end
    
    subgraph dw[DW]
    model[dbt Models]
    metric[Metric Tables]
    end

    subgraph doc[Documents]
    dbtdoc[dbt-docs]
    metrich[Metric Hierarchy]
    end 

    subgraph users[Users]
    ae[Analytics Engineer]
    eu[End Users]
    end
    
    eu -->|request| ae
    eu -->|read| doc
    eu -->|read| dw
    ae:::pros -->|write| dbt:::pros
    dbt -->|run| cicd:::pros 
    cicd -->|write| dw:::pros
    cicd -->|write| dbtdoc:::pros

    classDef pros stroke:#2b2, stroke-width:4px
    classDef cons stroke:#f00, stroke-width:4px
flowchart TD
    subgraph git[Github Action]
    dbt[dbt]
    cicd[CICD]
    end
    
    subgraph dw[DW]
    model[dbt Models]
    metric[Metric Tables]
    end

    subgraph doc[Documents]
    dbtdoc[dbt-docs]
    metrich[Metric Hierarchy]:::cons
    end 

    subgraph users[Users]
    ae[Analytics Engineer]
    eu[End Users]
    end
    
    eu:::cons -->|request| ae
    eu -->|read| doc
    eu -->|read| dw
    ae:::cons -->|write| dbt:::cons
    dbt -->|run| cicd:::cons
    cicd -->|write| dw:::cons
    cicd -->|write| dbtdoc

    classDef pros stroke:#2b2, stroke-width:4px
    classDef cons stroke:#f00, stroke-width:4px

EOD