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

메시 메트릭 정책

원문 보기 위키 갱신

메시 메트릭 정책 (MeshMetrics Policy)

메시 메트릭 정책은 메시 안의 모든 데이터 플레인 프록시에서 일관된 트래픽 메트릭을 수집하게 해주는 기능이에요 메시 전체에 기본 설정을 정의해 두고, 필요하면 개별 프록시에서 메트릭 포트 같은 부분만 골라서 바꿀 수도 있어요 프로메테우스와 오픈텔레메트리를 모두 지원해서, 프록시와 애플리케이션의 메트릭을 수집해 원하는 백엔드로 보낼 수 있답니다 설정은 sidecar, applications, backends 세 영역으로 나뉘고, 동적 구성 방식이라 프록시를 재시작하지 않아도 바로 적용된다는 점도 기억해 두면 좋아요

출처: 문서

본문

메시 전체에 대한 메트릭 설정을 정의하고, 필요에 따라 개별 데이터 플레인 프록시에 대해 일부 설정을 조정할 수도 있어요. 예를 들어, 지정된 머신에서 기본 메트릭 포트가 이미 사용 중이라면 이를 다른 포트로 재정의해야 할 수도 있어요.

Kong Mesh는 Prometheus와 완전히 통합돼요:

  • 각 프록시는 Prometheus 형식으로 메트릭을 노출할 수 있어요.
  • Kong Mesh는 모니터링 할당 서비스(MADS)라는 API를 제공하며, 이 API는 MeshMetric으로 설정된 프록시들을 노출해요.

또한 Kong Mesh는 OpenTelemetry와도 통합돼요:

Kong Mesh에서 메트릭을 수집하려면 프록시와 애플리케이션에서 메트릭을 노출해야 해요.

이 페이지의 나머지 부분에서는 관측 가능성 도구가 Kong Mesh와 함께 동작하도록 이미 설정해 두었다고 가정해요. 아직 읽지 않았다면 관측 가능성 문서를 먼저 확인하세요.

TargetRef 지원 매트릭스

사이드카

targetRef.kind

허용되는 종류: Mesh, Dataplane, MeshSubset(deprecated)

빌트인 게이트웨이

targetRef.kind

허용되는 종류: Mesh, MeshGateway, 리스너 tags가 있는 MeshGateway

위임 게이트웨이

targetRef.kind

허용되는 종류: Mesh, MeshSubset

설정

설정에는 sidecar, applications, backends라는 세 가지 주요 섹션이 있어요. 앞의 두 섹션은 메시의 일부(사이드카와 그 아래에서 동작하는 애플리케이션)를 어떻게 스크레이프할지 정의하고, 세 번째 섹션은 데이터를 어떻게 처리할지 정의해요(Prometheus의 경우 특정 주소를 스크레이프하도록 지시하고, OpenTelemetry의 경우 데이터를 어디로 푸시할지 정의해요).

Traffic Metrics와는 달리 모든 설정이 동적으로 적용되기 때문에 데이터 플레인 프록시를 재시작할 필요가 없어요. KUMA_DATAPLANE_RUNTIME_DYNAMIC_CONFIGURATION_REFRESH_INTERVAL 환경 변수나 kuma.dataplaneRuntime.dynamicConfiguration.refreshInterval Helm 값을 사용해 설정 새로 고침 간격을 정의할 수 있어요.

사이드카

설정의 이 부분은 데이터 플레인 프록시 스크레이핑에 적용돼요. Envoy의 모든 메트릭을 가져오고 싶지 않다면 필터링할 수도 있어요.

필터링 방법은 여러 가지가 있어요. 적용 순서는 다음과 같아요:

  1. 사용되지 않는 메트릭
  2. 프로파일
  3. 제외
  4. 포함

사용되지 않는 메트릭

기본적으로 업데이트되지 않은 메트릭은 게시되지 않아요. Envoy의 모든 메트릭을 돌려주는 includeUnused 플래그를 설정할 수 있어요.

프로파일

프로파일은 수동 include 및 exclude 기능이 더해진, 미리 정의된 메트릭 집합이에요. 3개의 섹션이 있어요:

  • appendProfiles - 여러 개의 미리 정의된 메트릭 프로파일을 조합할 수 있게 해줘요. 지금은 프로파일을 하나만 정의할 수 있지만 앞으로는 바뀔 수 있어요 (예를 들어 "Fault injection profile", "Circuit Breaker profile"처럼 기능 관련 프로파일이 생겨서, 사용하는 기능에 따라 필요한 프로파일을 골라 조합할 수 있게 될 수도 있어요). 현재 사용할 수 있는 프로파일은 All, Basic, None 세 가지예요. All 프로파일은 Envoy가 생성하는 모든 메트릭을 포함해요. Basic 프로파일은 Kong Mesh 대시보드에 필요한 모든 메트릭과 골든 4 신호 메트릭을 포함해요. None 프로파일은 모든 메트릭을 제거해요
  • exclude - 프로파일이 적용된 후에는 프로파일 필터링 위에서 메트릭을 수동으로 제외할 수 있어요.
  • include - exclude가 적용된 후에는 메트릭을 수동으로 다시 포함할 수 있어요.

예제

수동 exclude 및 include와 함께 Basic 프로파일의 사용되지 않는 메트릭 포함하기
Kubernetes
apiVersion: kuma.io/v1alpha1
kind: MeshMetric
metadata:
  name: metrics-default
  namespace: kong-mesh-demo
  labels:
    kuma.io/mesh: default
spec:
  default:
    sidecar:
      includeUnused: true
      profiles:
        appendProfiles:
        - name: Basic
        exclude:
        - type: Regex
          match: envoy_cluster_external_upstream_rq_.*
        include:
        - type: Exact
          match: envoy_cluster_default_total_match_count
    backends:
    - type: Prometheus
      prometheus:
        port: 5670
        path: "/metrics"
Universal
type: MeshMetric
mesh: default
name: metrics-default
spec:
  default:
    sidecar:
      includeUnused: true
      profiles:
        appendProfiles:
        - name: Basic
        exclude:
        - type: Regex
          match: envoy_cluster_external_upstream_rq_.*
        include:
        - type: Exact
          match: envoy_cluster_default_total_match_count
    backends:
    - type: Prometheus
      prometheus:
        port: 5670
        path: "/metrics"
Terraform

현재 설정에 맞게 konnect_mesh_control_plane.my_meshcontrolplane.id와 konnect_mesh.my_mesh.name을 조정하세요. {: .text-sm}

resource "konnect_mesh_metric" "metrics_default" {
  provider = konnect-beta
  type = "MeshMetric"
  name = "metrics-default"
  spec = {
    default = {
      sidecar = {
        include_unused = "true"
        profiles = {
          append_profiles = [
            {
              name = "Basic"
            }
          ]
          exclude = [
            {
              type = "Regex"
              match = "envoy_cluster_external_upstream_rq_.*"
            }
          ]
          include = [
            {
              type = "Exact"
              match = "envoy_cluster_default_total_match_count"
            }
          ]
        }
      }
      backends = [
        {
          type = "Prometheus"
          prometheus = {
            port = "5670"
            path = "/metrics"
          }
        }
      ]
    }
  }
  labels   = {
  "kuma.io/mesh" = konnect_mesh.my_mesh.name
  }
  cp_id    = konnect_mesh_control_plane.my_meshcontrolplane.id
  mesh     = konnect_mesh.my_mesh.name
}

수동으로 정의한 메트릭만 포함하기
Kubernetes
apiVersion: kuma.io/v1alpha1
kind: MeshMetric
metadata:
  name: metrics-default
  namespace: kong-mesh-demo
  labels:
    kuma.io/mesh: default
spec:
  default:
    sidecar:
      profiles:
        appendProfiles:
        - name: None
        include:
        - type: Regex
          match: envoy_cluster_external_upstream_rq_.*
    backends:
    - type: Prometheus
      prometheus:
        port: 5670
        path: "/metrics"
Universal
type: MeshMetric
mesh: default
name: metrics-default
spec:
  default:
    sidecar:
      profiles:
        appendProfiles:
        - name: None
        include:
        - type: Regex
          match: envoy_cluster_external_upstream_rq_.*
    backends:
    - type: Prometheus
      prometheus:
        port: 5670
        path: "/metrics"
Terraform

현재 설정에 맞게 konnect_mesh_control_plane.my_meshcontrolplane.id와 konnect_mesh.my_mesh.name을 조정하세요. {: .text-sm}

resource "konnect_mesh_metric" "metrics_default" {
  provider = konnect-beta
  type = "MeshMetric"
  name = "metrics-default"
  spec = {
    default = {
      sidecar = {
        profiles = {
          append_profiles = [
            {
              name = "None"
            }
          ]
          include = [
            {
              type = "Regex"
              match = "envoy_cluster_external_upstream_rq_.*"
            }
          ]
        }
      }
      backends = [
        {
          type = "Prometheus"
          prometheus = {
            port = "5670"
            path = "/metrics"
          }
        }
      ]
    }
  }
  labels   = {
  "kuma.io/mesh" = konnect_mesh.my_mesh.name
  }
  cp_id    = konnect_mesh_control_plane.my_meshcontrolplane.id
  mesh     = konnect_mesh.my_mesh.name
}

수동으로 추가한 하나를 제외한 모든 메트릭 제외하기
Kubernetes
apiVersion: kuma.io/v1alpha1
kind: MeshMetric
metadata:
  name: metrics-default
  namespace: kong-mesh-demo
  labels:
    kuma.io/mesh: default
spec:
  default:
    sidecar:
      profiles:
        appendProfiles:
        - name: None
        include:
        - type: Regex
          match: envoy_cluster_external_upstream_rq_.*
    backends:
    - type: Prometheus
      prometheus:
        port: 5670
        path: "/metrics"
Universal
type: MeshMetric
mesh: default
name: metrics-default
spec:
  default:
    sidecar:
      profiles:
        appendProfiles:
        - name: None
        include:
        - type: Regex
          match: envoy_cluster_external_upstream_rq_.*
    backends:
    - type: Prometheus
      prometheus:
        port: 5670
        path: "/metrics"
Terraform

현재 설정에 맞게 konnect_mesh_control_plane.my_meshcontrolplane.id와 konnect_mesh.my_mesh.name을 조정하세요. {: .text-sm}

resource "konnect_mesh_metric" "metrics_default" {
  provider = konnect-beta
  type = "MeshMetric"
  name = "metrics-default"
  spec = {
    default = {
      sidecar = {
        profiles = {
          append_profiles = [
            {
              name = "None"
            }
          ]
          include = [
            {
              type = "Regex"
              match = "envoy_cluster_external_upstream_rq_.*"
            }
          ]
        }
      }
      backends = [
        {
          type = "Prometheus"
          prometheus = {
            port = "5670"
            path = "/metrics"
          }
        }
      ]
    }
  }
  labels   = {
  "kuma.io/mesh" = konnect_mesh.my_mesh.name
  }
  cp_id    = konnect_mesh_control_plane.my_meshcontrolplane.id
  mesh     = konnect_mesh.my_mesh.name
}

애플리케이션

애플리케이션이 노출하는 메트릭은 Dataplane Proxy가 이를 파싱해서 Prometheus 또는 OpenTelemetry 백엔드에 노출할 수 있도록 Prometheus 형식이어야 해요.

데이터 플레인 프록시의 메트릭을 노출하는 것 외에도, 프록시 옆에서 실행 중인 애플리케이션의 메트릭을 노출하고 싶을 수 있어요. Kong Mesh는 같은 Pod나 VM에서 실행 중인 애플리케이션 엔드포인트에서 Prometheus 메트릭을 스크래핑할 수 있게 해줘요. 이후 이 메트릭들은 데이터 플레인 프록시 메트릭과 같은 port/path에서 집계되어 노출돼요. Mesh 수준에서 Mesh의 모든 애플리케이션에 대해 설정하거나, 특정 애플리케이션에만 설정하는 것도 가능해요.

이 기능을 사용하고 싶어질 만한 이유는 다음과 같아요:

  • 애플리케이션 메트릭에 메시 파라미터(태그, mesh, 데이터 플레인 이름 등)가 라벨로 붙어요. 즉, Universal과 Kubernetes가 섞인 모드에서도 메트릭이 같은 종류의 라벨로 보고돼요.
  • 애플리케이션 메트릭과 사이드카 메트릭이 동시에 스크래핑돼요. 이 덕분에 두 메트릭의 일관성이 보장돼요(스크래퍼가 2개면 서로 다른 간격으로 스크래핑하게 돼서 메트릭 간 연관성을 파악하기 어려워질 수 있어요). 다음 조건이 충족될 때 앱이 사이드카 뒤에 완전히 가려져 있는 경우, 이 메트릭을 가져올 수 있는 유일한 방법이에요:
  • passthrough를 비활성화한 경우
  • 메시가 mTLS를 사용하는 경우
  • Prometheus가 메시 외부에 있는 경우

설정 예시 섹션:

applications:
  - name: "backend" # application name used for logging and to scope OpenTelemetry metrics (optional)
    path: "/metrics/prometheus" # application metrics endpoint path
    address: # optional custom address if the underlying application listens on a different address than the Data Plane Proxy
    port: 8888 # port on which application is listening

백엔드

Prometheus

backends:
  - type: Prometheus
    prometheus: 
      port: 5670
      path: /metrics

이 설정은 Kong Mesh에게 포트 5670과 uri 경로 /metrics에서 Prometheus 메트릭이 담긴 HTTP 엔드포인트를 노출하도록 지시해요.

메트릭 엔드포인트는 표준 Envoy Prometheus 메트릭 엔드포인트로 포워딩되며, 같은 쿼리 파라미터를 지원해요. filter 쿼리 파라미터를 전달하면 결과를 주어진 정규 표현식과 이름이 일치하는 메트릭으로 제한할 수 있어요. 기본적으로는 사용 가능한 모든 메트릭이 반환돼요.

TLS로 메트릭 보호하기

Kong Mesh를 사용하면 메트릭 엔드포인트를 TLS로 설정할 수 있어요.

backends:
  - type: Prometheus
    prometheus: 
      port: 5670
      path: /metrics
      tls:
        mode: ProvidedTLS

MeshMetric 설정 외에도, kuma-sidecar가 동작하려면 인증서와 키가 제공되어야 해요.

Kubernetes

컨테이너 안에서 인증서와 키를 사용할 수 있게 되면, kuma-sidecar는 제공된 파일의 경로를 다음 환경 변수로 필요로 해요:

  • KUMA_DATAPLANE_RUNTIME_METRICS_CERT_PATH
  • KUMA_DATAPLANE_RUNTIME_METRICS_KEY_PATH

ContainerPatch를 사용하면 kuma-sidecar에 변수를 추가할 수 있어요:

apiVersion: kuma.io/v1alpha1
kind: ContainerPatch
metadata:
  name: container-patch-1
  namespace: kong-mesh-system
spec:
  sidecarPatch:
    - op: add
      path: /env/-
      value: '{
          "name": "KUMA_DATAPLANE_RUNTIME_METRICS_CERT_PATH",
          "value": "/kuma/server.crt"
        }'
    - op: add
      path: /env/-
      value: '{
          "name": "KUMA_DATAPLANE_RUNTIME_METRICS_KEY_PATH",
          "value": "/kuma/server.key"
        }'
Universal

인증서와 키를 머신에 업로드한 다음, 올바른 경로로 다음 환경 변수를 정의해 주세요:

* `KUMA_DATAPLANE_RUNTIME_METRICS_CERT_PATH`
* `KUMA_DATAPLANE_RUNTIME_METRICS_KEY_PATH`
activeMTLSBackend

더 이상 activeMTLSBackend는 지원하지 않아요. 메트릭을 암호화하고 권한을 부여해야 한다면 TLS로 메트릭 보호와 권한 부여 방법 중 하나를 조합해서 사용하세요.

여러 Prometheus 배포 실행하기

여러 개의 Prometheus 인스턴스를 실행하면서 서로 다른 데이터 플레인 프록시 집합을 대상으로 삼고 싶다면, MeshMetric의 Client ID 설정(clientId)과 Prometheus 설정의 client_id 양쪽에서 이를 설정하면 돼요.

clientId 지원은 Prometheus 버전 2.50.0에 추가됐어요.

Prometheus 설정 예시

main과 secondary라는 두 개의 Prometheus 배포가 있다고 가정해 봐요. 각 배포를 사용해 서로 다른 태그를 가진 서로 다른 데이터 플레인 프록시 집합을 모니터링하고 싶어요.

각 Prometheus 배포가 Kuma SD를 사용하도록 설정하는 것부터 시작할 수 있어요. Prometheus 배포는 client_id 파라미터로 구분돼요.

메인 Prometheus 설정:

scrape_configs:
  - job_name: 'kuma-dataplanes'
    # ...
    kuma_sd_configs:
    - server: http://kong-mesh-control-plane.kong-mesh-system:5676
      refresh_interval: 60s # different from prometheus-secondary
      client_id: "prometheus-main" # Kuma will use this to pick proper data plane proxies

세컨더리 Prometheus 설정:

scrape_configs:
  - job_name: 'kuma-dataplanes'
    # ...
    kuma_sd_configs:
      - server: http://kong-mesh-control-plane.kong-mesh-system:5676
        refresh_interval: 20s # different from prometheus-main
        client_id: "prometheus-secondary"

이제 첫 번째 MeshMetric 정책을 설정해서 prometheus: main 태그가 붙은 데이터 플레인 프록시를 메인 Prometheus 디스커버리 대상으로 선택하게 할 수 있어요. 정책의 clientId는 Prometheus 설정의 client_id와 같아야 해요.

####### Kubernetes

apiVersion: kuma.io/v1alpha1
kind: MeshMetric
metadata:
  name: prometheus-one
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: default
spec:
  targetRef:
    kind: Dataplane
    labels:
      prometheus: main
  default:
    backends:
    - type: Prometheus
      prometheus:
        clientId: prometheus-main
        port: 5670
        path: "/metrics"

####### Universal

type: MeshMetric
name: prometheus-one
mesh: default
spec:
  targetRef:
    kind: Dataplane
    labels:
      prometheus: main
  default:
    backends:
    - type: Prometheus
      prometheus:
        clientId: prometheus-main
        port: 5670
        path: "/metrics"

####### Terraform

현재 설정에 맞게 konnect_mesh_control_plane.my_meshcontrolplane.id와 konnect_mesh.my_mesh.name을 조정하세요. {: .text-sm}

resource "konnect_mesh_metric" "prometheus_one" {
  provider = konnect-beta
  type = "MeshMetric"
  name = "prometheus-one"
  spec = {
    target_ref = {
      kind = "Dataplane"
      labels = {
        prometheus = "main"
      }
    }
    default = {
      backends = [
        {
          type = "Prometheus"
          prometheus = {
            client_id = "prometheus-main"
            port = "5670"
            path = "/metrics"
          }
        }
      ]
    }
  }
  labels   = {
  "kuma.io/mesh" = konnect_mesh.my_mesh.name
  }
  cp_id    = konnect_mesh_control_plane.my_meshcontrolplane.id
  mesh     = konnect_mesh.my_mesh.name
}

그리고 prometheus: secondary 태그가 붙은 데이터 플레인 프록시를 선택할 세컨더리 Prometheus 배포용 정책이에요.

####### Kubernetes

apiVersion: kuma.io/v1alpha1
kind: MeshMetric
metadata:
  name: prometheus-two
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: default
spec:
  targetRef:
    kind: Dataplane
    labels:
      prometheus: secondary
  default:
    backends:
    - type: Prometheus
      prometheus:
        clientId: prometheus-secondary
        port: 5670
        path: "/metrics"

####### Universal

type: MeshMetric
name: prometheus-two
mesh: default
spec:
  targetRef:
    kind: Dataplane
    labels:
      prometheus: secondary
  default:
    backends:
    - type: Prometheus
      prometheus:
        clientId: prometheus-secondary
        port: 5670
        path: "/metrics"

####### Terraform

현재 설정에 맞게 konnect_mesh_control_plane.my_meshcontrolplane.id와 konnect_mesh.my_mesh.name을 조정하세요. {: .text-sm}

resource "konnect_mesh_metric" "prometheus_two" {
  provider = konnect-beta
  type = "MeshMetric"
  name = "prometheus-two"
  spec = {
    target_ref = {
      kind = "Dataplane"
      labels = {
        prometheus = "secondary"
      }
    }
    default = {
      backends = [
        {
          type = "Prometheus"
          prometheus = {
            client_id = "prometheus-secondary"
            port = "5670"
            path = "/metrics"
          }
        }
      ]
    }
  }
  labels   = {
  "kuma.io/mesh" = konnect_mesh.my_mesh.name
  }
  cp_id    = konnect_mesh_control_plane.my_meshcontrolplane.id
  mesh     = konnect_mesh.my_mesh.name
}

OpenTelemetry

backends:
  - type: OpenTelemetry
    openTelemetry: 
      endpoint: otel-collector.observability.svc:4317
      refreshInterval: 60s

이 설정은 Kong Mesh Dataplane Proxy가 OpenTelemetry collector로 메트릭을 푸시하도록 지시해요. Dataplane Proxy는 Pod/VM 안에서 Envoy와 다른 애플리케이션으로부터 메트릭을 스크레이프해서 설정된 OpenTelemetry collector로 푸시하며, 기본값은 60초마다예요(refreshInterval로 변경할 수 있어요).

애플리케이션 스크레이핑을 설정할 때는 OpenTelemetry scoping을 사용하도록 application.name을 반드시 지정하세요.

관련 리소스

더 알아보기 (Learn more)