Skip to content

Commit

Permalink
solutionOne (#2175)
Browse files Browse the repository at this point in the history
  • Loading branch information
siyuniu-ms committed Oct 10, 2023
1 parent 4c326f7 commit 5f10dcf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
4 changes: 2 additions & 2 deletions AISKU/Tests/Unit/src/CdnThrottle.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ export class CdnThrottle extends AITestClass {
let core = this._ai['core'];
let _logger = core.logger;
let loggingSpy = this.sandbox.stub(_logger, 'throwInternal');
Assert.ok(!loggingSpy.called);
Assert.equal(loggingSpy.called, 0);

// now enable feature
this.init.config.featureOptIn = {["iKeyUsage"]: {mode: FeatureOptInMode.enable}};
this.clock.tick(1);
Assert.ok(loggingSpy.called);
Assert.equal(loggingSpy.called, 1);
Assert.equal(_eInternalMessageId.InstrumentationKeyDeprecation, loggingSpy.args[0][1]);
let message= loggingSpy.args[0][2];
Assert.ok(message.includes("Instrumentation key"));
Expand Down
37 changes: 34 additions & 3 deletions AISKU/Tests/Unit/src/ThrottleSentMessage.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,43 @@ export class ThrottleSentMessage extends AITestClass {
config.throttleMgrCfg= {[_eInternalMessageId.CdnDeprecation]:tconfig, [_eInternalMessageId.DefaultThrottleMsgKey]:tconfig};
this._ai.context.internal.sdkSrc = "az416426";
this.clock.tick(1);
Assert.ok(loggingSpy.called);
Assert.equal(loggingSpy.called, 1);
Assert.equal(_eInternalMessageId.CdnDeprecation, loggingSpy.args[0][1]);
let message= loggingSpy.args[0][2];
Assert.ok(message.includes("Cdn"));
}
});
this.testCase({
name: "ThrottleSentMessage: Message will not be sent again when other config change",
useFakeTimers: true,
test: () => {
Assert.ok(this._ai, 'ApplicationInsights SDK exists');
Assert.ok(this._ai.appInsights, 'App Analytics exists');
Assert.equal(true, this._ai.appInsights.isInitialized(), 'App Analytics is initialized');

Assert.ok(this._ai.appInsights.core, 'Core exists');
Assert.equal(true, this._ai.appInsights.core.isInitialized(),
'Core is initialized');
let loggingSpy = this.sandbox.stub(this._logger, 'throwInternal');

let config = this.getAi.config;

config.throttleMgrCfg= {[_eInternalMessageId.CdnDeprecation]:tconfig, [_eInternalMessageId.DefaultThrottleMsgKey]:tconfig};
config.featureOptIn = {["CdnUsage"]: {mode: FeatureOptInMode.enable},["iKeyUsage"]: {mode: FeatureOptInMode.enable}};
this._ai.context.internal.sdkSrc = "az416426";
this.clock.tick(1);
Assert.equal(loggingSpy.called, 1);
console.log("is called", loggingSpy.callCount);
Assert.equal(_eInternalMessageId.CdnDeprecation, loggingSpy.args[0][1]);
let message= loggingSpy.args[0][2];
Assert.ok(message.includes("Cdn"));

config.instrumentationKey = "newinstrumentkey";
this.clock.tick(1);
Assert.equal(loggingSpy.called, 1);

}
});
}

public ikeyMessageTests(): void {
Expand All @@ -144,7 +175,7 @@ export class ThrottleSentMessage extends AITestClass {
config.featureOptIn = {["iKeyUsage"]: {mode: FeatureOptInMode.enable}};
this.clock.tick(1);

Assert.ok(loggingSpy.called);
Assert.equal(loggingSpy.called, 1);
Assert.equal(_eInternalMessageId.InstrumentationKeyDeprecation, loggingSpy.args[0][1]);
let message= loggingSpy.args[0][2];
Assert.ok(message.includes("Instrumentation key"));
Expand Down Expand Up @@ -185,7 +216,7 @@ export class ThrottleSentMessage extends AITestClass {
snippet.config.throttleMgrCfg= {[_eInternalMessageId.SdkLdrUpdate]:tconfig, [_eInternalMessageId.DefaultThrottleMsgKey]:tconfig};
snippet.config.featureOptIn = {["SdkLoaderVer"]: {mode: FeatureOptInMode.enable}}
this.clock.tick(1);
Assert.ok(loggingSpy.called);
Assert.equal(loggingSpy.called, 1);
Assert.equal(_eInternalMessageId.SdkLdrUpdate, loggingSpy.args[0][1]);
}
});
Expand Down
12 changes: 3 additions & 9 deletions AISKU/src/AISku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,23 +310,17 @@ export class AppInsightsSku implements IApplicationInsights {
var result;
if (!_iKeySentMessage && !_config.connectionString && isFeatureEnabled(IKEY_USAGE, _config)) {
result = _throttleMgr.sendMessage( _eInternalMessageId.InstrumentationKeyDeprecation, "See Instrumentation key support at aka.ms/IkeyMigrate");
if (result && result.isThrottled){
_iKeySentMessage = true;
}
_iKeySentMessage = true;
}

if (!_cdnSentMessage && _self.context.internal.sdkSrc && _self.context.internal.sdkSrc.indexOf("az416426") != -1 && isFeatureEnabled(CDN_USAGE, _config)) {
result = _throttleMgr.sendMessage( _eInternalMessageId.CdnDeprecation, "See Cdn support notice at aka.ms/JsActiveCdn");
if (result && result.isThrottled){
_cdnSentMessage = true;
}
_cdnSentMessage = true;
}

if (!_sdkVerSentMessage && parseInt(_snippetVersion) < 6 && isFeatureEnabled(SDK_LOADER_VER, _config)) {
result = _throttleMgr.sendMessage( _eInternalMessageId.SdkLdrUpdate, "An updated Sdk Loader is available, see aka.ms/SnippetVer");
if (result && result.isThrottled){
_sdkVerSentMessage = true;
}
_sdkVerSentMessage = true;
}

}));
Expand Down

0 comments on commit 5f10dcf

Please sign in to comment.