Feature Flag Determination
Feature flags are only available for SDK version 2.0.0 or higher.
When using feature flags, please apply SDK version 2.0.0 or higher when adding dependencies.
A feature flag has an on and off state. You will set different features according to each state.
Once a feature flag is applied, a specific user from your traffic should be able to either receive an off or on status. This on/off status determination can be done through the Hackle SDK.
isFeatureOn
You can pass a feature key to the isFeatureOn()
method to receive status results for the user. After receiving the status, we can then implement the logic according to each status.
In the example code below, we are passing feature key 42, and the user identifier of the user who will receive the status is "ae03e1adf" .
// Determines the status of the feature flag to assign the user in a feature flag with a feature key of 42.
// For undetermined cases, users are assigned to false (off status).
boolean featureOn = hackleClient.isFeatureOn(42, "ae03e1adf");
if (featureOn) {
// Logic for on status
} else {
// Logic for off status
}
// Determines the status of the feature flag to assign the user in a feature flag with a feature key of 42.
// For undetermined cases, users are assigned to false (off status).
val featureOn = hackleClient.isFeatureOn(42, "ae03e1adf")
if (featureOn) {
// Logic for on status
} else {
// Logic for off status
}
featureFlagDetail
The featureFlagDetail()
method works the same as the isFeatureOn()
method and additionally provides a reason for determining the status of a particular user. This can be useful when you want to check whether the manual allocation is working well or when you think that the traffic allocation you have set is not being reflected in your results.
You must pass a feature key as a parameter. For the example code below, we are passing feature key 42.
FeatureFlagDecision decision = hackleClient.featureFlagDetail(42, "ae03e1adf");
// Feature flag on/off results
boolean featureOn = decision.isOn();
// Reason for status determination
DecisionReason reason = decision.getReason();
val decision = hackleClient.featureFlagDetail(42, "ae03e1adf")
// Feature flag on/off results
val featureOn = decision.isOn()
// Reason for status determination
val reason = decision.getReason()
The reason for the status determination will be in the form of SDK_NOT_READY
. Please refer to the table below for the full list of all the different types of reasons.
Reason | Description | Feature Status |
---|---|---|
SDK_NOT_READY | The SDK is not ready to use. (e.g. Initialization with the wrong SDK key) | Default status(off) |
FEATURE_FLAG_NOT_FOUND | No feature flags were found for the feature key you passed. The feature key may be incorrect or the corresponding feature flag may be in an archived state. | Default status(off) |
OVERRIDDEN | The user has been determined to have a specific feature flag status by manual assignment. | Manual assignment |
TRAFFIC_ALLOCATED | User status has been determined. | Status determined |
EXCEPTION | An unknown error has occurred. | Default status(off) |
Deduplication of exposure event
If you use Backend-side SDK, Any successive Exposure events within one minute for same Feature Flag from single user will be counted as one.
Feature Flag Parameter
getString
- Returns the parameter value set to STRING, JSON type.
- Returns the default value or the value set in the rule based on the status determination.
FeatureFlagDecision decision = hackleClient.featureFlagDetail(42, “ae03e1adf”);
ParameterConfig config = decision.getConfig();
String strValue = decision.getString(“parameter_key_string_type”, “defaultValue”);
String strValueInConfig = config.getString(“parameter_key_string_type”, “defaultValue”);
String jsonValue = decision.getString(“parameter_key_json_type”, “defaultValue”);
String jsonValueInConfig = config.getString(“parameter_key_json_type”, “defaultValue”);
val decision: FeatureFlagDecision = hackleClient.featureFlagDetail(42, “ae03e1adf”)
val config: ParameterConfig = decision.config
val strValue: String = decision.getString(“parameter_key_string_type”, “defaultValue”)
val strValueInConfig: String = config.getString(“parameter_key_string_type”, “defaultValue”)
val jsonValue: String = decision.getString(“parameter_key_json_type”, “defaultValue”)
val jsonValueInConfig: String = config.getString(“parameter_key_json_type”, “defaultValue”)
getInt
- Returns the parameter value set to Number type as Int type.
- Returns the default value or the value set in the rule based on the status determination.
FeatureFlagDecision decision = hackleClient.featureFlagDetail(42, “ae03e1adf”);
ParameterConfig config = decision.getConfig();
int intValue = decision.getInt(“parameter_key_number_type”, 0);
int intValueInConfig = config.getInt(“parameter_key_number_type”, 0);
val decision: FeatureFlagDecision = hackleClient.featureFlagDetail(42, “ae03e1adf”)
val config: ParameterConfig = decision.config
val intValue: Int = decision.getInt(“parameter_key_number_type”, 0)
val intValueInConfig: Int = config.getInt(“parameter_key_number_type”, 0)
getDouble
- Returns the parameter value set to Number type as Double type.
- Returns the default value or the value set in the rule based on the status determination.
FeatureFlagDecision decision = hackleClient.featureFlagDetail(42, “ae03e1adf”);
ParameterConfig config = decision.getConfig();
double doubleValue = decision.getDouble(“parameter_key_number_type”, 0.0);
double doubleValueInConfig = config.getDouble(“parameter_key_number_type”, 0.0);
val decision: FeatureFlagDecision = hackleClient.featureFlagDetail(42, “ae03e1adf”)
val config: ParameterConfig = decision.config
val doubleValue: Double = decision.getDouble(“parameter_key_number_type”, 0.0)
val doubleValueInConfig: Double = config.getDouble(“parameter_key_number_type”, 0.0)
getLong
- Returns the parameter value set to Number type as Long type.
- Returns the default value or the value set in the rule based on the status determination.
FeatureFlagDecision decision = hackleClient.featureFlagDetail(42, “ae03e1adf”);
ParameterConfig config = decision.getConfig();
long longValue = decision.getLong(“parameter_key_number_type”, 0L);
long longValueInConfig = config.getLong(“parameter_key_number_type”, 0L);
val decision: FeatureFlagDecision = hackleClient.featureFlagDetail(42, “ae03e1adf”)
val config: ParameterConfig = decision.config
val longValue: Long = decision.getLong(“parameter_key_number_type”, 0L)
val longValueInConfig: Long = config.getLong(“parameter_key_number_type”, 0L)
getBoolean
- Returns the parameter value set to Boolean type.
- Returns the default value or the value set in the rule based on the status determination.
FeatureFlagDecision decision = hackleClient.featureFlagDetail(42, “ae03e1adf”);
ParameterConfig config = decision.getConfig();
boolean booleanValue = decision.getBoolean(“parameter_key_boolean_type”, false);
boolean booleanValueInConfig = config.getBoolean(“parameter_key_boolean_type”, false);
val decision: FeatureFlagDecision = hackleClient.featureFlagDetail(42, “ae03e1adf”)
val config: ParameterConfig = decision.config
val booleanValue: Boolean = decision.getBoolean(“parameter_key_boolean_type”, false)
val booleanValueInConfig: Boolean = config.getBoolean(“parameter_key_boolean_type”, false)
Updated over 1 year ago