Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature context and Async Filters #43435

Open
wants to merge 1 commit into
base: SpringCloudAzure6.0-Preview
Choose a base branch
from

Conversation

mrm9084
Copy link
Member

@mrm9084 mrm9084 commented Dec 16, 2024

Description

Adds Async filters and Feature Context.

Trying to minimize the change in here #42853

@mrm9084 mrm9084 requested a review from Copilot December 16, 2024 23:43
@github-actions github-actions bot added the azure-spring All azure-spring related issues label Dec 16, 2024
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 5 out of 10 changed files in this pull request and generated 1 comment.

Files not reviewed (5)
  • sdk/spring/spring-cloud-azure-feature-management/src/test/java/com/azure/spring/cloud/feature/management/filters/TargetingFilterTest.java: Evaluated as low risk
  • sdk/spring/spring-cloud-azure-feature-management/src/test/java/com/azure/spring/cloud/feature/management/FeatureManagerTest.java: Evaluated as low risk
  • sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/implementation/FeatureManagementConstants.java: Evaluated as low risk
  • sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/FeatureManager.java: Evaluated as low risk
  • sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/implementation/FeatureFilterUtils.java: Evaluated as low risk

}

/**
* Checks to see if the feature is enabled. If enabled it check each filter, once a single filter returns true it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Checks to see if the feature is enabled. If enabled it check each filter, once a single filter returns true it
* Checks to see if the feature is enabled. If enabled it checks each filter, once a single filter returns true it

Same comment on multiple functions

@@ -59,7 +67,7 @@ public class FeatureManager {
* @throws FilterNotFoundException file not found
*/
public Mono<Boolean> isEnabledAsync(String feature) {
return Mono.just(checkFeature(feature));
return checkFeature(feature, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do async methods throw the FilterNotFoundException?

* @throws FilterNotFoundException file not found
*/
public Boolean isEnabled(String feature, Object featureContext) throws FilterNotFoundException {
return checkFeature(feature, featureContext).block(Duration.ofSeconds(100));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want context for why we chose 100. Could you maybe pull this out into a constant and name it AzureSDKDefaultBlockDuration or something like that

ReflectionUtils.rethrowRuntimeException(new FilterNotFoundException(message, e, filter));
private Mono<Boolean> checkFeatureFilters(Feature featureFlag, Object featureContext) {
Conditions conditions = featureFlag.getConditions();
List<FeatureFilterEvaluationContext> featureFilters = conditions.getClientFilters();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null check on conditions

String filterName = featureFilter.getName();

try {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


/**
* A Filter for Feature Management that is attached to Features. The filter needs to have @Component set to be found by
* feature management.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably call out that these filters have context

contextAccessor.configureTargetingContext(targetingContext);
if (contextualAccessor != null && (appContext != null || contextAccessor == null)) {
// Use this if, there is an appContext + the contextualAccessor, or there is no contextAccessor.
contextualAccessor.configureTargetingContext(targetingContext, appContext);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced the contextualAccessor is providing value here. Couldn't this just be
targetingContext = appContext (with a type check)

It's unclear to me why we want a ContextualTargetingContextAccessor at all. I think it could be removed if we make the above change.

private boolean targetUser(String userId, List<String> users) {
return userId != null && users != null && users.stream().anyMatch(user -> equals(userId, user));
private boolean targetUser(String userId, Collection<String> collection) {
return userId != null && collection != null && collection.stream().anyMatch(user -> equals(userId, user));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the variable name still be users

/**
* Looks at the given key in the parameters and coverts it to a list if it is currently a map.
*
* @param parameters map of generic objects
* @param key key of object int the parameters map
*/
@SuppressWarnings("unchecked")
public static void updateValueFromMapToList(Map<String, Object> parameters, String key) {
public static void updateValueFromMapToList(Map<String, Object> parameters, String key, boolean fixNull) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the fixNull here- as you only ever call it with true as far as I can tell. Could be removed from the if below as well. Also means we remove the overload method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
azure-spring All azure-spring related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants