Reputation: 372
I started using Azure App Configuration service and Feature Flags functionality in my project. I followed this documentation and was able to create a Spring boot project. I also created a FeatureFlagService class and autowired the FeatureManager class in it as shown below :
@Service
public class FeatureFlagService {
private FeatureManager featureManager;
public FeatureFlagService(FeatureManager featureManager) {
this.featureManager = featureManager;
}
public boolean isFeatureEnabled() {
return featureManager.isEnabledAsync("scopeid/MyFeature").block();
}
}
With this I get the value of the feature flag 'MyFeature' but with no label. I have the same feature defined with different labels in Azure App Configuration as shown below.
I need to fetch the feature flag with specific label. How can I achieve it at runtime? I don't see a way to do it using the FeatureManager class.
Upvotes: 0
Views: 1436
Reputation: 11
I got FeatureManager
to pull in non-blank labels with the following configuration path:
spring.cloud.azure.appconfiguration.stores[0].feature-flags.selects[0].label-filter
The key is that the other answer was missing the selects
piece.
Here it is in yaml form:
spring:
cloud:
azure:
appconfiguration:
enabled: true
stores[0]:
connection-string: ${APP_CONFIGURATION_CONNECTION_STRING}
feature-flags:
enabled: true
selects[0]:
# this pulls in flags with "local" label and no label (trailing comma)
label-filter: local,
# you can put key-filter here, too
Relevant source code:
Artifact:
artifactId=spring-cloud-azure-appconfiguration-config
groupId=com.azure.spring
version=5.8.0
If you notice in the code, you can also use active Spring profiles for filtering the Azure feature flags by label.
You may want to to wire in a AppConfigurationRefresh
bean to refresh feature flag values on demand. I think the refresh default is 5 minutes. You can setup a Spring scheduled task to invoke it more frequently. Or if you can find a way to override the default, feel free to share it here.
Upvotes: 1
Reputation: 493
They only way to load from a label is by using spring.cloud.azure.appconfiguration.stores[0].feature-flags.label-filter
, the Feature Management Library itself has no concept of a label.
Upvotes: 0