-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
.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. |
src/featureManager.ts
Outdated
if (isTargetedUser(context.userId, userAllocation.users)) { | ||
const variant = featureFlag.variants?.find(v => v.name == userAllocation.variant); | ||
if (variant !== undefined) { | ||
return { variant, reason: VariantAssignmentReason.User }; |
There was a problem hiding this comment.
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 }?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. ;)
@Eskibear Except for the NIT in comments and the logic of variant assignment reason, this PR looks good to me. |
* @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>; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
No description provided.