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

fix: frontend variant weights distribution #4347

Merged
merged 2 commits into from
Jul 26, 2023

Conversation

Tymek
Copy link
Member

@Tymek Tymek commented Jul 26, 2023

About the changes

Unit-tested way of distributing weights between variants.

@sonatype-lift
Copy link

sonatype-lift bot commented Jul 26, 2023

Sonatype Lift is retiring

Sonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console.
We are extremely grateful and thank you for your support over the years.

📖 Read about the impacts and timeline

@vercel
Copy link

vercel bot commented Jul 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 26, 2023 0:57am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Jul 26, 2023 0:57am

({ remainingPercentage, variableVariantCount }, variant) => {
if (variant.weight && variant.weightType === weightTypes.FIX) {
remainingPercentage -= Number(variant.weight);
} else {
}
if (variant.weightType === weightTypes.VARIABLE) {
Copy link
Member Author

@Tymek Tymek Jul 26, 2023

Choose a reason for hiding this comment

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

there is a bugfix here - it was not counting correctly when weight == 0

Copy link
Contributor

Choose a reason for hiding this comment

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

do we need let?

@Tymek Tymek force-pushed the fix/feature-toggle-weight-rebalance branch from 35fb0b7 to b56f9ae Compare July 26, 2023 12:51
String(remainingPercentage / variableVariantCount)
);
const getPercentage = () =>
Math.round(remainingPercentage / variableVariantCount);
Copy link
Member Author

Choose a reason for hiding this comment

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

When variableVariantCount == 1 it will return remainingPercentage, so there is no special case at the end


return variants.map(variant => {
if (variant.weightType !== weightTypes.FIX) {
const percentage = getPercentage(); // round "as we go" - clean best effort approach
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of dividing everything at once, calculate "head" and adjust "tail"

@Tymek Tymek marked this pull request as ready for review July 26, 2023 13:07
({ remainingPercentage, variableVariantCount }, variant) => {
if (variant.weight && variant.weightType === weightTypes.FIX) {
remainingPercentage -= Number(variant.weight);
} else {
}
if (variant.weightType === weightTypes.VARIABLE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need let?

@@ -52,7 +52,7 @@ export interface IFeatureVariant {
name: string;
stickiness: string;
weight: number;
weightType: string;
weightType: 'fix' | 'variable';
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't it gonna break openapi schemas?

Copy link
Member Author

@Tymek Tymek Jul 26, 2023

Choose a reason for hiding this comment

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

That's in frontend, before we started generating it from OpenAPI. Something to clean up and refactor

@Tymek
Copy link
Member Author

Tymek commented Jul 26, 2023

we need let to substract percentages and variants count as we go

@Tymek Tymek merged commit d2a4763 into main Jul 26, 2023
15 checks passed
@Tymek Tymek deleted the fix/feature-toggle-weight-rebalance branch July 26, 2023 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants