跳到主要内容

用户稳定进入灰度组

大部分情况下,我们希望在一个功能的灰度放量过程中,某个特定用户一旦进入了灰度放量组,在灰度比例不减少的情况下,总是进入灰度组。 不希望用户因为刷新页面、重新打开APP、请求被分配到另一个服务端实例等原因,一会看到新功能,一会看不到新功能,从而感到迷惑。 这种应用场景我们称之为『用户稳定进入灰度组』。

以下我们介绍如何使用 FeatureProbe SDK 以达到稳定进组的效果。

平台创建开关

这里我们复用 tutorial_rollout 开关,创建过程参考这里

编写后端代码

  1. 参考这里 1-4 步,准备后端代码环境。
  2. 将用户唯一ID(以下例子中假设共100个用户,id为0-99),通过 stableRollout 函数传入FeatureProbe SDK
src/main/java/com/featureprobe/sdk/example/FeatureProbeDemo.java
    public static void main(String[] args) throws IOException {

Logger root = (Logger)LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.WARN);

final FPConfig config = FPConfig.builder()
.remoteUri(FEATURE_PROBE_SERVER_URL)
.build();

// Init FeatureProbe, share this FeatureProbe instance in your project.
final FeatureProbe fpClient = new FeatureProbe(FEATURE_PROBE_SERVER_SDK_KEY, config);

for (Integer i = 0; i < 100; i++) {
FPUser user = new FPUser().stableRollout(i.toString());
Boolean isOpen = fpClient.boolValue("tutorial_rollout", user, false);
System.out.println("feature for user " + i + " is :" + isOpen);
}
fpClient.close();
}
  1. 运行编辑后的服务端程序
mvn package
java -jar ./target/server-sdk-java-1.4.0.jar

验证结果

  1. 从命令行log可以看到,有大约10%的用户进入了开关,且不论运行多少次(甚至是使用不同语言SDK),都是相同id(例如:13,15,16)的用户拿到了true。
10% 放量的log示例
feature for user 0 is :false
feature for user 1 is :false
feature for user 2 is :false
feature for user 3 is :false
feature for user 4 is :false
feature for user 5 is :false
feature for user 6 is :false
feature for user 7 is :false
feature for user 8 is :false
feature for user 9 is :false
feature for user 10 is :false
feature for user 11 is :false
feature for user 12 is :false
feature for user 13 is :true
feature for user 14 is :false
feature for user 15 is :true
feature for user 16 is :true
feature for user 17 is :false
feature for user 18 is :false
feature for user 19 is :false
feature for user 20 is :false
  1. 平台上调大放量比例到50%,可以看到50%用户拿到了true,且之前拿到true的用户(例如id:13,15,16)仍然拿到了true。
50% 放量的log示例
feature for user 0 is: false
feature for user 1 is: false
feature for user 2 is: false
feature for user 3 is: false
feature for user 4 is: true
feature for user 5 is: true
feature for user 6 is: false
feature for user 7 is: false
feature for user 8 is: false
feature for user 9 is: false
feature for user 10 is: false
feature for user 11 is: false
feature for user 12 is: false
feature for user 13 is: true
feature for user 14 is: true
feature for user 15 is: true
feature for user 16 is: true
feature for user 17 is: true
feature for user 18 is: false
feature for user 19 is: false