요청/응답 유형에 따른 메트릭 분류

요청/응답 유형에 따른 메트릭 분류 (Classifying Metrics Based on Request or Response)

이 작업은 요청과 응답을 유형별로 묶어 텔레메트리를 개선하는 방법을 보여드려요. 메시의 서비스가 처리하는 요청/응답의 유형에 따라 텔레메트리를 시각화하면 유용해요.

출처: Istio 문서

본문

메시의 서비스가 처리하는 요청과 응답의 유형에 따라 텔레메트리를 시각화하면 유용해요. 예를 들어 서점에서는 책 리뷰가 요청된 횟수를 추적해요. 책 리뷰 요청은 이런 구조를 가져요.

GET /reviews/{review_id}

리뷰 요청 횟수를 세려면 무한한 요소인 review_id를 고려해야 해요. GET /reviews/1 다음에 GET /reviews/2가 오는 것은 리뷰를 가져오는 요청 두 번으로 세어야 해요. Istio는 AttributeGen 플러그인을 사용해서 분류 규칙을 만들 수 있게 해줘요. 이 플러그인은 요청을 고정된 수의 논리적 연산으로 묶어요. 예를 들어 GetReviews라는 연산을 만들 수 있는데, 이는 Open API Spec의 operationId를 사용해서 연산을 식별하는 일반적인 방법이에요. 이 정보는 GetReviews 값을 가진 istio_operationId 속성으로 요청 처리에 주입돼요. 이 속성을 Istio 표준 메트릭의 차원으로 사용할 수 있어요. 마찬가지로 ListReviews, CreateReviews 같은 다른 연산을 기준으로 메트릭을 추적할 수도 있어요.

요청별 메트릭 분류 (Classify metrics by request)

요청을 유형별로 분류할 수 있어요. 예: ListReview, GetReview, CreateReview.

  1. 예를 들어 attribute_gen_service.yaml 파일을 만들고 다음 내용으로 저장하세요. 이렇게 하면 istio.attributegen 플러그인이 추가돼요. 그리고 istio_operationId 속성을 만들고, 메트릭으로 셀 범주 값으로 채워요. 요청 경로는 보통 서비스별로 다르므로 이 구성은 서비스별로 정해져요.
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
  name: istio-attributegen-filter
spec:
  selector:
    matchLabels:
      app: reviews
  url: https://storage.googleapis.com/istio-build/proxy/attributegen-359dcd3a19f109c50e97517fe6b1e2676e870c4d.wasm
  imagePullPolicy: Always
  phase: AUTHN
  pluginConfig:
    attributes:
    - output_attribute: "istio_operationId"
      match:
        - value: "ListReviews"
          condition: "request.url_path == '/reviews' && request.method == 'GET'"
        - value: "GetReview"
          condition: "request.url_path.matches('^/reviews/[[:alnum:]]*$') && request.method == 'GET'"
        - value: "CreateReview"
          condition: "request.url_path == '/reviews/' && request.method == 'POST'"
---
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: custom-tags
spec:
  metrics:
    - overrides:
        - match:
            metric: REQUEST_COUNT
            mode: CLIENT_AND_SERVER
          tagOverrides:
            request_operation:
              value: filter_state['wasm.istio_operationId']
      providers:
        - name: prometheus
  1. 다음 명령으로 변경 사항을 적용하세요.
$ kubectl -n istio-system apply -f attribute_gen_service.yaml
  1. 변경 사항이 적용된 후 Prometheus에 접속해서 reviews 파드의 istio_requests_total 같은 새 차원이나 변경된 차원을 찾아보세요.

응답별 메트릭 분류 (Classify metrics by response)

요청과 비슷한 과정으로 응답을 분류할 수 있어요. response_code 차원은 기본적으로 이미 존재한다는 점에 주의하세요. 아래 예시는 이 값이 채워지는 방식을 바꿔요.

  1. 예를 들어 attribute_gen_service.yaml 파일을 만들고 다음 내용으로 저장하세요. 이렇게 하면 istio.attributegen 플러그인이 추가되고 stats 플러그인이 사용하는 istio_responseClass 속성이 생성돼요. 이 예시는 여러 응답을 분류하는데, 예를 들어 200 범위의 모든 응답 코드를 2xx 차원으로 묶어요.
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
  name: istio-attributegen-filter
spec:
  selector:
    matchLabels:
      app: productpage
  url: https://storage.googleapis.com/istio-build/proxy/attributegen-359dcd3a19f109c50e97517fe6b1e2676e870c4d.wasm
  imagePullPolicy: Always
  phase: AUTHN
  pluginConfig:
    attributes:
      - output_attribute: istio_responseClass
        match:
          - value: 2xx
            condition: response.code >= 200 && response.code <= 299
          - value: 3xx
            condition: response.code >= 300 && response.code <= 399
          - value: "404"
            condition: response.code == 404
          - value: "429"
            condition: response.code == 429
          - value: "503"
            condition: response.code == 503
          - value: 5xx
            condition: response.code >= 500 && response.code <= 599
          - value: 4xx
            condition: response.code >= 400 && response.code <= 499
---
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: custom-tags
spec:
  metrics:
    - overrides:
        - match:
            metric: REQUEST_COUNT
            mode: CLIENT_AND_SERVER
          tagOverrides:
            response_code:
              value: filter_state['wasm.istio_responseClass']
      providers:
        - name: prometheus
  1. 다음 명령으로 변경 사항을 적용하세요.
$ kubectl -n istio-system apply -f attribute_gen_service.yaml

결과 검증하기 (Verify the results)

  1. 애플리케이션으로 트래픽을 보내 메트릭을 생성하세요.
  2. Prometheus에 접속해서 2xx 같은 새 차원이나 변경된 차원을 찾아보세요. 또는 다음 명령으로 Istio가 새 차원에 대한 데이터를 생성하는지 확인할 수 있어요.
$ kubectl exec pod-name -c istio-proxy -- curl -sS 'localhost:15000/stats/prometheus' | grep istio_

출력에서 메트릭(예: istio_requests_total)을 찾아 새 차원이나 변경된 차원이 있는지 확인하세요.

문제 해결 (Troubleshooting)

분류가 예상대로 일어나지 않으면 다음 잠재적 원인과 해결책을 확인하세요. 구성 변경을 적용한 서비스가 있는 파드의 Envoy 프록시 로그를 검토하세요. 다음 명령으로 분류를 구성한 파드(pod-name)의 Envoy 프록시 로그에서 서비스가 보고한 오류가 없는지 확인하세요.

$ kubectl logs pod-name -c istio-proxy | grep -e "Config Error" -e "envoy wasm"

또한 다음 명령의 출력에서 재시작 징후를 찾아 Envoy 프록시 충돌이 없는지 확인하세요.

$ kubectl get pods pod-name

정리 (Cleanup)

yaml 구성 파일을 제거하세요.

$ kubectl -n istio-system delete -f attribute_gen_service.yaml

더 알아보기 (Learn more)

  • WasmPlugin과 AttributeGen 플러그인에 대한 자세한 내용은 Istio 확장 문서를 참고하세요.
  • Telemetry API에서 메트릭 overrides에 대해 더 알아보세요.