Skip to content

Commit f250ff8

Browse files
authored
Add AKS resource provider in Statsbeat (#1237)
1 parent 892bbb1 commit f250ff8

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

AutoCollection/Statsbeat.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ class Statsbeat {
302302
);
303303
if (currentCounter.totalSuccesfulRequestCount > 0) {
304304
this._statbeatMetrics.push({
305-
name: Constants.StatsbeatCounter.REQUEST_SUCCESS,
306-
value: currentCounter.totalSuccesfulRequestCount,
307-
properties: properties
305+
name: Constants.StatsbeatCounter.REQUEST_SUCCESS,
306+
value: currentCounter.totalSuccesfulRequestCount,
307+
properties: properties
308308
});
309309
currentCounter.totalSuccesfulRequestCount = 0; //Reset
310310
}
@@ -385,7 +385,11 @@ class Statsbeat {
385385
let waiting: boolean = false;
386386
this._resourceProvider = Constants.StatsbeatResourceProvider.unknown;
387387
this._resourceIdentifier = Constants.StatsbeatResourceProvider.unknown;
388-
if (process.env.WEBSITE_SITE_NAME) { // Web apps
388+
if (process.env.AKS_ARM_NAMESPACE_ID) {//AKS
389+
this._resourceProvider = Constants.StatsbeatResourceProvider.aks;
390+
this._resourceIdentifier = process.env.AKS_ARM_NAMESPACE_ID;
391+
}
392+
else if (process.env.WEBSITE_SITE_NAME) { // Web apps
389393
this._resourceProvider = Constants.StatsbeatResourceProvider.appsvc;
390394
this._resourceIdentifier = process.env.WEBSITE_SITE_NAME;
391395
if (process.env.WEBSITE_HOME_STAMPNAME) {

Declarations/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export const StatsbeatTelemetryName = "Statsbeat";
135135

136136
export const StatsbeatResourceProvider = {
137137
appsvc: "appsvc",
138+
aks: "aks",
138139
functions: "functions",
139140
vm: "vm",
140141
unknown: "unknown"

Tests/AutoCollection/Statsbeat.tests.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ describe("AutoCollection/Statsbeat", () => {
120120
done();
121121
}).catch((error) => { done(error); });
122122
});
123+
124+
it("aks", (done) => {
125+
var newEnv = <{ [id: string]: string }>{};
126+
newEnv["AKS_ARM_NAMESPACE_ID"] = "Test AKS cluster and namespace";
127+
var originalEnv = process.env;
128+
process.env = newEnv;
129+
statsBeat["_getResourceProvider"]().then(() => {
130+
process.env = originalEnv;
131+
assert.equal(statsBeat["_resourceProvider"], "aks");
132+
assert.equal(statsBeat["_resourceIdentifier"], "Test AKS cluster and namespace");
133+
done();
134+
}).catch((error) => { done(error); });
135+
});
123136
});
124137

125138
describe("#trackStatbeats", () => {

0 commit comments

Comments
 (0)