Skip to content

Commit b3b6b07

Browse files
update
1 parent 197f4b8 commit b3b6b07

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AzureAppConfigurationImpl.ts

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,10 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
567567

568568
if (featureFlag[TELEMETRY_KEY_NAME] && featureFlag[TELEMETRY_KEY_NAME][ENABLED_KEY_NAME] === true) {
569569
const metadata = featureFlag[TELEMETRY_KEY_NAME][METADATA_KEY_NAME];
570-
const allocationId = await this.#generateAllocationId(featureFlag);
570+
let allocationId = "";
571+
if (featureFlag[ALLOCATION_KEY_NAME] !== undefined) {
572+
allocationId = await this.#generateAllocationId(featureFlag);
573+
}
571574
featureFlag[TELEMETRY_KEY_NAME][METADATA_KEY_NAME] = {
572575
[ETAG_KEY_NAME]: setting.etag,
573576
[FEATURE_FLAG_ID_KEY_NAME]: await this.#calculateFeatureFlagId(setting),
@@ -642,51 +645,50 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
642645
let rawAllocationId = "";
643646
// Only default variant when enabled and variants allocated by percentile involve in the experimentation
644647
// The allocation id is genearted from default variant when enabled and percentile allocation
645-
const variantsForExperiementation: string[] = [];
648+
const variantsForExperimentation: string[] = [];
646649

647-
if (featureFlag[ALLOCATION_KEY_NAME]) {
648-
rawAllocationId += `seed=${featureFlag[ALLOCATION_KEY_NAME][SEED_KEY_NAME] ?? ""}\ndefault_when_enabled=`;
650+
rawAllocationId += `seed=${featureFlag[ALLOCATION_KEY_NAME][SEED_KEY_NAME] ?? ""}\ndefault_when_enabled=`;
649651

650-
if (featureFlag[ALLOCATION_KEY_NAME][DEFAULT_WHEN_ENABLED_KEY_NAME]) {
651-
variantsForExperiementation.push(featureFlag[ALLOCATION_KEY_NAME][DEFAULT_WHEN_ENABLED_KEY_NAME]);
652-
rawAllocationId += `${featureFlag[ALLOCATION_KEY_NAME][DEFAULT_WHEN_ENABLED_KEY_NAME]}`;
653-
}
652+
if (featureFlag[ALLOCATION_KEY_NAME][DEFAULT_WHEN_ENABLED_KEY_NAME]) {
653+
variantsForExperimentation.push(featureFlag[ALLOCATION_KEY_NAME][DEFAULT_WHEN_ENABLED_KEY_NAME]);
654+
rawAllocationId += `${featureFlag[ALLOCATION_KEY_NAME][DEFAULT_WHEN_ENABLED_KEY_NAME]}`;
655+
}
654656

655-
rawAllocationId += "\npercentiles=";
656-
657-
const percentileList = featureFlag[ALLOCATION_KEY_NAME][PERCENTILE_KEY_NAME];
658-
if (percentileList) {
659-
const sortedPercentileList = percentileList
660-
.filter(p =>
661-
(p[FROM_KEY_NAME] !== undefined) &&
662-
(p[TO_KEY_NAME] !== undefined) &&
663-
(p[VARIANT_KEY_NAME] !== undefined) &&
664-
(p[FROM_KEY_NAME] !== p[TO_KEY_NAME]))
665-
.sort((a, b) => a[FROM_KEY_NAME] - b[FROM_KEY_NAME]);
666-
667-
const percentileAllocation: string[] = [];
668-
for (const percentile of sortedPercentileList) {
669-
variantsForExperiementation.push(percentile[VARIANT_KEY_NAME]);
670-
percentileAllocation.push(`${percentile[FROM_KEY_NAME]},${base64Helper(percentile[VARIANT_KEY_NAME])},${percentile[TO_KEY_NAME]}`);
671-
}
672-
rawAllocationId += percentileAllocation.join(";");
657+
rawAllocationId += "\npercentiles=";
658+
659+
const percentileList = featureFlag[ALLOCATION_KEY_NAME][PERCENTILE_KEY_NAME];
660+
if (percentileList) {
661+
const sortedPercentileList = percentileList
662+
.filter(p =>
663+
(p[FROM_KEY_NAME] !== undefined) &&
664+
(p[TO_KEY_NAME] !== undefined) &&
665+
(p[VARIANT_KEY_NAME] !== undefined) &&
666+
(p[FROM_KEY_NAME] !== p[TO_KEY_NAME]))
667+
.sort((a, b) => a[FROM_KEY_NAME] - b[FROM_KEY_NAME]);
668+
669+
const percentileAllocation: string[] = [];
670+
for (const percentile of sortedPercentileList) {
671+
variantsForExperimentation.push(percentile[VARIANT_KEY_NAME]);
672+
percentileAllocation.push(`${percentile[FROM_KEY_NAME]},${base64Helper(percentile[VARIANT_KEY_NAME])},${percentile[TO_KEY_NAME]}`);
673673
}
674+
rawAllocationId += percentileAllocation.join(";");
674675
}
676+
675677

676-
if (featureFlag[ALLOCATION_KEY_NAME] === undefined || (variantsForExperiementation.length === 0 && featureFlag[ALLOCATION_KEY_NAME][SEED_KEY_NAME] === undefined)) {
678+
if (variantsForExperimentation.length === 0 && featureFlag[ALLOCATION_KEY_NAME][SEED_KEY_NAME] === undefined) {
677679
// All fields required for generating allocation id are missing, short-circuit and return empty string
678680
return "";
679681
}
680682

681683
rawAllocationId += "\nvariants=";
682684

683-
if (variantsForExperiementation.length !== 0) {
685+
if (variantsForExperimentation.length !== 0) {
684686
const variantsList = featureFlag[VARIANTS_KEY_NAME];
685687
if (variantsList) {
686688
const sortedVariantsList = variantsList
687689
.filter(v =>
688690
(v[NAME_KEY_NAME] !== undefined) &&
689-
variantsForExperiementation.includes(v[NAME_KEY_NAME]))
691+
variantsForExperimentation.includes(v[NAME_KEY_NAME]))
690692
.sort((a, b) => (a.name > b.name ? 1 : -1));
691693

692694
const variantConfiguration: string[] = [];

0 commit comments

Comments
 (0)