From f250ff857f5b1ba7169e9bec3a6191fad4678e1f Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:48:50 -0800 Subject: [PATCH] Add AKS resource provider in Statsbeat (#1237) --- AutoCollection/Statsbeat.ts | 12 ++++++++---- Declarations/Constants.ts | 1 + Tests/AutoCollection/Statsbeat.tests.ts | 13 +++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/AutoCollection/Statsbeat.ts b/AutoCollection/Statsbeat.ts index a498e8537..05db7ce37 100644 --- a/AutoCollection/Statsbeat.ts +++ b/AutoCollection/Statsbeat.ts @@ -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 } @@ -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) { diff --git a/Declarations/Constants.ts b/Declarations/Constants.ts index 14e603e5d..03d6ea553 100644 --- a/Declarations/Constants.ts +++ b/Declarations/Constants.ts @@ -135,6 +135,7 @@ export const StatsbeatTelemetryName = "Statsbeat"; export const StatsbeatResourceProvider = { appsvc: "appsvc", + aks: "aks", functions: "functions", vm: "vm", unknown: "unknown" diff --git a/Tests/AutoCollection/Statsbeat.tests.ts b/Tests/AutoCollection/Statsbeat.tests.ts index a7a5d99a6..2abf8137e 100644 --- a/Tests/AutoCollection/Statsbeat.tests.ts +++ b/Tests/AutoCollection/Statsbeat.tests.ts @@ -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", () => {