Skip to content

Commit

Permalink
[Main][Task]27742145: Change nonOverrideCfgs to be added only during …
Browse files Browse the repository at this point in the history
…initialization (#2332)

* cfg sync override

* update
  • Loading branch information
Karlie-777 committed Apr 19, 2024
1 parent 9375ed3 commit 7bcd35c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion extensions/applicationinsights-cfgsync-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Refer to [our GitHub page](https://github.com/microsoft/ApplicationInsights-JS)
| onCfgChangeReceive | function<br>[Optional] | null | Overrides callback function to handle event details when changes are received via event listener. |
| overrideSyncFn | function<br>[Optional] | null | Overrides sync() function to broadcast changes. |
| overrideFetchFn | function<br>[Optional] | null | Overrides fetch function to get config from cfgUrl when cfgUrl is defined. |
| nonOverrideConfigs | NonOverrideCfg<br>[Optional] | {instrumentationKey: true, connectionString: true, endpointUrl: true } | When current instance is set with syncMode: `Receive`, config fields under nonOverrideConfigs will NOT be changed by any confif details sent out from other instances. |
| nonOverrideConfigs | NonOverrideCfg<br>[Optional] | {instrumentationKey: true, connectionString: true, endpointUrl: true } | When current instance is set with syncMode: `Receive`, config fields under nonOverrideConfigs will NOT be changed by any confif details sent out from other instances. NOTE: this config will be ONLY applied during initialization, so it won't be changed dynamically. |
| scheduleFetchTimeout | number<br>[Optional] | 30 mins | Identifies the time interval (in milliseconds) for fetching config details from cfgUrl when cfgUrl is defined. If set to 0, the fetch operation will only be called once during initialization. |


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ export class CfgSyncPluginTests extends AITestClass {
this.core.config.extensionConfig[this.identifier].syncMode = ICfgSyncMode.Receive;
this.core.config.extensionConfig[this.identifier].receiveChanges = true;
this.core.config.extensionConfig[this.identifier].blkCdnCfg = true;
this.core.config.extensionConfig[this.identifier].nonOverrideConfigs = {};

this.clock.tick(1);
targets = this.mainInst["_getDbgPlgTargets"]();
Assert.equal(targets[0], true, "auto sync should not be changed to false dynamically");
Assert.equal(targets[1], false, "receive changes should not be changed dynamically");
Assert.equal(targets[3], true, "blkCdnCfg changes should be changed dynamically");
Assert.deepEqual(targets[4], defaultNonOverrideCfg, "nonOverrideCfg changes should not be changed dynamically");
Assert.equal(patchEvnSpy.callCount, 3, "event dispatch should be called again");
curMainCfg = this.mainInst.getCfg();
Assert.deepEqual(curMainCfg, this.core.config, "main config should be set test2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class CfgSyncPlugin extends BaseTelemetryPlugin implements ICfgSyncPlugin
};

_self["_getDbgPlgTargets"] = () => {
return [_broadcastChanges, _receiveChanges, _evtName, _blkCdnCfg];
return [_broadcastChanges, _receiveChanges, _evtName, _blkCdnCfg, _nonOverrideConfigs];
};

function _initDefaults() {
Expand Down Expand Up @@ -179,7 +179,8 @@ export class CfgSyncPlugin extends BaseTelemetryPlugin implements ICfgSyncPlugin
_overrideSyncFn = _extensionConfig.overrideSyncFn;
_overrideFetchFn = _extensionConfig.overrideFetchFn;
_onCfgChangeReceive = _extensionConfig.onCfgChangeReceive;
_nonOverrideConfigs = _extensionConfig.nonOverrideConfigs;
_nonOverrideConfigs = _extensionConfig.nonOverrideConfigs; // override values should not be changed

_fetchTimeout = _extensionConfig.scheduleFetchTimeout;
_fetchFn = _getFetchFnInterface();
_retryCnt = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export interface ICfgSyncConfig {
*/
overrideFetchFn?: SendGetFunction;
/**
* When current instance is set with syncMode: `Receive`, config fields under nonOverrideConfigs will NOT be changed by any confif details sent out from other instances.
* When current instance is set with syncMode: `Receive`, config fields under nonOverrideConfigs will NOT be changed by any config details sent out from other instances.
* NOTE: this config will be ONLY applied during initialization, so it won't be changed dynamically
* @default {instrumentationKey:true,connectionString:true,endpointUrl:true}
*/
nonOverrideConfigs?: NonOverrideCfg;
Expand Down

0 comments on commit 7bcd35c

Please sign in to comment.