Skip to content

support feature variant #13

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

Merged
merged 9 commits into from
Aug 15, 2024
Merged

support feature variant #13

merged 9 commits into from
Aug 15, 2024

Conversation

Eskibear
Copy link
Member

No description provided.

@Eskibear Eskibear marked this pull request as ready for review August 2, 2024 08:03
@zhiyuanliang-ms
Copy link
Contributor

zhiyuanliang-ms commented Aug 5, 2024

.NET FM has TargetingEvaluationOptions which allows user to ignore case while targeting (both targeting filter and varaint allocation). This is missing in JS FM.

Python FM allows to ignore case while using targeting filter. here But it doesn't support it for variant allocation.

@Eskibear
Copy link
Member Author

Eskibear commented Aug 5, 2024

.NET FM has TargetingEvaluationOptions which allows user to ignore case while targeting (both targeting filter and varaint allocation). This is missing in JS FM.

Python FM allows to ignore case while using targeting filter. here But it doesn't support it for variant allocation.

I personally prefer not to support this option ignoreCase now until there's valid customer requests coming for simplicity. We'll see issues if it does block customers from conveniently using it. It's relatively easy to add the support if later we decide to do that, and won't breaking anything.

if (isTargetedUser(context.userId, userAllocation.users)) {
const variant = featureFlag.variants?.find(v => v.name == userAllocation.variant);
if (variant !== undefined) {
return { variant, reason: VariantAssignmentReason.User };
Copy link
Contributor

@zhiyuanliang-ms zhiyuanliang-ms Aug 5, 2024

Choose a reason for hiding this comment

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

Should it be { variant: variant, reason: VariantAssignmentReason.User }?

Copy link
Member Author

Choose a reason for hiding this comment

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

{variant} is short for {variant: variant}. A syntax sugar for simplicity, I can make it clearer if it looks confusing to you now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am ok with it. But personally, I prefer consistency. Is there linting rule for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course there is corresponding linting rule, it's called object-shorthand.
This shorthand syntax makes the code more readable and is widely adopted in ES6 and later versions of JavaScript. See the example of this rule, usually we force to use object shorthand in linting rules instead of forbidding.


export interface IFeatureManager {
/**
* Get the list of feature names.
Copy link
Contributor

Choose a reason for hiding this comment

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

Somewhere you used the third person singular, while in others, you did not.

Copy link
Member Author

Choose a reason for hiding this comment

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

I use Get... instead of `Gets..." here. But for the properties of options, I use "It gets/specifies ..." if starting with an "It".

Those copied from dotnet are using third person singular for verbs I guess. ; ) Yes, they should be updated to be consistent.

// no default specified
variantDef = undefined;
reason = VariantAssignmentReason.DefaultWhenDisabled;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

reason = VariantAssignmentReason.DefaultWhenDisabled; should be put here outside the if-else

Copy link
Member Author

Choose a reason for hiding this comment

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

I decide to keep it in the if-else block together with variantDef assignment for better clarity. ;)

@zhiyuanliang-ms
Copy link
Contributor

@Eskibear Except for the NIT in comments and the logic of variant assignment reason, this PR looks good to me.

@Eskibear Eskibear merged commit d8e7d54 into preview Aug 15, 2024
1 check passed
@Eskibear Eskibear deleted the yanzh/variant branch August 15, 2024 03:03
* @param featureName name of the feature.
* @param context a targeting context object used to evaluate which variant the user will be assigned.
*/
getVariant(featureName: string, context: ITargetingContext): Promise<Variant | undefined>;

Choose a reason for hiding this comment

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

We're actively debating this now- but I think context here should be unknown. https://github.com/microsoft/FeatureManagement-Dotnet/pull/484/files#r1717629098

Copy link
Member Author

Choose a reason for hiding this comment

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

Given the possibility that we calculate audience context id based on any other property rather than userid, I agree that the context is unknown (or to limit it to an object?). A good thing is, here all properties in ITargetingContext are optional, meaning it’s compatible with an arbitrary object type.

import { createHash } from "crypto";

/**
* Determines if the user is part of the audience, based on the user id and the percentage range.

Choose a reason for hiding this comment

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

Suggested change
* Determines if the user is part of the audience, based on the user id and the percentage range.
* Determines if the user is part of the audience, based on the user id and the percentile range.

I think percentile is slightly more explicit here. I'd also use it in the from and to param comments.

Copy link
Member Author

Choose a reason for hiding this comment

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

@zhiyuanliang-ms please help to follow up with the wording in comments, thanks!

Percentile
}

class EvaluationResult {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this also be exported, since developers will need it to send telemetry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants