Skip to content

Commit

Permalink
Add AKS resource provider in Statsbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhdzg committed Nov 7, 2023
1 parent 892bbb1 commit 54e63e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
12 changes: 8 additions & 4 deletions AutoCollection/Statsbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ class Statsbeat {
);
if (currentCounter.totalSuccesfulRequestCount > 0) {
this._statbeatMetrics.push({
name: Constants.StatsbeatCounter.REQUEST_SUCCESS,
value: currentCounter.totalSuccesfulRequestCount,
properties: properties
name: Constants.StatsbeatCounter.REQUEST_SUCCESS,
value: currentCounter.totalSuccesfulRequestCount,
properties: properties
});
currentCounter.totalSuccesfulRequestCount = 0; //Reset
}
Expand Down Expand Up @@ -385,7 +385,11 @@ class Statsbeat {
let waiting: boolean = false;
this._resourceProvider = Constants.StatsbeatResourceProvider.unknown;
this._resourceIdentifier = Constants.StatsbeatResourceProvider.unknown;
if (process.env.WEBSITE_SITE_NAME) { // Web apps
if (process.env.AKS_ARM_NAMESPACE_ID) {//AKS
this._resourceProvider = Constants.StatsbeatResourceProvider.aks;
this._resourceIdentifier = process.env.AKS_ARM_NAMESPACE_ID;
}
else if (process.env.WEBSITE_SITE_NAME) { // Web apps
this._resourceProvider = Constants.StatsbeatResourceProvider.appsvc;
this._resourceIdentifier = process.env.WEBSITE_SITE_NAME;
if (process.env.WEBSITE_HOME_STAMPNAME) {
Expand Down
1 change: 1 addition & 0 deletions Declarations/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const StatsbeatTelemetryName = "Statsbeat";

export const StatsbeatResourceProvider = {
appsvc: "appsvc",
aks: "aks",
functions: "functions",
vm: "vm",
unknown: "unknown"
Expand Down
13 changes: 13 additions & 0 deletions Tests/AutoCollection/Statsbeat.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ describe("AutoCollection/Statsbeat", () => {
done();
}).catch((error) => { done(error); });
});

it("aks", (done) => {
var newEnv = <{ [id: string]: string }>{};
newEnv["AKS_ARM_NAMESPACE_ID"] = "Test AKS cluster and namespace";
var originalEnv = process.env;
process.env = newEnv;
statsBeat["_getResourceProvider"]().then(() => {
process.env = originalEnv;
assert.equal(statsBeat["_resourceProvider"], "aks");
assert.equal(statsBeat["_resourceIdentifier"], "Test AKS cluster and namespace");
done();
}).catch((error) => { done(error); });
});
});

describe("#trackStatbeats", () => {
Expand Down

0 comments on commit 54e63e2

Please sign in to comment.