launchdarkly-flag-targeting

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

LaunchDarkly Flag Targeting & Rollout

LaunchDarkly 标志定向与灰度发布

You're using a skill that will guide you through changing who sees what for a feature flag. Your job is to understand the current state of the flag, figure out the right targeting approach for what the user wants, make the changes safely, and verify the resulting state.
你正在使用一项可引导你调整功能标志受众范围的技能。你的任务是了解标志的当前状态,为用户需求选择合适的定向方案,安全地完成配置变更,并验证最终状态。

Prerequisites

前置条件

This skill requires the remotely hosted LaunchDarkly MCP server to be configured in your environment.
Required MCP tools:
  • get-flag
    — understand current state before making changes
  • toggle-flag
    — turn targeting on or off for a flag in an environment
  • update-rollout
    — change the default rule (fallthrough) variation or percentage rollout
  • update-targeting-rules
    — add, remove, or modify custom targeting rules
  • update-individual-targets
    — add or remove specific users/contexts from individual targeting
Optional MCP tools:
  • copy-flag-config
    — copy targeting configuration from one environment to another
使用此技能需要在环境中配置远程托管的LaunchDarkly MCP服务器。
必需的MCP工具:
  • get-flag
    — 变更前了解标志当前状态
  • toggle-flag
    — 在指定环境中开关标志的定向功能
  • update-rollout
    — 修改默认规则(兜底规则)的变体或按百分比灰度发布配置
  • update-targeting-rules
    — 添加、删除或修改自定义定向规则
  • update-individual-targets
    — 在单个定向列表中添加或移除特定用户/上下文
可选的MCP工具:
  • copy-flag-config
    — 将定向配置从一个环境复制到另一个环境

Core Concept: Evaluation Order

核心概念:评估顺序

Before making any targeting changes, understand how LaunchDarkly evaluates flags. This determines what your changes actually do:
  1. Flag is OFF → Serve the
    offVariation
    to everyone. Nothing else matters.
  2. Individual targets → If the context matches a specific target list, serve that variation. Highest priority.
  3. Custom rules → Evaluate rules top-to-bottom. First matching rule wins.
  4. Default rule (fallthrough) → If nothing else matched, serve this variation or rollout.
This means: if you add a targeting rule but the flag is OFF, nobody sees the change. If you set a percentage rollout on the default rule but there's an individual target, that targeted user bypasses the rollout.
在进行任何定向变更前,需了解LaunchDarkly的标志评估逻辑,这将决定你的变更实际效果:
  1. 标志处于关闭状态 → 向所有用户返回
    offVariation
    ,其他配置均不生效。
  2. 单个目标用户 → 如果上下文匹配特定目标列表,返回对应的变体。优先级最高。
  3. 自定义规则 → 从上到下依次评估规则,第一个匹配的规则生效。
  4. 默认规则(兜底规则) → 如果没有匹配任何其他规则,返回此规则的变体或灰度发布结果。
这意味着:如果标志处于关闭状态,即使添加定向规则也不会有任何用户看到变更;如果在默认规则中设置了百分比灰度发布,但存在单个目标用户,该目标用户将绕过灰度发布配置。

Workflow

工作流程

Step 1: Understand Current State

步骤1:了解当前状态

Before changing anything, check what's already configured.
  1. Confirm the environment. "Turn it on" without specifying an environment is ambiguous. Always confirm which environment the user means. Default to asking rather than assuming.
  2. Fetch the flag. Use
    get-flag
    with the target environment to see:
    • on
      — Is targeting currently enabled?
    • fallthrough
      — What's the default rule? (variation or percentage rollout)
    • offVariation
      — What serves when the flag is off?
    • rules
      — Any custom targeting rules?
    • targets
      — Any individually targeted users/contexts?
    • prerequisites
      — Any flags this depends on?
  3. Assess complexity. A flag with no rules and no individual targets is simple. A flag with multiple rules, targets, and prerequisites needs more care.
在进行任何变更前,先检查已有的配置。
  1. 确认环境。仅说“开启它”而未指定环境是模糊的,务必确认用户指的是哪个环境。默认情况下应询问用户,而非自行假设。
  2. 获取标志信息。使用
    get-flag
    工具查询目标环境的标志,查看以下内容:
    • on
      — 当前是否启用了定向功能?
    • fallthrough
      — 默认规则是什么?(变体或百分比灰度发布)
    • offVariation
      — 标志关闭时返回的变体是什么?
    • rules
      — 是否存在自定义定向规则?
    • targets
      — 是否有单个目标用户/上下文?
    • prerequisites
      — 此标志是否依赖其他标志?
  3. 评估复杂度。没有规则和单个目标的标志配置简单;包含多个规则、目标和依赖项的标志需要更谨慎处理。

Step 2: Determine the Right Approach

步骤2:选择合适的方案

Based on what the user wants and what you found, choose the right tool and strategy. See Targeting Patterns for the full reference.
Common scenarios:
User wantsToolNotes
"Turn it on"
toggle-flag
with
on: true
Simplest change
"Turn it off"
toggle-flag
with
on: false
Serves offVariation to everyone
"Roll out to X%"
update-rollout
with
rolloutType: "percentage"
Weights must sum to 100
"Enable for beta users"
update-targeting-rules
— add a rule with clause
Rules are ANDed within, ORed between
"Add specific users"
update-individual-targets
Highest priority, overrides all rules
"Full rollout"
update-rollout
with
rolloutType: "variation"
Serve one variation to everyone
"Copy from staging"
copy-flag-config
Promote tested config to production
根据用户需求和当前状态,选择合适的工具和策略。详细参考定向模式文档。
常见场景:
用户需求使用工具注意事项
"开启功能"
toggle-flag
并设置
on: true
最简单的变更操作
"关闭功能"
toggle-flag
并设置
on: false
向所有用户返回
offVariation
"按X%灰度发布"
update-rollout
并设置
rolloutType: "percentage"
权重总和必须为100
"向beta用户开放"
update-targeting-rules
— 添加包含子句的规则
规则内部为逻辑与关系,规则之间为逻辑或关系
"添加特定用户"
update-individual-targets
优先级最高,覆盖所有规则
"全量发布"
update-rollout
并设置
rolloutType: "variation"
向所有用户返回同一个变体
"从预发布环境复制配置"
copy-flag-config
将经过测试的配置同步到生产环境

Step 3: Run the Safety Checklist

步骤3:执行安全检查清单

Before applying changes, especially in production, run through the Safety Checklist. The key checks:
  1. Right environment? Double-check you're targeting the intended environment.
  2. Approval required? Some environments require approval workflows. If
    toggle-flag
    or other tools return
    requiresApproval: true
    , surface this to the user with the approval URL.
  3. Prerequisite flags? If this flag has prerequisites, they must be met before targeting works as expected.
  4. Rule ordering impact? If adding rules, consider where they fall in evaluation order. Rules evaluate top-to-bottom, first match wins.
  5. Include a comment. Always add an audit trail comment, especially for production changes.
在应用变更前,尤其是生产环境,需完成安全检查清单中的内容。关键检查项:
  1. 是否为正确环境? 再次确认目标环境是否正确。
  2. 是否需要审批? 部分环境需要审批流程。如果
    toggle-flag
    或其他工具返回
    requiresApproval: true
    ,需将审批链接告知用户。
  3. 是否存在依赖标志? 如果此标志有依赖项,需确保依赖项已满足要求,定向配置才能按预期生效。
  4. 规则顺序是否有影响? 添加规则时,需考虑其在评估顺序中的位置。规则从上到下评估,第一个匹配的规则生效。
  5. 添加审计注释。尤其是生产环境的变更,务必添加审计注释留痕。

Step 4: Apply Changes

步骤4:应用变更

Use the appropriate tool for the change. Key notes:
  • toggle-flag
    : Specify
    on: true
    or
    on: false
    , the
    env
    , and a
    comment
    .
  • update-rollout
    : Use
    rolloutType: "percentage"
    with human-friendly weights (e.g., 80 for 80%) that sum to 100, or
    rolloutType: "variation"
    with a
    variationIndex
    .
  • update-targeting-rules
    : Instructions support
    addRule
    ,
    removeRule
    ,
    updateRuleVariationOrRollout
    ,
    addClauses
    ,
    removeClauses
    ,
    reorderRules
    .
  • update-individual-targets
    : Instructions support
    addTargets
    ,
    removeTargets
    ,
    addContextTargets
    ,
    removeContextTargets
    ,
    replaceTargets
    .
See Targeting Patterns for detailed instruction examples.
使用对应的工具执行变更。关键注意事项:
  • toggle-flag
    :需指定
    on: true
    on: false
    env
    环境参数,以及
    comment
    注释。
  • update-rollout
    :使用
    rolloutType: "percentage"
    时传入易读的百分比数值(例如80代表80%),权重总和需为100;或使用
    rolloutType: "variation"
    并指定
    variationIndex
  • update-targeting-rules
    :支持的操作包括
    addRule
    removeRule
    updateRuleVariationOrRollout
    addClauses
    removeClauses
    reorderRules
  • update-individual-targets
    :支持的操作包括
    addTargets
    removeTargets
    addContextTargets
    removeContextTargets
    replaceTargets
详细的指令示例请参考定向模式

Step 5: Verify

步骤5:验证结果

After applying changes, confirm the result:
  1. Fetch the updated flag. Use
    get-flag
    again to verify the new state.
  2. Confirm what the user expects. Describe the resulting targeting in plain language:
    • "The flag is now ON in production, serving
      true
      to 25% of users and
      false
      to 75%."
    • "Beta users now see variation A. Everyone else gets the default (variation B)."
  3. Check for side effects. If there are rules or individual targets, make sure the change interacts correctly with them.
应用变更后,确认最终状态是否符合预期:
  1. 获取更新后的标志信息。再次使用
    get-flag
    工具验证新的配置状态。
  2. 向用户确认预期效果。用通俗易懂的语言描述最终的定向配置:
    • “该标志现已在生产环境启用,向25%的用户返回
      true
      ,向75%的用户返回
      false
      。”
    • “Beta用户现在看到变体A,其他用户看到默认变体B。”
  3. 检查副作用。如果存在规则或单个目标用户,需确保变更与现有配置的交互符合预期。

Important Context

重要说明

  • update-rollout
    uses human-friendly percentages.
    Pass 80 for 80%, not 80000. The tool handles the internal weight conversion.
  • Weights must sum to 100. For percentage rollouts, the weights across all variations must total exactly 100.
  • Rule ordering matters. Rules evaluate top-to-bottom. Reordering rules can change behavior without changing any individual rule.
  • Individual targets are highest priority. They override all rules and the default. Adding someone as an individual target means rules don't apply to them.
  • "Launched" flags are still ON. A flag with status "launched" is serving a single variation to everyone. If you want to remove the flag, use the cleanup skill, not targeting changes.
  • update-rollout
    使用易读的百分比数值
    。传入80代表80%,而非80000。工具会自动处理内部权重转换。
  • 权重总和必须为100。百分比灰度发布时,所有变体的权重总和必须恰好为100。
  • 规则顺序至关重要。规则从上到下评估,调整规则顺序可能会改变标志行为,即使单个规则内容未变。
  • 单个目标用户优先级最高。单个目标用户覆盖所有规则和默认配置。将用户添加为单个目标后,规则对其不再生效。
  • “已发布”的标志仍处于启用状态。状态为“launched”的标志向所有用户返回同一个变体。如果需要移除标志,请使用清理技能,而非修改定向配置。

References

参考文档

  • Targeting Patterns — Rollout strategies, rule construction, individual targeting, and cross-environment copying
  • Safety Checklist — Pre-change verification, approval workflows, environment awareness
  • 定向模式 — 灰度发布策略、规则构建、单个目标配置、跨环境复制配置
  • 安全检查清单 — 变更前验证、审批流程、环境确认