Skip to content

Commit 8ed48b5

Browse files
merge preview
2 parents ea7709e + 71aebab commit 8ed48b5

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

src/AzureAppConfigurationImpl.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,19 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
9393
/**
9494
* Selectors of key-values obtained from @see AzureAppConfigurationOptions.selectors
9595
*/
96+
<<<<<<< HEAD
9697
#kvSelectorCollection: SettingSelectorCollection = { selectors: [] };
9798
/**
9899
* Selectors of feature flags obtained from @see AzureAppConfigurationOptions.featureFlagOptions.selectors
99100
*/
100101
#ffSelectorCollection: SettingSelectorCollection = { selectors: [] };
102+
=======
103+
#kvSelectors: PagedSettingSelector[] = [];
104+
/**
105+
* Selectors of feature flags obtained from @see AzureAppConfigurationOptions.featureFlagOptions.selectors
106+
*/
107+
#ffSelectors: PagedSettingSelector[] = [];
108+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
101109

102110
// Load balancing
103111
#lastSuccessfulEndpoint: string = "";
@@ -124,6 +132,9 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
124132
this.#sortedTrimKeyPrefixes = [...options.trimKeyPrefixes].sort((a, b) => b.localeCompare(a));
125133
}
126134

135+
// if no selector is specified, always load key values using the default selector: key="*" and label="\0"
136+
this.#kvSelectors = getValidKeyValueSelectors(options?.selectors);
137+
127138
if (options?.refreshOptions?.enabled) {
128139
const { refreshIntervalInMs, watchedSettings } = options.refreshOptions;
129140
if (watchedSettings === undefined || watchedSettings.length === 0) {
@@ -156,8 +167,13 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
156167

157168
// feature flag options
158169
if (options?.featureFlagOptions?.enabled) {
170+
<<<<<<< HEAD
159171
// validate feature flag selectors
160172
this.#ffSelectorCollection.selectors = getValidFeatureFlagSelectors(options.featureFlagOptions.selectors);
173+
=======
174+
// validate feature flag selectors, only load feature flags when enabled
175+
this.#ffSelectors = getValidFeatureFlagSelectors(options.featureFlagOptions.selectors);
176+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
161177

162178
if (options.featureFlagOptions.refresh?.enabled) {
163179
const { refreshIntervalInMs } = options.featureFlagOptions.refresh;
@@ -197,7 +213,10 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
197213
initialLoadCompleted: this.#isInitialLoadCompleted,
198214
replicaCount: this.#clientManager.getReplicaCount(),
199215
isFailoverRequest: this.#isFailoverRequest,
216+
<<<<<<< HEAD
200217
isCdnUsed: this.#isCdnUsed,
218+
=======
219+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
201220
featureFlagTracing: this.#featureFlagTracing
202221
};
203222
}
@@ -395,6 +414,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
395414
* If false, loads key-value using the key-value selectors. Defaults to false.
396415
*/
397416
async #loadConfigurationSettings(loadFeatureFlag: boolean = false): Promise<ConfigurationSetting[]> {
417+
<<<<<<< HEAD
398418
const selectorCollection = loadFeatureFlag ? this.#ffSelectorCollection : this.#kvSelectorCollection;
399419
const funcToExecute = async (client) => {
400420
const loadedSettings: ConfigurationSetting[] = [];
@@ -417,20 +437,41 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
417437
};
418438
}
419439

440+
=======
441+
const selectors = loadFeatureFlag ? this.#ffSelectors : this.#kvSelectors;
442+
const funcToExecute = async (client) => {
443+
const loadedSettings: ConfigurationSetting[] = [];
444+
// deep copy selectors to avoid modification if current client fails
445+
const selectorsToUpdate = JSON.parse(
446+
JSON.stringify(selectors)
447+
);
448+
449+
for (const selector of selectorsToUpdate) {
450+
const listOptions: ListConfigurationSettingsOptions = {
451+
keyFilter: selector.keyFilter,
452+
labelFilter: selector.labelFilter
453+
};
454+
455+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
420456
const pageEtags: string[] = [];
421457
const pageIterator = listConfigurationSettingsWithTrace(
422458
this.#requestTraceOptions,
423459
client,
424460
listOptions
425461
).byPage();
426462
for await (const page of pageIterator) {
463+
<<<<<<< HEAD
427464
pageEtags.push(page.etag ?? ""); // pageEtags is string[]
465+
=======
466+
pageEtags.push(page.etag ?? "");
467+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
428468
for (const setting of page.items) {
429469
if (loadFeatureFlag === isFeatureFlag(setting)) {
430470
loadedSettings.push(setting);
431471
}
432472
}
433473
}
474+
<<<<<<< HEAD
434475

435476
if (pageEtags.length === 0) {
436477
console.warn(`No page is found in the response of listing key-value selector: key=${selector.keyFilter} and label=${selector.labelFilter}.`);
@@ -439,6 +480,16 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
439480
}
440481

441482
selectorCollection.selectors = selectorsToUpdate;
483+
=======
484+
selector.pageEtags = pageEtags;
485+
}
486+
487+
if (loadFeatureFlag) {
488+
this.#ffSelectors = selectorsToUpdate;
489+
} else {
490+
this.#kvSelectors = selectorsToUpdate;
491+
}
492+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
442493
return loadedSettings;
443494
};
444495

@@ -476,13 +527,24 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
476527
if (matchedSetting) {
477528
sentinel.etag = matchedSetting.etag;
478529
} else {
530+
<<<<<<< HEAD
479531
// Send a request to retrieve watched key-value since it may be either not loaded or loaded with a different selector
480532
// If cdn is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
481533
const getOptions = this.#isCdnUsed ?
482534
{ requestOptions: { customHeaders: { [ETAG_LOOKUP_HEADER]: this.#kvSelectorCollection.etagToBreakCdnCache ?? "" } } } :
483535
{};
484536
const response = await this.#getConfigurationSetting(sentinel, {...getOptions, onlyIfChanged: false}); // always send non-conditional request
485537
sentinel.etag = response?.etag;
538+
=======
539+
// Send a request to retrieve key-value since it may be either not loaded or loaded with a different label or different casing
540+
const { key, label } = sentinel;
541+
const response = await this.#getConfigurationSetting({ key, label });
542+
if (response) {
543+
sentinel.etag = response.etag;
544+
} else {
545+
sentinel.etag = undefined;
546+
}
547+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
486548
}
487549
}
488550
}
@@ -527,6 +589,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
527589
// try refresh if any of watched settings is changed.
528590
let needRefresh = false;
529591
if (this.#watchAll) {
592+
<<<<<<< HEAD
530593
needRefresh = await this.#checkConfigurationSettingsChange(this.#kvSelectorCollection);
531594
}
532595
for (const sentinel of this.#sentinels.values()) {
@@ -541,6 +604,19 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
541604
) {
542605
sentinel.etag = response?.etag;// update etag of the sentinel
543606
this.#kvSelectorCollection.etagToBreakCdnCache = sentinel.etag;
607+
=======
608+
needRefresh = await this.#checkConfigurationSettingsChange(this.#kvSelectors);
609+
}
610+
for (const sentinel of this.#sentinels.values()) {
611+
const response = await this.#getConfigurationSetting(sentinel, {
612+
onlyIfChanged: true
613+
});
614+
615+
if (response?.statusCode === 200 // created or changed
616+
|| (response === undefined && sentinel.etag !== undefined) // deleted
617+
) {
618+
sentinel.etag = response?.etag;// update etag of the sentinel
619+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
544620
needRefresh = true;
545621
break;
546622
}
@@ -564,7 +640,11 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
564640
return Promise.resolve(false);
565641
}
566642

643+
<<<<<<< HEAD
567644
const needRefresh = await this.#checkConfigurationSettingsChange(this.#ffSelectorCollection);
645+
=======
646+
const needRefresh = await this.#checkConfigurationSettingsChange(this.#ffSelectors);
647+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
568648
if (needRefresh) {
569649
await this.#loadFeatureFlags();
570650
}
@@ -575,6 +655,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
575655

576656
/**
577657
* Checks whether the key-value collection has changed.
658+
<<<<<<< HEAD
578659
* @param selectorCollection - The @see SettingSelectorCollection of the kev-value collection.
579660
* @returns true if key-value collection has changed, false otherwise.
580661
*/
@@ -596,12 +677,27 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
596677
listOptions = { ...listOptions, pageEtags: selector.pageEtags };
597678
}
598679

680+
=======
681+
* @param selectors - The @see PagedSettingSelector of the kev-value collection.
682+
* @returns true if key-value collection has changed, false otherwise.
683+
*/
684+
async #checkConfigurationSettingsChange(selectors: PagedSettingSelector[]): Promise<boolean> {
685+
const funcToExecute = async (client) => {
686+
for (const selector of selectors) {
687+
const listOptions: ListConfigurationSettingsOptions = {
688+
keyFilter: selector.keyFilter,
689+
labelFilter: selector.labelFilter,
690+
pageEtags: selector.pageEtags
691+
};
692+
693+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
599694
const pageIterator = listConfigurationSettingsWithTrace(
600695
this.#requestTraceOptions,
601696
client,
602697
listOptions
603698
).byPage();
604699

700+
<<<<<<< HEAD
605701
if (selector.pageEtags === undefined || selector.pageEtags.length === 0) {
606702
selectorCollection.etagToBreakCdnCache = undefined;
607703
return true; // no etag is retrieved from previous request, always refresh
@@ -623,6 +719,12 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
623719
selectorCollection.etagToBreakCdnCache = selector.pageEtags[i];
624720
}
625721
return true;
722+
=======
723+
for await (const page of pageIterator) {
724+
if (page._response.status === 200) { // created or changed
725+
return true;
726+
}
727+
>>>>>>> 71aebabca61a3e3fa5df2b7112b1236768932408
626728
}
627729
}
628730
return false;

0 commit comments

Comments
 (0)