점진적 기능 출시 사용

이 가이드에서는 App Lifecycle Manager 기능 플래그를 사용하여 점진적 기능 출시를 구성하고 실행하는 방법을 설명합니다. 타겟팅 속성을 정의하고, 비율 기반 할당을 구성하고, 점진적 출시를 안전하게 실행하는 방법을 알아봅니다.

userID 속성으로 무작위로 추출된 트래픽의 1% 에 대해서만 enhanced-search 알고리즘을 사용 설정하고 나머지 99% 는 일반 검색을 계속 사용하는 시나리오를 사용합니다.

기본 요건

시작하기 전에 표준 빠른 시작 중 하나를 완료하여 기준 인프라 또는 독립형 기능 플래그 리소스를 프로비저닝했는지 확인하세요.

애플리케이션에 플래그 통합

사용자 데이터를 기반으로 한 비율 기반 할당을 지원하려면 애플리케이션이 평가 메서드를 호출하기 전에 런타임에 속성 값(예: userID)을 OpenFeature 평가 컨텍스트에 연결해야 합니다.

다음 예시에서는 초기화된 클라이언트를 가져오고 타겟팅 컨텍스트가 연결된 플래그를 평가하는 방법을 보여줍니다.

Go

import (
    "context"
    "fmt"
    "log"

    "github.com/open-feature/go-sdk/openfeature"
)

// Example userID - in a real application, this would come from the request context.
var userID = "example-user-123"

// 1. Get client
client := openfeature.NewClient("simple-api")

// 2. Create Evaluation Context with user data
evalCtx := openfeature.NewEvaluationContext(
    userID,
    map[string]interface{}{
        "userID": userID, // Ensure userID is passed dynamically
    },
)

// 3. Evaluate flag (defaults to false if unreachable)
isEnhanced, err := client.BooleanValue(context.Background(), "enhanced-search", false, evalCtx)
if err != nil {
    log.Printf("Flag evaluation failed: %v", err)
}

// 4. Execute business logic
if isEnhanced {
    log.Printf("Enhanced search algorithm for user %s", userID)
} else {
    log.Printf("Standard search algorithm for user %s", userID)
}

자바

// 1. Get client
var client = OpenFeatureAPI.getInstance().getClient("simple-api");

// 2. Create Evaluation Context with user data
var context = new dev.openfeature.sdk.MutableContext();
context.add("userID", userID);

// 3. Evaluate flag
boolean isEnhanced = client.getBooleanValue("enhanced-search", false, context);

// 4. Execute business logic
if (isEnhanced) {
    System.out.println("Executing enhanced search algorithm...");
} else {
    System.out.println("Executing standard search algorithm...");
}

Python

import openfeature
from openfeature.evaluation_context import EvaluationContext

# 1. Get client
client = openfeature.api.get_client()

# 2. Create Evaluation Context with user data
eval_ctx = EvaluationContext(
    targeting_key=str(user_id),
    attributes={
        "userID": user_id,
    }
)

# 3. Evaluate flag
is_enhanced = client.get_boolean_value(
    "enhanced-search",
    False,
    eval_ctx
)

# 4. Execute business logic
if is_enhanced:
    print(f"Executing enhanced search for user {user_id}")
else:
    print(f"Executing standard search for user {user_id}")

플래그 동작 구성

무작위 속성 매개변수를 정의하고 이를 기능 플래그 리소스의 백분율 기반 할당 규칙과 연결합니다.

  1. 타겟팅 속성 만들기: userID 속성 리소스를 전역으로 정의하여 타겟팅 평가에 등록합니다.

    gcloud beta app-lifecycle-manager flags attributes create "user-id-attr" \
      --key="userID" \
      --attribute-value-type="STRING" \
      --location="global"
    
  2. 플래그 할당 규칙 정의: userID에서 무작위로 추출된 enabled 대안에 1% 가중치를 할당하도록 기능 플래그 리소스를 구성합니다.

    gcloud beta app-lifecycle-manager flags create "enhanced-search" \
      --key="enhanced-search" \
      --flag-value-type=bool \
      --location="global" \
      --unit-kind="demo-test-unitkind" \
      --variants='[ { "id": "disabled", "booleanValue": false }, { "id": "enabled", "booleanValue": true } ]' \
      --evaluation-spec='{
        "allocations": [{
          "id": "percentage-rollout",
          "randomizedOn": "userID",
          "slots": [
            {"variant": "disabled", "weight": 99},
            {"variant": "enabled", "weight": 1}
          ]
        }],
        "defaultAllocation": "percentage-rollout",
        "attributes": ["projects/PROJECT_ID/locations/global/flagAttributes/user-id-attr"]
      }'
    

플래그 구성 출시 만들기

새로 만든 점진적 할당 규칙을 안전하게 배포하려면 표준 변경 불가 출시 단계를 진행합니다.

  1. 버전 만들기: 1% 할당 구성의 스냅샷을 캡처합니다.

    gcloud beta app-lifecycle-manager flags revisions create "enhanced-search-rev-1" \
       --location="global" \
       --flag="enhanced-search"
    
  2. 출시 버전 만들기: 단위 종류에 배포할 버전을 패키징합니다.

    gcloud beta app-lifecycle-manager flags releases create "release-of-enhanced-search" \
       --location="global" \
       --unit-kind="demo-test-unitkind" \
       --revisions="enhanced-search-rev-1"
    
  3. 출시 시작: 조정 전략을 정의하고 구성을 배포합니다.

    gcloud beta app-lifecycle-manager rollout-kinds create "rollout-kind-of-enhanced-search" \
       --unit-kind="demo-test-unitkind" \
       --rollout-orchestration-strategy="Google.Cloud.Simple.AllAtOnce" \
       --location="global"
    
    gcloud beta app-lifecycle-manager rollouts create "rollout-of-enhanced-search" \
       --flag-release="release-of-enhanced-search" \
       --rollout-kind="rollout-kind-of-enhanced-search" \
       --location="global"
    
  4. 출시 모니터링: 배포가 SUCCEEDED 상태에 도달하는지 확인합니다.

    gcloud beta app-lifecycle-manager rollouts describe "rollout-of-enhanced-search" \
       --location="global"
    

플래그 타겟팅 업데이트

1% 출시가 성공적이고 안정적이라고 판단되면 플래그의 내부 할당 가중치를 업데이트하여(예: 50%) 출시 비율 잠재고객을 확장합니다.

  1. 플래그 사양 업데이트: 할당 슬롯을 사용 설정 50%, 사용 중지 50% 로 변경합니다.

    gcloud beta app-lifecycle-manager flags update "enhanced-search" \
      --location="global" \
      --evaluation-spec='{
        "allocations": [{
          "id": "percentage-rollout",
          "randomizedOn": "userID",
          "slots": [
            {"variant": "disabled", "weight": 50},
            {"variant": "enabled", "weight": 50}
          ]
        }],
        "defaultAllocation": "percentage-rollout",
        "attributes": ["projects/PROJECT_ID/locations/global/flagAttributes/user-id-attr"]
      }'
    
  2. 확장 배포: 수명 주기에 따라 업데이트된 가중치를 연결된 클라이언트에 배포합니다.

    gcloud beta app-lifecycle-manager flags revisions create "enhanced-search-rev-2" \
       --location="global" \
       --flag="enhanced-search"
    
    gcloud beta app-lifecycle-manager flags releases create "enhanced-search-50pct" \
       --location="global" \
       --unit-kind="demo-test-unitkind" \
       --revisions="enhanced-search-rev-2"
    
    gcloud beta app-lifecycle-manager rollouts create "rollout-of-enhanced-search-50pct" \
       --flag-release="enhanced-search-50pct" \
       --rollout-kind="rollout-kind-of-enhanced-search" \
       --location="global"
    

    이 작업은 기능이 100% 배포될 때까지 계속 반복할 수 있습니다.

플래그 사용 중단

기능 플래그가 출시를 완료하고 표준 운영 동작으로 사용된 후에는 안전하게 사용 중지해야 합니다.

  1. 애플리케이션에서 삭제: 애플리케이션 코드베이스에서 모든 플래그 평가 조건부 로직을 삭제하고 업데이트된 페이로드를 프로덕션에 배포합니다.
  2. 정리 대상으로 표시: 플래그 상태를 CLEANUP로 설정하여 프로비저닝 해제 의도를 알립니다.

    gcloud beta app-lifecycle-manager flags update "enhanced-search" \
        --location="global" \
        --state=cleanup
    
  3. 최종 출시 배포: 플래그를 참조하는 플래그 출시를 만들고 출시하여 단위에서 플래그를 분리합니다.

    gcloud beta app-lifecycle-manager flags releases create "cleanup-enhanced-search" \
        --location="global" \
        --unit-kind="demo-test-unitkind" \
        --flags="enhanced-search"
    
    gcloud beta app-lifecycle-manager rollouts create "rollout-of-cleanup-enhanced-search" \
        --flag-release="cleanup-enhanced-search" \
        --rollout-kind="rollout-kind-of-enhanced-search" \
        --location="global"
    

    출시가 완료되면 관리 영역에서 플래그 출시 버전, 플래그 버전, 플래그를 삭제합니다.