본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Terraform으로 프로파일 상관관계(profile correlation) 구성

원문 보기 위키 갱신

Knowledge Graph의 프로파일 구성(profile configurations)을 사용하면 연속 프로파일링(continuous profiling) 데이터를 어떻게 쿼리하고 엔티티와 상관시키는지 정의할 수 있어요. 성능 프로파일링을 위한 데이터 소스, 엔티티 매칭 규칙, 라벨 매핑을 지정할 수 있어요.

Knowledge Graph UI에서 프로파일 상관관계를 구성하는 방법에 대한 자세한 내용은 프로파일 상관관계 구성 문서를 참고하세요.

출처: 문서

본문

기본 프로파일 구성

profile-configs.tf라는 파일을 만들고 다음 내용을 추가하세요:

# Basic profile configuration for services
resource "grafana_asserts_profile_config" "production" {
  provider = grafana.asserts

  name            = "production"
  priority        = 1000
  default_config  = false
  data_source_uid = "grafanacloud-profiles"

  match {
    property = "asserts_entity_type"
    op       = "="
    values   = ["Service"]
  }

  match {
    property = "deployment_environment"
    op       = "="
    values   = ["production", "staging"]
  }

  entity_property_to_profile_label_mapping = {
    "cluster"        = "k8s_cluster_name"
    "namespace"      = "k8s_namespace_name"
    "container"      = "k8s_container_name"
    "otel_service"   = "service_name"
    "otel_namespace" = "service_namespace"
  }
}

여러 매치 규칙이 있는 프로파일 구성

여러 엔티티 매칭 기준으로 프로파일 상관관계를 구성하세요:

# Development environment profile configuration
resource "grafana_asserts_profile_config" "development" {
  provider = grafana.asserts

  name            = "development"
  priority        = 2000
  default_config  = false
  data_source_uid = "pyroscope-dev"

  match {
    property = "asserts_entity_type"
    op       = "="
    values   = ["Service"]
  }

  match {
    property = "deployment_environment"
    op       = "="
    values   = ["development", "testing"]
  }

  match {
    property = "asserts_site"
    op       = "="
    values   = ["us-east-1"]
  }

  match {
    property = "service"
    op       = "="
    values   = ["api"]
  }

  entity_property_to_profile_label_mapping = {
    "cluster"        = "k8s_cluster_name"
    "namespace"      = "k8s_namespace_name"
    "container"      = "k8s_container_name"
    "otel_service"   = "service_name"
    "otel_namespace" = "service_namespace"
    "pod"            = "k8s_pod_name"
  }
}

최소 프로파일 구성

모든 엔티티에 대한 최소 구성 만들기:

# Minimal configuration for all entities
resource "grafana_asserts_profile_config" "minimal" {
  provider = grafana.asserts

  name            = "minimal"
  priority        = 3000
  default_config  = false
  data_source_uid = "pyroscope-minimal"

  match {
    property = "asserts_entity_type"
    op       = "IS NOT NULL"
    values   = []
  }

  entity_property_to_profile_label_mapping = {
    "cluster"        = "k8s_cluster_name"
    "otel_service"   = "service_name"
    "otel_namespace" = "service_namespace"
  }
}

복잡한 매치 규칙이 있는 고급 프로파일 구성

여러 연산과 고급 매치 규칙으로 프로파일을 구성하세요:

# Advanced configuration with multiple operations
resource "grafana_asserts_profile_config" "advanced" {
  provider = grafana.asserts

  name            = "advanced"
  priority        = 1500
  default_config  = false
  data_source_uid = "pyroscope-advanced"

  match {
    property = "service_type"
    op       = "CONTAINS"
    values   = ["web", "api"]
  }

  match {
    property = "deployment_environment"
    op       = "<>"
    values   = ["test"]
  }

  match {
    property = "team"
    op       = "IS NOT NULL"
    values   = []
  }

  match {
    property = "cpu_threshold"
    op       = ">="
    values   = ["80"]
  }

  entity_property_to_profile_label_mapping = {
    "service_type"   = "service_type"
    "team"           = "team_owner"
    "environment"    = "deployment_env"
    "version"        = "app_version"
    "region"         = "cloud_region"
    "node"           = "k8s_node_name"
  }
}

리소스 참조

grafana_asserts_profile_config

Grafana API를 통해 Knowledge Graph 프로파일 구성을 관리해요.

인자(Arguments)

이름 유형 필수 설명
name string Yes 프로파일 구성의 이름. 이 필드는 불변(immutable)이며 변경 시 재생성을 강제해요.
priority number Yes 프로파일 구성의 우선순위. 숫자가 낮을수록 우선순위가 높아요.
default_config bool Yes 기본 구성인지 여부. 기본 구성은 삭제할 수 없어요.
data_source_uid string Yes 쿼리할 DataSource UID(예: Pyroscope 인스턴스).
match list(object) No 엔티티 속성에 대한 매치 규칙 목록. 자세한 내용은 match 블록을 참고하세요.
entity_property_to_profile_label_mapping map(string) No 상관관계를 위한 엔티티 속성과 프로파일 라벨 간 매핑.

Match 블록

각 match 블록은 다음을 지원해요:

이름 유형 필수 설명
property string Yes 매칭할 엔티티 속성.
op string Yes 매칭에 사용할 연산. 다음 중 하나: =, <>, >, >=, IS NULL, IS NOT NULL, STARTS WITH, CONTAINS.
values list(string) Yes 매칭할 값. IS NULL 및 IS NOT NULL 연산에서는 비어 있을 수 있어요.

예시

resource "grafana_asserts_profile_config" "example" {
  provider = grafana.asserts

  name            = "example-profiles"
  priority        = 1000
  default_config  = false
  data_source_uid = "pyroscope-prod"

  match {
    property = "asserts_entity_type"
    op       = "="
    values   = ["Service", "Pod"]
  }

  match {
    property = "deployment_environment"
    op       = "STARTS WITH"
    values   = ["prod"]
  }

  entity_property_to_profile_label_mapping = {
    "service"     = "service_name"
    "namespace"   = "k8s_namespace_name"
    "environment" = "deployment_env"
    "cluster"     = "k8s_cluster_name"
    "container"   = "k8s_container_name"
  }
}

모범 사례

Terraform으로 프로파일 상관관계를 구성할 때 다음 모범 사례를 고려하세요.

우선순위 관리

  • 더 구체적인 구성에 더 낮은 우선순위 번호를 할당하세요.
  • 우선순위 번호가 낮을수록 우선순위가 높아요(구성은 오름차순 우선순위 순서로 평가됨).
  • 서로 다른 구성 유형에 대해 일관된 우선순위 범위를 사용하세요.
  • 우선순위 할당의 근거를 문서화하세요.

데이터 소스 구성

  • 데이터 소스 UID가 실제 Pyroscope 또는 프로파일링 시스템과 일치하는지 확인하세요.
  • 구성을 적용하기 전에 데이터 소스 연결을 테스트하세요.
  • 프로파일 구성의 목적을 나타내는 설명적인 이름을 사용하세요.
  • 환경마다 별도의 데이터 소스를 사용하는 것을 고려하세요.

라벨 매핑 전략

  • 모든 프로파일 구성에서 엔티티 속성을 일관되게 매핑하세요.
  • 프로파일링 표준과 일치하는 의미 있는 프로파일 라벨 이름을 사용하세요.
  • 구성 주석에 매핑 관계를 문서화하세요.
  • 매핑된 라벨이 프로파일 데이터에 존재하는지 확인하세요.
  • 연속 프로파일링 설정(Pyroscope, Grafana Agent 등)과 라벨 이름을 일치시키세요.

매치 규칙 설계

  • 광범위한 매치 규칙으로 시작하고 필요에 따라 다듬으세요.
  • 엔티티 모델에 존재하는 구체적인 속성 이름을 사용하세요.
  • 배포 전에 샘플 데이터로 매치 규칙을 테스트하세요.
  • 정밀한 엔티티 타기팅을 위해 여러 매치 규칙을 결합하세요.
  • 숫자 임계값 또는 성능 기반 필터링을 위해 비교 연산자(>, >=)를 활용하세요.

연속 프로파일링 통합

  • 프로파일링 에이전트가 적절한 라벨로 구성되었는지 확인하세요.
  • 프로파일링 인프라 전반에 걸쳐 일관된 라벨 이름을 사용하세요.
  • 포괄적인 상관관계를 위해 서비스 수준과 인프라 수준 속성을 모두 매핑하세요.
  • Kubernetes 배포에 pod, node, container 정보를 포함하는 것을 고려하세요.
  • 예상대로 작동하는지 프로파일 상관관계를 테스트하세요.

검증

Terraform 구성을 적용한 후 다음을 확인하세요:

  • 프로파일 구성이 Knowledge Graph 인스턴스에 생성되었는지.
  • 구성이 Knowledge Graph UI의 Observability > Configuration > Profiles 아래에 나타나는지.
  • 엔티티에서 드릴다운할 때 프로파일 상관관계가 작동하는지.
  • 라벨 매핑이 엔티티 속성을 프로파일 라벨로 올바르게 변환하는지.
  • 매치 규칙이 엔티티를 올바르게 필터링하는지.
  • 프로파일 쿼리가 Knowledge Graph UI에서 예상 결과를 반환하는지.
  • Knowledge Graph를 통해 접근할 때 플레임 그래프와 프로파일링 데이터가 올바르게 표시되는지.

관련 문서

더 알아보기 (Learn more)