Skip to content

Commit

Permalink
Add Automatic Name replacing / Crunching
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Apr 26, 2022
1 parent 4e88f21 commit 2428a89
Show file tree
Hide file tree
Showing 133 changed files with 3,787 additions and 1,893 deletions.
64 changes: 64 additions & 0 deletions .aiAutoMinify.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"pkgs": {
"@microsoft/applicationinsights-core-js": {
"constEnums": [
"CallbackType",
"eEventsDiscardedReason",
"eLoggingSeverity",
"_eInternalMessageId",
"SendRequestReason",
"TelemetryUnloadReason",
"TelemetryUpdateReason",
"GetExtCfgMergeType"
]
},
"@microsoft/applicationinsights-perfmarkmeasure-js": {
"constEnums": []
},
"@microsoft/applicationinsights-common": {
"constEnums": [
"eStorageType",
"FieldType",
"eDistributedTracingModes",
"eRequestHeaders",
"DataPointType",
"DependencyKind",
"DependencySourceType",
"eSeverityLevel",
"DataSanitizerValues"
]
},
"@microsoft/applicationinsights-properties-js": {
"constEnums": []
},
"@microsoft/applicationinsights-dependencies-js": {
"constEnums": []
},
"@microsoft/applicationinsights-debugplugin-js": {
"constEnums": []
},
"@microsoft/applicationinsights-channel-js": {
"constEnums": []
},
"@microsoft/applicationinsights-react-native": {
"constEnums": []
},
"@microsoft/applicationinsights-clickanalytics-js": {
"constEnums": [
"_eExtendedInternalMessageId"
]
},
"@microsoft/applicationinsights-web-basic": {
"constEnums": []
},
"@microsoft/applicationinsights-analytics-js": {
"constEnums": []
},
"@microsoft/applicationinsights-web": {
"constEnums": []
},
"@microsoft/applicationinsights-react-js": {
"constEnums": []
}
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,6 @@ aicore.tests.js*
aicore.tests.d.ts
ai.tests.d.ts
/.vs

# Generated Constant File
**/__DynamicConstants.ts
76 changes: 47 additions & 29 deletions AISKU/Tests/Perf/src/AISKUPerf.Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ function addSnippetLoadingTimeEvent(AISKUPerfTest: any, endtime: number): void {
createPerfEvent(AISKUPerfTest, "SDKInit", duration, true, `AppInsightsInit-Init: Script LoadingTime: ${duration} ms added`);
}


export class AISKUPerf extends AITestClass {
public AISKUPerfTest: AppInsightsInitPerfTestClass;
public perfMgr: any;
Expand All @@ -137,7 +136,6 @@ export class AISKUPerf extends AITestClass {
public testInitialize() {
try {
this.AISKUPerfTest = new AppInsightsInitPerfTestClass();
this.AISKUPerfTest.loadScriptOnInit = () => {return this._loadScriptOnInit();}
Assert.ok(window["oneDS"], "oneDS exists");
Assert.ok(window["Microsoft"]?.ApplicationInsights?.PerfMarkMeasureManager, "perfMgr exists");
Assert.ok(window["Microsoft"]?.ApplicationInsights?.doPerf, "doPerf exists");
Expand Down Expand Up @@ -167,6 +165,7 @@ export class AISKUPerf extends AITestClass {
this.testCaseAsync({
name: "AppInsights AISKU perf Test",
stepDelay: 10000,
assertNoHooks: false,
steps: [() => {
Assert.ok(window["appInsightsInitPerftest"], "global appInsightsInitPerftest exists");
Assert.ok(window["oneDS"], "oneDS exists");
Expand Down Expand Up @@ -199,16 +198,27 @@ export class AISKUPerf extends AITestClass {
});
}

protected _loadScriptOnInit(): void {
protected _loadScriptOnInit(theModule: any): void {
var snippetLoadingEndTime = performance.now();
this._addMemoryPerfEvent(this.initialMemoryUsage);
Assert.ok(true,"AppInsights script loaded");

addSnippetLoadingTimeEvent(this.AISKUPerfTest,snippetLoadingEndTime);
addSnippetLoadingTimeEvent(this.AISKUPerfTest, snippetLoadingEndTime);

let appInsights = window["appInsights"];
this.appInsights = appInsights;

this.onDone(() => {
if (appInsights && appInsights.unload && appInsights.core && appInsights.core.isInitialized()) {
Assert.ok(true, "Unloading...");
appInsights.unload(false);
} else {
Assert.ok(true, "Unload not supported...");
}

appInsights = null;
this.appInsights = null;
});
try {
let notificationManager = this.appInsights.core["_notificationManager"] ||this.appInsights.core?.getNotifyMgr();
if (notificationManager) {
Expand All @@ -230,29 +240,31 @@ export class AISKUPerf extends AITestClass {
}

protected _loadSnippet():void {
this.initialMemoryUsage = performance["memory"]?.usedJSHeapSize;
var tag = document.createElement("script");
tag.innerText = this.getSnippet();
this.AISKUPerfTest.snippetStartTime = performance.now();
document.getElementsByTagName("head")[0].appendChild(tag);
}

public getSnippet(): string {
return `
loadSdkUsingRequire({
src: "https://js.monitor.azure.com/scripts/b/ai.${this.AISKUPerfTest.version}.min.js?${this.AISKUPerfTest.testPostfix}",
onInit: function (appInsights) {
console.log("snippet loaded");
appInsightsInitPerftest.loadScriptOnInit();
},
cfg: {
instrumentationKey: "key",
enablePerfMgr: true,
maxBatchSizeInBytes: 1000000,
maxBatchInterval: 30000000,
extensionConfig: {}
}
});`;
let self = this;
self.initialMemoryUsage = performance["memory"]?.usedJSHeapSize;
window["loadSdkUsingRequire"]({
src: self.getScriptSrc(),
onInit: function (theInstance) {
console.log("snippet loaded");
self._loadScriptOnInit(theInstance);

self.onDone(() => {
if (theInstance && theInstance.unload && theInstance.core && theInstance.core.isInitialized()) {
Assert.ok(true, "Unloading from onInit...");
theInstance.unload(false);
} else {
Assert.ok(true, "Unload not supported in onInit...");
}
});
},
cfg: {
instrumentationKey: "key",
enablePerfMgr: true,
maxBatchSizeInBytes: 1000000,
maxBatchInterval: 30000000,
extensionConfig: {}
}
});
}

public addPerfEvents() {
Expand All @@ -277,8 +289,14 @@ export class AISKUPerf extends AITestClass {
}

public getScriptSrc(): string {
return `https://js.monitor.azure.com/scripts/b/ai.${this.AISKUPerfTest.version}.min.js?${this.AISKUPerfTest.testPostfix}`;
}
let baseUrl = "https://js.monitor.azure.com/scripts/b/ai.";

if (this.AISKUPerfTest.version.indexOf("nightly") !== -1) {
baseUrl = "https://js.monitor.azure.com/nightly/ai.";
}

return baseUrl + `${this.AISKUPerfTest.version}.min.js?${this.AISKUPerfTest.testPostfix}`;
}

private _addMemoryPerfEvent(initialMemoryUsage: number, metric?: string): void {
let curMemory = performance["memory"]?.usedJSHeapSize;
Expand Down
4 changes: 3 additions & 1 deletion AISKU/Tests/PerfTests.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
};

if (snippetCfg.onInit) {
appInsights.queue.push(snippetCfg.onInit);
appInsights.queue.push(function() {
snippetCfg.onInit(appInsights);
});
}

window["appInsights"] = appInsights;
Expand Down
13 changes: 10 additions & 3 deletions AISKU/Tests/Unit/src/AISKUSize.Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import * as pako from "pako";
import { Snippet } from "../../../src/Initialization";

export class AISKUSizeCheck extends AITestClass {
private readonly MAX_DEFLATE_SIZE = 44;
private readonly MAX_RAW_SIZE = 118;
private readonly MAX_BUNDLE_SIZE = 114;
private readonly MAX_RAW_DEFLATE_SIZE = 46;
private readonly MAX_BUNDLE_DEFLATE_SIZE = 44;
private readonly rawFilePath = "../dist/applicationinsights-web.min.js";
private readonly prodFilePath = "../browser/ai.2.min.js";

Expand Down Expand Up @@ -50,6 +53,8 @@ export class AISKUSizeCheck extends AITestClass {

private _checkFileSize(isProd: boolean): void {
let _filePath = isProd? this.prodFilePath : this.rawFilePath;
let _maxFullSize = isProd ? this.MAX_BUNDLE_SIZE : this.MAX_RAW_SIZE;
let _maxDeflateSize = isProd ? this.MAX_BUNDLE_DEFLATE_SIZE : this.MAX_RAW_DEFLATE_SIZE;
let postfix = isProd? "" : "-raw";
let fileName = _filePath.split("..")[2];
this.testCase({
Expand All @@ -63,8 +68,10 @@ export class AISKUSizeCheck extends AITestClass {
return;
} else {
return response.text().then(text => {
let size = Math.ceil((pako.deflate(text).length/1024) * 100) / 100.0;
Assert.ok(size <= this.MAX_DEFLATE_SIZE ,`max ${this.MAX_DEFLATE_SIZE} KB, current deflate size is: ${size} KB`);
let size = Math.ceil((text.length/1024) * 100) / 100.0;
Assert.ok(size <= _maxFullSize, `max ${_maxFullSize} KB, current deflate size is: ${size} KB`);
let deflateSize = Math.ceil((pako.deflate(text).length/1024) * 100) / 100.0;
Assert.ok(deflateSize <= _maxDeflateSize ,`max ${_maxDeflateSize} KB, current deflate size is: ${deflateSize} KB`);
}).catch((error: Error) => {
Assert.ok(false, `AISKU${postfix} response error: ${error}`);
});
Expand Down
3 changes: 3 additions & 0 deletions AISKU/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
"build:snippet": "grunt snippetvnext",
"rebuild": "npm run build",
"test": "grunt aiskuunittests",
"mintest": "grunt aisku-mintests",
"perftest": "grunt aiskuperf",
"lint": "tslint -p tsconfig.json",
"dtsgen": "api-extractor run --local && node ../scripts/dtsgen.js 'Microsoft.ApplicationInsights'",
"sri": "node ../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt aisku-min",
"ai-restore": "grunt aisku-restore",
"nightwatch:chrome": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env chrome",
"nightwatch:firefox": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env firefox",
"nightwatch:edge": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env edge",
Expand Down
4 changes: 2 additions & 2 deletions AISKU/src/ApplicationInsightsContainer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IAppInsightsDeprecated, AppInsightsDeprecated } from "./ApplicationInsightsDeprecated";
import { Initialization as ApplicationInsights, Snippet, IApplicationInsights } from "./Initialization";
import { _legacyCookieMgr } from "@microsoft/applicationinsights-core-js";
import { AppInsightsDeprecated, IAppInsightsDeprecated } from "./ApplicationInsightsDeprecated";
import { IApplicationInsights, Initialization as ApplicationInsights, Snippet } from "./Initialization";

export class ApplicationInsightsContainer {

Expand Down
Loading

0 comments on commit 2428a89

Please sign in to comment.