Prometheus Azure AD에서 Azure Monitor Managed Service for Prometheus로 마이그레이션

Prometheus Azure AD에서 Azure Monitor Managed Service for Prometheus로 마이그레이션

경고: Azure Monitor Managed Service for Prometheus용 핵심 Prometheus 데이터 소스와 함께 Azure AD 인증을 사용하는 것은 **비권장(deprecated)**이에요. Grafana 13에서는 전용 Azure Monitor Managed Service for Prometheus 데이터 소스로의 마이그레이션이 자동으로 이뤄져요. Azure AD 인증을 사용하는 기존 데이터 소스는 시작 시 마이그레이션돼요.

이 변경의 배경은 Prometheus 데이터 소스 업데이트: Our big tent 철학 재정의 블로그를 참고하세요. Grafana 13에서 Azure AD로 Prometheus를 쓰는 중이라면 자동 마이그레이션으로 별도 조치 없이 전용 플러그인으로 전환되는 흐름을 정리했어요.

출처: Migrate from Prometheus Azure AD to Azure Monitor Managed Service for Prometheus

본문

Grafana 13에서 바뀐 점

Grafana 13에서는 prometheusTypeMigration 기능 토글이 기본적으로 활성화되고 비권장 처리돼요. 이는 다음을 의미해요.

  • Azure AD 인증으로 구성된 Prometheus 데이터 소스는 Grafana 시작 시 전용 Azure Monitor Managed Service for Prometheus 플러그인으로 자동 마이그레이션돼요.
  • 기능 토글을 수동으로 활성화할 필요가 없어요.
  • Grafana Cloud 사용자는 별도 조치 없이 자동으로 마이그레이션돼요.
  • 마이그레이션 후 대시보드, 알림, 쿼리는 변경 없이 계속 동작해요.

마이그레이션 상태 확인

Prometheus 데이터 소스가 마이그레이션됐는지 확인하려면:

  1. Connections > Data sources로 이동해요.
  2. Prometheus 데이터 소스를 선택해요.
  3. 구성 페이지 상단의 마이그레이션 배너를 확인해요.

배너는 다음 메시지 중 하나를 표시해요.

  • "Migration Notice": 데이터 소스가 Azure Monitor Managed Service for Prometheus 플러그인으로 마이그레이션됨
  • "Deprecation Notice": 데이터 소스가 아직 마이그레이션되지 않음
  • 배너 없음: 마이그레이션이 필요 없음(Azure AD 인증을 사용하지 않는 데이터 소스)

Azure Monitor Managed Service for Prometheus 데이터 소스 구성

마이그레이션 후(또는 새 설정에서) 전용 플러그인을 구성해요.

  1. Connections > Data sources로 이동해요.
  2. Azure Monitor Managed Service for Prometheus 데이터 소스를 선택해요.
  3. Authentication 섹션에서 인증 방법을 선택해요.
방법 용도 추가 구성 필요
Managed Identity Azure 호스팅 Grafana 인스턴스 없음(system-assigned) 또는 Client ID(user-assigned)
App Registration 서비스 주체 인증 Directory ID, Application ID, Client secret
Current User 현재 사용자의 Entra ID 자격 증명 없음

Managed Identity 인증에서:

  • system-assigned ID를 사용한다면 추가 구성이 필요 없어요.
  • user-assigned ID라면 Client ID를 제공해요.

App Registration 인증에서:

설정 설명 예시
Directory (tenant) ID Entra ID 테넌트 ID 12345678-1234-1234-1234-123456789012
Application (client) ID 앱 등록 클라이언트 ID 87654321-4321-4321-4321-210987654321
Client secret 앱 등록 시크릿 your-client-secret

Grafana용 Entra ID 인증에 대해 더 배우려면 Entra ID OAuth 인증 구성을 참고하세요.

  1. Prometheus server URL을 Azure Monitor 워크스페이스 엔드포인트로 설정해요.
https://your-workspace.eastus2.prometheus.monitor.azure.com
  1. Save & test를 클릭해 연결을 확인해요.

데이터 소스 프로비저닝

apiVersion: 1
datasources:
  - name: Azure Monitor Prometheus
    type: grafana-azureprometheus-datasource
    url: https://your-workspace.eastus2.prometheus.monitor.azure.com
    jsonData:
      azureCredentials:
        authType: clientsecret
        azureCloud: AzureCloud
        clientId: <CLIENT_ID>
        tenantId: <TENANT_ID>
      httpMethod: POST
    secureJsonData:
      azureClientSecret: <CLIENT_SECRET>

<CLIENT_ID>, <TENANT_ID>, <CLIENT_SECRET>를 Azure 자격 증명으로 바꿔요.

마이그레이션 문제 해결

다음 섹션은 마이그레이션 중 또는 후에 겪을 수 있는 일반적인 문제와 해결 방법을 다뤄요.

Azure Monitor Managed Service for Prometheus 플러그인이 설치되지 않음

증상: 마이그레이션이 발생하지 않거나 데이터 소스 유형이 없음.

해결책:

  1. Connections > Add new connection으로 이동해 "Azure Monitor Managed Service for Prometheus"를 검색해요.
  2. 플러그인이 설치되어 있지 않으면 설치해요.
  3. 에어갭 환경에서는 Grafana 플러그인 카탈로그에서 플러그인을 다운로드해 수동으로 설치해요.

마이그레이션 후 "401 Unauthorized"

증상: 마이그레이션된 데이터 소스가 인증 오류를 반환해요.

해결책:

  1. 셀프 관리 Grafana: .ini 구성 파일의 [azure] 헤딩 아래 forward_settings_to_pluginsgrafana-azureprometheus-datasource가 포함되어 있는지 확인해요.
  2. Grafana Cloud: Grafana Support에 문의해요.

마이그레이션 롤백

마이그레이션된 데이터 소스를 핵심 Prometheus 유형으로 되돌려야 한다면:

  1. Grafana 구성 기능 토글에서 prometheusTypeMigrationfalse로 설정해요. 자세한 내용은 Manage feature toggles 참고.
  2. Grafana를 다시 시작해요.
  3. 데이터 소스 API에 대한 readwrite 권한이 있는 베어러 토큰을 얻어요. 자세한 내용은 Data source API 참고.
  4. Grafana URL과 베어러 토큰을 제공하고 다음 롤백 스크립트를 실행해요.
#!/bin/bash

GRAFANA_URL=""
BEARER_TOKEN=""
LOG_FILE="grafana_azure_migration_rollback_$(date +%Y%m%d_%H%M%S).log"

log_message() {
    local message="$1"
    local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
    echo "[$timestamp] $message" | tee -a "$LOG_FILE"
}

update_data_source() {
    local uid="$1"
    local data="$2"

    response=$(curl -s -w "\n%{http_code}" -X PUT \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer ***" \
        -d "$data" \
        "$GRAFANA_URL/api/datasources/uid/$uid")

    http_code=$(echo "$response" | tail -n1)
    response_body=$(echo "$response" | sed '$d')

    if [[ "$http_code" -ge 200 && "$http_code" -lt 300 ]]; then
        log_message "$uid reverted successfully"
    else
        log_message "$uid error: HTTP $http_code - $response_body"
    fi
}

if ! command -v jq &> /dev/null; then
    echo "Error: jq is required but not installed."
    exit 1
fi

if [[ -z "$GRAFANA_URL" || -z "$BEARER_TOKEN" ]]; then
    echo "Error: Set GRAFANA_URL and BEARER_TOKEN variables at the top of the script."
    exit 1
fi

log_message "Starting Azure Prometheus to core Prometheus rollback"

response=$(curl -s -w "\n%{http_code}" -X GET \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ***" \
    "$GRAFANA_URL/api/datasources/")

http_code=$(echo "$response" | tail -n1)
response_body=$(echo "$response" | sed '$d')

if [[ "$http_code" -lt 200 || "$http_code" -ge 300 ]]; then
    log_message "Error fetching data sources: HTTP $http_code"
    exit 1
fi

total=$(echo "$response_body" | jq '[.[] | select(.jsonData["prometheus-type-migration"] == true and .type == "grafana-azureprometheus-datasource")] | length')
log_message "Found $total data sources to revert"

echo "$response_body" | jq -c '.[] | select(.jsonData["prometheus-type-migration"] == true and .type == "grafana-azureprometheus-datasource")' | while read -r data; do
    uid=$(echo "$data" | jq -r '.uid')
    read_only=$(echo "$data" | jq -r '.readOnly // false')

    if [[ "$read_only" == "true" ]]; then
        log_message "$uid is readOnly; edit the type to 'prometheus' in the provisioning file instead."
        continue
    fi

    updated_data=$(echo "$data" | jq '.type = "prometheus" | .jsonData["prometheus-type-migration"] = false')
    update_data_source "$uid" "$updated_data"
done

log_message "Rollback complete. Log: $LOG_FILE"

참고: 프로비저닝된 데이터 소스(readOnly)는 API로 되돌릴 수 없어요. 대신 프로비저닝 YAML 파일에서 type 필드를 prometheus로 업데이트하세요.

계속 문제가 발생하면 Grafana 서버 로그에서 상세 오류 메시지를 확인하고 Grafana Support에 문의해요.

더 알아보기 (Learn more)