This commit is contained in:
Karlie-777 2024-04-22 16:29:05 -07:00 коммит произвёл GitHub
Родитель 50d893a00e
Коммит f2565757eb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 129 добавлений и 7 удалений

Просмотреть файл

@ -271,6 +271,7 @@ export class ApplicationInsightsTests extends AITestClass {
ai.config.extensionConfig = ai.config.extensionConfig || {};
let extConfig = ai.config.extensionConfig["AppInsightsCfgSyncPlugin"];
Assert.equal(extConfig.cfgUrl, CONFIG_ENDPOINT_URL, "default cdn endpoint should be set");
Assert.equal(extConfig.syncMode, 2, "default mode should be set to receive");
let featureOptIn = config.featureOptIn || {};
Assert.equal(featureOptIn["iKeyUsage"].mode, FeatureOptInMode.enable, "ikey message should be turned on");

Просмотреть файл

@ -4,7 +4,7 @@
import dynamicProto from "@microsoft/dynamicproto-js";
import { AnalyticsPlugin, ApplicationInsights } from "@microsoft/applicationinsights-analytics-js";
import { CfgSyncPlugin, ICfgSyncConfig } from "@microsoft/applicationinsights-cfgsync-js";
import { CfgSyncPlugin, ICfgSyncConfig, ICfgSyncMode } from "@microsoft/applicationinsights-cfgsync-js";
import { Sender } from "@microsoft/applicationinsights-channel-js";
import {
AnalyticsPluginIdentifier, DEFAULT_BREEZE_PATH, IAutoExceptionTelemetry, IConfig, IDependencyTelemetry, IEventTelemetry,
@ -92,7 +92,8 @@ const defaultConfigValues: IConfigDefaults<IConfiguration & IConfig> = {
),
extensionConfig: cfgDfMerge<{[key: string]: any}>({
["AppInsightsCfgSyncPlugin"]: cfgDfMerge<ICfgSyncConfig>({
cfgUrl: CONFIG_ENDPOINT_URL
cfgUrl: CONFIG_ENDPOINT_URL,
syncMode: ICfgSyncMode.Receive
})
})
};

Просмотреть файл

@ -1,5 +1,5 @@
import { Assert, AITestClass, IFetchArgs, PollingAssert } from "@microsoft/ai-test-framework";
import { AppInsightsCore, IAppInsightsCore, IPlugin, ITelemetryItem, getGlobal, getGlobalInst } from "@microsoft/applicationinsights-core-js";
import { AppInsightsCore, FeatureOptInMode, IAppInsightsCore, IPlugin, ITelemetryItem, getGlobal, getGlobalInst } from "@microsoft/applicationinsights-core-js";
import { IConfiguration } from "@microsoft/applicationinsights-core-js";
import { CfgSyncPlugin } from "../../../../applicationinsights-cfgsync-js/src/applicationinsights-cfgsync-js";
import { ICfgSyncConfig, ICfgSyncMode, NonOverrideCfg } from "../../../src/Interfaces/ICfgSyncConfig";
@ -10,7 +10,7 @@ import { createSyncPromise } from "@nevware21/ts-async";
export class CfgSyncPluginTests extends AITestClass {
private core: AppInsightsCore;
private _config: IConfiguration;
private _config: IConfiguration & IConfig;
private mainInst: CfgSyncPlugin;
private identifier: string;
private _channel: ChannelPlugin;
@ -271,7 +271,7 @@ export class CfgSyncPluginTests extends AITestClass {
let fetchStub = this._context["fetchStub"];
let patchEvnSpy = this._context["patchEvnSpy"];
let config = {
instrumentationKey:"testIkey",
//instrumentationKey:"testIkey", // should not be override
enableAjaxPerfTracking: true
} as IConfiguration & IConfig;
if (fetchStub.called && patchEvnSpy.called) {
@ -330,7 +330,7 @@ export class CfgSyncPluginTests extends AITestClass {
let fetchStub = this._context["fetchStub"];
let patchEvnSpy = this._context["patchEvnSpy"];
let config = {
instrumentationKey:"testIkey",
//instrumentationKey:"testIkey", // should not be override
enableAjaxPerfTracking: true
} as IConfiguration & IConfig;
if (fetchStub.called && patchEvnSpy.called) {
@ -524,6 +524,124 @@ export class CfgSyncPluginTests extends AITestClass {
}, "response received", 60, 100) as any)
});
this.testCaseAsync({
name: "CfgSyncPlugin: Test with current cfgSync CDN v1",
stepDelay: 10,
useFakeTimers: true,
useFakeServer: true,
steps: [ () => {
let doc = getGlobal();
this.onDone(() => {
this.core.unload(false);
});
let fetchStub = this.sandbox.spy((doc as any), "fetch");
this._config.featureOptIn = {["iKeyUsage"]: {mode: FeatureOptInMode.enable}, ["CdnUsage"]:{mode: FeatureOptInMode.disable}}
this._config.throttleMgrCfg = {
["109"]: {disabled: true},
["106"]: {disabled: true},
["110"]: {disabled: true}
}
this._config.extensionConfig = { [this.identifier]: {
syncMode: ICfgSyncMode.Receive,
cfgUrl: "https://js.monitor.azure.com/scripts/b/ai.config.1.cfg.json",
scheduleFetchTimeout: 10000
}};
this._context["fetchStub"] = fetchStub;
this.core.initialize(this._config, [this._channel]);
}].concat(PollingAssert.createPollingAssert(() => {
let fetchStub = this._context["fetchStub"];
Assert.equal(fetchStub.callCount, 1, "fetch is should called once");
if (fetchStub.called) {
return true;
}
return false;
}, "wait for fetch response", 60, 100) as any).concat(PollingAssert.createPollingAssert(() => {
let coreConfig = this.core.config as IConfig & IConfiguration;
let featureOptIn = coreConfig.featureOptIn || {};
let throttleMgrConfig = coreConfig.throttleMgrCfg || {};
let ikeyOptIn = featureOptIn["iKeyUsage"];
let defaultIkey = throttleMgrConfig["109"];
let defaultEnabled = !defaultIkey.disabled;
let onConfig = ikeyOptIn.onCfg;
let offConfig = ikeyOptIn.onCfg;
if (onConfig && offConfig && defaultEnabled) {
let ikeyMsg = throttleMgrConfig["106"];
Assert.equal(ikeyMsg.disabled, false, "ikey msg should be enabled");
let otherMsg = throttleMgrConfig["110"];
Assert.equal(otherMsg.disabled, true, "other msg should be disabled");
let cdnOptIn = featureOptIn["CdnUsage"];
Assert.equal(cdnOptIn.mode, 2, "cdn feature optin should be disabled");
Assert.equal(ikeyOptIn.mode, 3, "ikey feature optin should be enabled");
return true;
}
return false;
}, "wait for core config update", 60, 100) as any)
});
this.testCaseAsync({
name: "CfgSyncPlugin: NonOverride values should not be changed Test with current cfgSync CDN v1",
stepDelay: 10,
useFakeTimers: true,
useFakeServer: true,
steps: [ () => {
let doc = getGlobal();
this.onDone(() => {
this.core.unload(false);
});
let fetchStub = this.sandbox.spy((doc as any), "fetch");
this._config.throttleMgrCfg = {};
this._config.featureOptIn = {["iKeyUsage"]: {mode: FeatureOptInMode.enable}, ["CdnUsage"]:{mode: FeatureOptInMode.disable}}
this._config.throttleMgrCfg = {
["109"]: {disabled: true},
["106"]: {disabled: true},
["110"]: {disabled: true}
}
this._config.extensionConfig = { [this.identifier]: {
syncMode: ICfgSyncMode.Receive,
cfgUrl: "https://js.monitor.azure.com/scripts/b/ai.config.1.cfg.json",
scheduleFetchTimeout: 10000,
nonOverrideConfigs: {throttleMgrCfg: true}
} as ICfgSyncConfig};
this._context["fetchStub"] = fetchStub;
this.core.initialize(this._config, [this._channel]);
}].concat(PollingAssert.createPollingAssert(() => {
let fetchStub = this._context["fetchStub"];
Assert.equal(fetchStub.callCount, 1, "fetch is should called once");
if (fetchStub.called) {
return true;
}
return false;
}, "wait for fetch response", 60, 100) as any).concat(PollingAssert.createPollingAssert(() => {
let coreConfig = this.core.config as IConfig & IConfiguration;
let featureOptIn = coreConfig.featureOptIn || {};
let throttleMgrConfig = coreConfig.throttleMgrCfg || {};
let ikeyOptIn = featureOptIn["iKeyUsage"];
let onConfig = ikeyOptIn.onCfg;
let offConfig = ikeyOptIn.onCfg;
if (onConfig && offConfig) {
let defaultIkey = throttleMgrConfig["109"];
Assert.equal(defaultIkey.disabled, true, "ikey msg should be disbaled");
let ikeyMsg = throttleMgrConfig["106"];
Assert.equal(ikeyMsg.disabled, true, "ikey msg should be disabled");
let otherMsg = throttleMgrConfig["110"];
Assert.equal(otherMsg.disabled, true, "other msg should be disabled");
let cdnOptIn = featureOptIn["CdnUsage"];
Assert.equal(cdnOptIn.mode, 2, "cdn feature optin should be disabled");
Assert.equal(ikeyOptIn.mode, 3, "ikey feature optin should be enabled");
return true;
}
return false;
}, "wait for core config update", 60, 100) as any)
});
}
}

Просмотреть файл

@ -317,7 +317,9 @@ export class CfgSyncPlugin extends BaseTelemetryPlugin implements ICfgSyncPlugin
if (JSON) {
let cdnCfg = JSON.parse(response); //comments are not allowed
let cfg = applyCdnfeatureCfg(cdnCfg, _self.core);
cfg && _setCfg(cfg, isAutoSync);
let newCfg = cfg && isPlainObject(cfg) && _replaceTartgetByKeys(cfg);
newCfg && _setCfg(newCfg, isAutoSync);
//cfg && _setCfg(cfg, isAutoSync);
}
} else {
_retryCnt ++;