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

Azure Application Insights

원문 보기 위키 갱신

Azure Application Insights의 메트릭 값에 따라 파드를 스케일링하고 싶다면 azure-app-insights 트리거를 사용하면 돼요. KEDA가 Application Insights REST API를 호출해 지정한 메트릭을 조회하고, 그 값이 목표치를 넘으면 레플리카를 늘려 줍니다.

출처: 문서

본문

Trigger Specification

이 명세는 Azure Application Insights 메트릭을 기준으로 스케일링하는 azure-app-insights 트리거를 설명해요.

triggers:
- type: azure-app-insights
  metadata:
    metricAggregationTimespan: "0:1"
    metricAggregationType: avg
    metricFilter: cloud/roleName eq 'role_name'
    metricId: "customMetrics/example-metric"
    targetValue: "1.5"
    activationTargetValue: "5.5"
    activeDirectoryClientIdFromEnv: CLIENT_ID_ENV_NAME # Optional, can use TriggerAuthentication as well
    activeDirectoryClientPasswordFromEnv: CLIENT_PASSWORD_ENV_NAME # Optional, can use TriggerAuthentication as well
    applicationInsightsIdFromEnv: APP_ID # Optional, can use TriggerAuthentication as well
    tenantIdFromEnv: TENANT_ID` # Optional, can use TriggerAuthentication as well
    # Optional (Default: AzurePublicCloud)
    cloud: Private
    # Required when cloud = Private
    appInsightsResourceURL: https://api.applicationinsights.airgap.io/
    # Required when cloud = Private.
    activeDirectoryEndpoint: https://login.airgap.example/
    ignoreNullValues: true # Default is `false`. Set to `true` to ignore any errors with data extraction from a successful query. Set to `false` the scaler will return error when null values are discovered

이 스케일러는 Azure Application Insights REST API를 기반으로 해요. 자세한 내용은 이 페이지를 참고하세요.

파라미터 목록입니다.

  • tenantId - Azure 리소스가 포함된 테넌트의 Id예요. 인증에 사용돼요.
  • metricId - 조회할 Application Insights 메트릭의 이름이에요. 사용 가능한 메트릭 목록을 보려면 Azure Command Line Interface로 az monitor app-insights metrics get-metadata를 실행하세요.
  • targetValue - 스케일링 작업을 트리거할 목표 값이에요. (이 값은 float일 수 있어요)
  • activationTargetValue - 스케일러를 활성화하기 위한 목표 값이에요. activation에 대해 더 알아보세요. (기본값: 0, 선택 항목, 이 값은 float일 수 있어요)
  • metricAggregationType - Azure Application Insights 메트릭의 집계 방법이에요. 집계 방법은 메트릭마다 달라요. az monitor app-insights metrics get-metadata 명령으로 특정 메트릭에 적용되는 방법을 확인할 수 있어요. (흔한 집계 방법으로 avg, count, sum, min, max가 있어요)
  • metricAggregationInterval - 메트릭의 수집 시간으로 형식은 "hh:mm"이에요.
  • applicationInsightsId - 조회할 Application Insights 인스턴스의 Id예요. Azure Portal의 Application Insight의 API Access 블레이드에서 가져올 수 있는 GUID예요.
  • activeDirectoryClientId - Active Directory 클라이언트의 Id예요. 클라이언트는 Application Insights 인스턴스에 대해 Monitoring Reader 권한이 있어야 해요.
  • activeDirectoryClientPassword - Active Directory 클라이언트 비밀번호예요.
  • metricFilter - 필터를 사용해 메트릭 쿼리를 더 세부적으로 지정해요. 예를 들어 cloud/roleName eq 'example'이에요. (선택 항목)
  • cloud - Application Insights 인스턴스가 속한 클라우드 환경의 이름이에요. (값: AzurePublicCloud, AzureUSGovernmentCloud, AzureChinaCloud, Private, 기본값: AzurePublicCloud, 선택 항목)
  • appInsightsResourceURL - 클라우드 환경의 Application Insights REST API URL이에요. (cloud가 Private로 설정된 경우 필수이며, 예: AzureChinaCloud의 https://api.applicationinsights.azure.cn/)
  • activeDirectoryEndpoint - 클라우드 환경의 Active Directory 엔드포인트예요. (cloud가 Private로 설정된 경우 필수이며, 예: AzureChinaCloud의 https://login.chinacloudapi.cn/)
  • ignoreNullValues - 성공한 쿼리에서 데이터 추출 시 발생하는 모든 오류를 무시할지 여부예요. (값: true,false, 기본값: false, 선택 항목)

일부 파라미터는 metadata에 직접 설정하는 대신 환경 변수로 제공할 수 있어요. 환경 변수에서 값을 가져오는 데 사용할 수 있는 파라미터 목록입니다.

  • activeDirectoryClientIdFromEnv - Active Directory 애플리케이션의 Id를 담은 환경 변수의 이름이에요. (선택 항목)
  • activeDirectoryClientPasswordFromEnv - Active Directory 클라이언트 비밀번호를 담은 환경 변수의 이름이에요. (선택 항목)
  • applicationInsightsIdFromEnv - Application Insights Id를 담은 환경 변수의 이름이에요. (선택 항목)
  • tenantIdFromEnv - Application Insights 인스턴스가 포함된 테넌트의 Id를 담은 환경 변수의 이름이에요. (선택 항목)

Authentication Parameters

TriggerAuthentication CRD를 사용해 Azure Active Directory 자격 증명 세트를 제공하거나 pod identity를 사용해 인증을 구성할 수 있어요.

Credential 기반 인증:

  • activeDirectoryClientId - 최소한 Monitoring Reader 권한이 필요한 Active Directory 애플리케이션의 Id예요.
  • activeDirectoryClientPassword - Active Directory 애플리케이션의 비밀번호예요.
  • applicationInsightsId - 조회할 Application Insights 인스턴스의 Id예요.
  • tenantId - Azure 리소스가 포함된 테넌트의 Id예요.

principle은 Application Insights 인스턴스에서 메트릭을 조회하려면 Monitoring Reader 접근 권한이 필요해요.

Pod identity 기반 인증: Azure AD Workload Identity provider를 credential 기반 인증 대신 사용할 수 있어요. 다음 섹션에는 pod identity를 사용하는 TriggerAuthentication 예시가 있어요.

Example

다음 예시는 Application Insights에 연결하기 위한 TriggerAuthentication 사용을 보여줘요.

apiVersion: v1
kind: Secret
metadata:
  name: azure-app-insights-secrets
data:
  activeDirectoryClientId: <clientId>
  activeDirectoryClientPassword: <clientPassword>
  applicationInsightsId: <appInsightsAppId>
  tenantId: <tenantId>
---
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
  name: azure-app-insights-trigger-auth
spec:
  secretTargetRef:
    - parameter: activeDirectoryClientId
      name: azure-app-insights-secrets
      key: activeDirectoryClientId
    - parameter: activeDirectoryClientPassword
      name: azure-app-insights-secrets
      key: activeDirectoryClientPassword
    - parameter: applicationInsightsId
      name: azure-app-insights-secrets
      key: applicationInsightsId
    - parameter: tenantId
      name: azure-app-insights-secrets
      key: tenantId
  # or Pod Identity, kind: Secret is not required in case of pod Identity
  podIdentity:
      provider: azure-workload
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: azure-app-insights-scaler
spec:
  scaleTargetRef:
    name: azure-app-insights-example
  minReplicaCount: 1
  maxReplicaCount: 10
  triggers:
  - type: azure-app-insights
    metadata:
      metricId: "customMetrics/example-metric"
      metricAggregationTimespan: "0:5"
      metricAggregationType: avg
      metricFilter: cloud/roleName eq 'example'
      targetValue: "1"
    authenticationRef:
      name: azure-app-insights-trigger-auth

다음 예시는 환경 변수를 사용해 Application Insights에 연결하는 방법을 보여줘요.

apiVersion: v1
kind: Secret
metadata:
  name: azure-app-insights-secrets
type: Opaque
data:
  activeDirectoryClientId: <clientId>
  activeDirectoryClientPassword: <clientPassword>
  applicationInsightsId: <appInsightsAppId>
  tenantId: <tenantId>
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: azure-app-insights-example
spec:
  replicas: 0
  selector:
    matchLabels:
      app: azure-app-insights-example
  template:
    metadata:
      labels:
        app: azure-app-insights-example
    spec:
      containers:
      - name: example
        image: nginx:1.16.1
        env:
        - name: ACTIVE_DIRECTORY_ID
          valueFrom:
            secretKeyRef:
              name: azure-app-insights-secrets
              key: activeDirectoryClientId
        - name: ACTIVE_DIRECTORY_PASSWORD
          valueFrom:
            secretKeyRef:
              name: azure-app-insights-secrets
              key: activeDirectoryClientPassword
        - name: APP_INSIGHTS_APP_ID
          valueFrom:
            secretKeyRef:
              name: azure-app-insights-secrets
              key: applicationInsightsId
        - name: TENANT_ID
          valueFrom:
            secretKeyRef:
              name: azure-app-insights-secrets
              key: tenantId
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: azure-app-insights-scaler
spec:
  scaleTargetRef:
    name: azure-app-insights-example
  pollingInterval: 5
  cooldownPeriod: 5
  minReplicaCount: 0
  maxReplicaCount: 2
  triggers:
    - type: azure-app-insights
      metadata:
        metricId: "customMetrics/example-metric"
        metricAggregationTimespan: "0:5"
        metricAggregationType: avg
        metricFilter: cloud/roleName eq 'example'
        targetValue: "1"
        activeDirectoryClientIdFromEnv: ACTIVE_DIRECTORY_ID
        activeDirectoryClientPasswordFromEnv: ACTIVE_DIRECTORY_PASSWORD
        applicationInsightsIdFromEnv: APP_INSIGHTS_APP_ID
        tenantIdFromEnv: TENANT_ID

더 알아보기 (Learn more)

Application Insights 스케일러를 구성할 때는 조회 대상 클라이언트(principal)에 Monitoring Reader 권한이 반드시 있어야 하며, 인증 정보는 TriggerAuthentication이나 환경 변수 중 환경에 맞는 방법으로 안전하게 전달해 주세요.