mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
fix: variant hashing in playground (#5213)
This commit is contained in:
parent
a7f3a89387
commit
b54d481fc8
@ -1,6 +1,6 @@
|
||||
import { Strategy } from './strategy';
|
||||
import { Context } from '../context';
|
||||
import normalizedValue from './util';
|
||||
import { normalizedStrategyValue } from './util';
|
||||
import { resolveContextValue } from '../helpers';
|
||||
|
||||
const STICKINESS = {
|
||||
@ -54,7 +54,7 @@ export default class FlexibleRolloutStrategy extends Strategy {
|
||||
if (!stickinessId) {
|
||||
return false;
|
||||
}
|
||||
const normalizedUserId = normalizedValue(stickinessId, groupId);
|
||||
const normalizedUserId = normalizedStrategyValue(stickinessId, groupId);
|
||||
return percentage > 0 && normalizedUserId <= percentage;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Strategy } from './strategy';
|
||||
import normalizedValue from './util';
|
||||
import { normalizedStrategyValue } from './util';
|
||||
import { Context } from '../context';
|
||||
|
||||
export default class GradualRolloutSessionIdStrategy extends Strategy {
|
||||
@ -19,7 +19,7 @@ export default class GradualRolloutSessionIdStrategy extends Strategy {
|
||||
const percentage = Number(parameters.percentage);
|
||||
const groupId = parameters.groupId || '';
|
||||
|
||||
const normalizedId = normalizedValue(sessionId, groupId);
|
||||
const normalizedId = normalizedStrategyValue(sessionId, groupId);
|
||||
|
||||
return percentage > 0 && normalizedId <= percentage;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Strategy } from './strategy';
|
||||
import { Context } from '../context';
|
||||
import normalizedValue from './util';
|
||||
import { normalizedStrategyValue } from './util';
|
||||
|
||||
export default class GradualRolloutUserIdStrategy extends Strategy {
|
||||
constructor() {
|
||||
@ -19,7 +19,7 @@ export default class GradualRolloutUserIdStrategy extends Strategy {
|
||||
const percentage = Number(parameters.percentage);
|
||||
const groupId = parameters.groupId || '';
|
||||
|
||||
const normalizedUserId = normalizedValue(userId, groupId);
|
||||
const normalizedUserId = normalizedStrategyValue(userId, groupId);
|
||||
|
||||
return percentage > 0 && normalizedUserId <= percentage;
|
||||
}
|
||||
|
@ -1,9 +1,27 @@
|
||||
import * as murmurHash3 from 'murmurhash3js';
|
||||
|
||||
export default function normalizedValue(
|
||||
function normalizedValue(
|
||||
id: string,
|
||||
groupId: string,
|
||||
normalizer = 100,
|
||||
normalizer: number,
|
||||
seed = 0,
|
||||
): number {
|
||||
return (murmurHash3.x86.hash32(`${groupId}:${id}`) % normalizer) + 1;
|
||||
const hash = murmurHash3.x86.hash32(`${groupId}:${id}`, seed);
|
||||
return (hash % normalizer) + 1;
|
||||
}
|
||||
|
||||
const STRATEGY_SEED = 0;
|
||||
|
||||
export function normalizedStrategyValue(id: string, groupId: string): number {
|
||||
return normalizedValue(id, groupId, 100, STRATEGY_SEED);
|
||||
}
|
||||
|
||||
const VARIANT_SEED = 86028157;
|
||||
|
||||
export function normalizedVariantValue(
|
||||
id: string,
|
||||
groupId: string,
|
||||
normalizer: number,
|
||||
): number {
|
||||
return normalizedValue(id, groupId, normalizer, VARIANT_SEED);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Context } from './context';
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import { FeatureInterface } from './feature';
|
||||
import normalizedValue from './strategy/util';
|
||||
import { normalizedVariantValue } from './strategy/util';
|
||||
import { resolveContextValue } from './helpers';
|
||||
|
||||
interface Override {
|
||||
@ -91,7 +91,7 @@ export function selectVariantDefinition(
|
||||
|
||||
const { stickiness } = variants[0];
|
||||
|
||||
const target = normalizedValue(
|
||||
const target = normalizedVariantValue(
|
||||
getSeed(context, stickiness),
|
||||
featureName,
|
||||
totalWeight,
|
||||
|
Loading…
Reference in New Issue
Block a user