云眼配置

云眼About 5 min

云眼配置

本主题介绍如何使用云眼灰度试验 Java SDK 的 EyeofcloudConfig 访问数据文件中的项目配置数据。

建议修改

概述

云眼灰度试验 SDK 打开一组定义良好的公共 API,隐藏所有实现详细信息。但是,某些客户端可能需要访问数据文件中的项目配置数据

在本文档中,我们扩展了公共 API 以定义数据模型和访问方法,客户端可以使用这些模型和方法访问项目配置数据。

EyeofcloudConfig API

公共配置数据模型(EyeofcloudConfig)在下面定义为静态Eyeofcloud项目数据的结构化格式。

获取云眼配置

EyeofcloudConfig可以通过以下公共API调用从EyeofcloudClient(顶级)访问:

Java

public EyeofcloudConfig getEyeofcloudConfig();

getEyeofcloudConfig 返回一个实例,其中包括EyeofcloudConfig

  • 环境键
  • 开发工具包密钥
  • 数据文件修订号
  • 按其键值映射的所有试验
  • 所有属性
  • 所有受众
  • 所有活动
  • 按其键值映射的灰度标帜
  • 检索项目配置(数据文件)的函数

📘 注意

当 SDK 数据文件更新时(客户端可以添加通知侦听器以获取通知),客户端应调用该方法以获取更新的 EyeofcloudConfig 数据。请参阅以下示例。EYEOFCLOUD_CONFIG_UPDATE

获取数据文件

要确保多个 SDK 实例都从同一配置实例化(例如,在客户端/服务器方案中),可以在实例之间传递配置的 JSON 字符串表示形式(“数据文件”)。若要获取数据文件,请使用对象的方法。有关更多信息,请参阅与多个 SDK 实现共享数据文件EyeofcloudConfig``getDatafile

对象模型

下面显示了 EyeofcloudConfig 的对象模型。

Java - 对象模型

// EyeofcloudConfig is an object describing the current project configuration data public class EyeofcloudConfig { // This experimentsMap is for experiments of legacy projects only. // For flag projects, experiment keys are not guaranteed to be unique // across multiple flags, so this map may not include all experiments // when keys conflict. Map<String, EyeofcloudExperiment> experimentsMap; Map<String, EyeofcloudFeature> featuresMap; List<EyeofcloudAttribute> attributes; List<EyeofcloudEvent> events; List<EyeofcloudAudience> audiences; String revision; String sdkKey; String environmentKey; } // EyeofcloudFeature is an object describing a feature flag public class EyeofcloudFeature { String id; String key; /** * @deprecated use {@link #experimentRules} and {@link #deliveryRules} instead */ @Deprecated Map<String, EyeofcloudExperiment> experimentsMap; Map<String, EyeofcloudVariable> variablesMap; List<EyeofcloudExperiment> experimentRules; List<EyeofcloudExperiment> deliveryRules; } // EyeofcloudExperiment is an object describing an experiment public class EyeofcloudExperiment { String id; String key; String audiences; Map<String, EyeofcloudVariation> variationsMap; } // EyeofcloudVariation is an object describing a variation public class EyeofcloudVariation { String id; String key; Boolean featureEnabled; Map<String, EyeofcloudVariable> variablesMap; } // EyeofcloudVariable is an object describing a Variable public class EyeofcloudVariable { String id; String key; String type; String value; } // EyeofcloudAttribute is an object describing an Attribute public class EyeofcloudAttribute { String id; String key; } // EyeofcloudAudience is an object describing an Audience public class EyeofcloudAudience { String id; String name; String conditions; } // EyeofcloudEvent is an object describing an Event public class EyeofcloudEvent { String id; String key; List<String> experimentIds; }

例子

EyeofcloudConfig可以从EyeofcloudClient(顶级)访问,如下所示:

Java

EyeofcloudConfig config = eyeofcloudClient.getEyeofcloudConfig(); System.out.println("[EyeofcloudConfig] revision = " + config.getRevision()); System.out.println("[EyeofcloudConfig] sdkKey = " + config.getSdkKey()); System.out.println("[EyeofcloudConfig] environmentKey = " + config.getEnvironmentKey()); System.out.println("[EyeofcloudConfig] attributes:"); for (EyeofcloudAttribute attribute: config.getAttributes()) { System.out.println("[EyeofcloudAttribute] -- (id, key) = " + attribute.getId() + ", " + attribute.getKey()); } System.out.println("[EyeofcloudConfig] audiences:"); for (EyeofcloudAudience audience: config.getAudiences()) { System.out.println("[EyeofcloudAudience] -- (id, name, conditions) = " + audience.getId() + ", " + audience.getName() + ", " + audience.getConditions()); } System.out.println("[EyeofcloudConfig] events:"); for (EyeofcloudEvent event: config.getEvents()) { System.out.println("[EyeofcloudEvent] -- (id, key, experimentIds) = " + event.getId() + ", " + event.getKey() + ", " + Arrays.toString(event.getExperimentIds().toArray())); } // all features for (String flagKey: config.getFeaturesMap().keySet()) { EyeofcloudFeature flag = config.getFeaturesMap().get(flagKey); for (EyeofcloudExperiment experiment: flag.getExperimentRules()) { System.out.println("[EyeofcloudExperiment] -- Experiment Rule Key: " + experiment.getKey()); System.out.println("[EyeofcloudExperiment] -- Experiment Audiences: " + experiment.getAudiences()); Map<String, EyeofcloudVariation> variationsMap = experiment.getVariationsMap(); for (String variationKey: variationsMap.keySet()) { EyeofcloudVariation variation = variationsMap.get(variationKey); System.out.println("[EyeofcloudVariation] -- variation = { key: " + variationKey + ", id: " + variation.getId() + ", featureEnabled: " + variation.getFeatureEnabled() + " }"); // use variation data here... Map<String, EyeofcloudVariable> eyeofcloudVariableMap = variation.getVariablesMap(); for (String variableKey: eyeofcloudVariableMap.keySet()) { EyeofcloudVariable variable = eyeofcloudVariableMap.get(variableKey); System.out.println("[EyeofcloudVariable] -- variable = key: " + variableKey + ", value: " + variable.getValue()); // use variable data here... } } } for (EyeofcloudExperiment delivery: flag.getDeliveryRules()) { System.out.println("[EyeofcloudExperiment] -- Delivery Rule Key: " + delivery.getKey()); System.out.println("[EyeofcloudExperiment] -- Delivery Audiences: " + delivery.getAudiences()); } Map<String, EyeofcloudExperiment> experimentsMap = flag.getExperimentsMap(); // feature flag experiments Set<String> experimentKeys = experimentsMap.keySet(); // use experiments and other feature flag data here... } NotificationHandler<UpdateConfigNotification> handler = message -> eyeofcloudClient.getEyeofcloudConfig(); eyeofcloudClient.addUpdateConfigNotificationHandler(handler);

Updated 2 months ago


[

Track Event

](/experimentation/v4.0.0-full-stack/docs/track-event-java)[

EyeofcloudDecision

](/experimentation/v4.0.0-full-stack/docs/eyeofclouddecision-java)

Did this page help you?

Yes

No

创建用户上下文

介绍创建用户上下文方法,该方法为云眼灰度试验中的标帜决策和事件创建用户上下文。

建议修改

此方法的目的是创建用户并设置用户上下文一次,因此不必在每次做出标帜决策或跟踪事件时都指定用户。可以定义多个用户上下文。系统将用户上下文作为运行时对象返回,否则不会持久化。

版本

1.0.0-beta 或更高版本

描述

此调用为标帜决策和事件创建用户上下文。可以在 Eyeofcloud 客户端实例上成功调用此方法,甚至在完全配置实例之前也是如此。

参数

下表列出了必需参数和可选参数:

参数

类型

描述

需要用户 ID

字符串

用户的 ID。

属性
可选

地图

自定义键值字符串对的映射,指定系统用户用于受众群体定位的用户的属性。有关更多详细信息,请参阅以下部分。

受众群体属性

为用户设置自定义受众群体属性,可以使用这些属性来定位受众群体。可以将字符串、数字、布尔值和 nil 作为自定义用户属性值传递。如果要根据他们使用的应用程序变体定位访问群体,还可以传入格式为语义变体的open in new window字符串,然后在 Eyeofcloud 应用中定义受众条件。version

🚧 重要

在访问群体评估期间,如果没有为给定的访问群体条件传递有效的属性值(例如,如果在受众群体条件需要布尔值时传递字符串,或者忘记传递值),则系统会跳过该条件。发生这种情况时,SDK 日志会包含警告。

返回

返回一个 EyeofcloudUserContext 对象。有关详细信息,请参阅云眼用户上下文

Dart

// option 1: create a user, then set attributes var user = await flutterSDK.createUserContext("user123"); var attributes = <String, dynamic>{}; attributes["is_logged_in"] = false; attributes["app_version"] = "1.3.2"; user!.setAttributes(attributes); // option 2: pass attributes when creating the user var attributes = <String, dynamic>{}; attributes["is_logged_in"] = false; attributes["app_version"] = "1.3.2"; var eyeofcloudUserContext = await eyeofcloudClient.createUserContext("user123", attributes);

参见

云眼用户上下文

源文件

包含 Flutter SDK for Android Eyeofcloudopen in new window 和 Swift 实现的语言/平台源文件.java为 EyeofcloudClient.swiftopen in new window

Last update:
Contributors: “zhangweixue”