From 7eb41000a48e081621bd2c2b8e49b93a1e4de33e Mon Sep 17 00:00:00 2001 From: tyaginidhi Date: Wed, 18 Sep 2024 12:00:44 +0530 Subject: [PATCH] Add location filter to ECS client (#1042) --- src/client/extension.ts | 6 +++-- .../ecs-features/ecsFeatureFlagFilters.ts | 6 +++++ src/common/ecs-features/ecsFeatureUtil.ts | 3 ++- src/common/utilities/Utils.ts | 22 +++++++++++++++++-- src/web/client/WebExtensionContext.ts | 8 +++++++ src/web/client/extension.ts | 15 ++++++++----- 6 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/client/extension.ts b/src/client/extension.ts index bc3460891..a97f6c2e1 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -45,6 +45,7 @@ import { EXTENSION_ID, SUCCESS } from "../common/constants"; import { AadIdKey, EnvIdKey, TenantIdKey } from "../common/OneDSLoggerTelemetry/telemetryConstants"; import { PowerPagesAppName, PowerPagesClientName } from "../common/ecs-features/constants"; import { ECSFeaturesClient } from "../common/ecs-features/ecsFeatureClient"; +import { getECSOrgLocationValue } from "../common/utilities/Utils"; let client: LanguageClient; let _context: vscode.ExtensionContext; @@ -191,7 +192,7 @@ export async function activate( const orgID = orgDetails.OrgId; const artemisResponse = await ArtemisService.getArtemisResponse(orgID, _telemetry, ""); if (artemisResponse !== null && artemisResponse.response !== null) { - const { geoName, geoLongName } = artemisResponse.response; + const { geoName, geoLongName, clusterName, clusterNumber } = artemisResponse.response; const pacActiveAuth = await pacTerminal.getWrapper()?.activeAuth(); let AadIdObject, EnvID, TenantID; if ((pacActiveAuth && pacActiveAuth.Status === SUCCESS)) { @@ -207,7 +208,8 @@ export async function activate( EnvID: EnvID[0].Value, UserID: AadIdObject[0].Value, TenantID: TenantID[0].Value, - Region: artemisResponse.stamp + Region: artemisResponse.stamp, + Location: getECSOrgLocationValue(clusterName, clusterNumber) }, PowerPagesClientName, true); } diff --git a/src/common/ecs-features/ecsFeatureFlagFilters.ts b/src/common/ecs-features/ecsFeatureFlagFilters.ts index e21381a92..a32ed7ea2 100644 --- a/src/common/ecs-features/ecsFeatureFlagFilters.ts +++ b/src/common/ecs-features/ecsFeatureFlagFilters.ts @@ -25,5 +25,11 @@ export interface ECSAPIFeatureFlagFilters { */ Region: string; + /** + * Deployment cluster location + * @example NDE, WCDE, NCH, WCH, CAE, NAE, SBR, SCUS, ECA, CCA, SIN, CIN, CFR, SFR + */ + Location: string; + // TBD - more API call filters to be added later } diff --git a/src/common/ecs-features/ecsFeatureUtil.ts b/src/common/ecs-features/ecsFeatureUtil.ts index d8fb297c7..df0d7d653 100644 --- a/src/common/ecs-features/ecsFeatureUtil.ts +++ b/src/common/ecs-features/ecsFeatureUtil.ts @@ -14,7 +14,8 @@ export function createECSRequestURL(filters: ECSAPIFeatureFlagFilters, clientNam EnvironmentID: filters.EnvID, UserID: filters.UserID, TenantID: filters.TenantID, - region: filters.Region + region: filters.Region, + location: filters.Location, }; const queryString = Object.keys(queryParams) diff --git a/src/common/utilities/Utils.ts b/src/common/utilities/Utils.ts index 86887253f..853f97433 100644 --- a/src/common/utilities/Utils.ts +++ b/src/common/utilities/Utils.ts @@ -264,7 +264,7 @@ async function getFileContentByType(activeFileUri: vscode.Uri, componentType: st } //fetchRelatedFiles function based on component type -export async function fetchRelatedFiles(activeFileUri: vscode.Uri, componentType: string, fieldType: string, telemetry: ITelemetry, sessionId:string): Promise { +export async function fetchRelatedFiles(activeFileUri: vscode.Uri, componentType: string, fieldType: string, telemetry: ITelemetry, sessionId: string): Promise { try { const relatedFileTypes = relatedFilesSchema[componentType]?.[fieldType]; if (!relatedFileTypes) { @@ -286,7 +286,7 @@ export async function fetchRelatedFiles(activeFileUri: vscode.Uri, componentType } catch (error) { const message = (error as Error)?.message; telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_COPILOT_CONTEXT_RELATED_FILES_FETCH_FAILED, { error: message, sessionId: sessionId }); - oneDSLoggerWrapper.getLogger().traceError(VSCODE_EXTENSION_COPILOT_CONTEXT_RELATED_FILES_FETCH_FAILED, message, error as Error, { sessionId:sessionId }, {}); + oneDSLoggerWrapper.getLogger().traceError(VSCODE_EXTENSION_COPILOT_CONTEXT_RELATED_FILES_FETCH_FAILED, message, error as Error, { sessionId: sessionId }, {}); return []; } } @@ -302,3 +302,21 @@ export function getFileNameFromUri(uri: vscode.Uri): string { export function getFolderPathFromUri(uri: vscode.Uri): string { return path.dirname(uri.fsPath); } + +export function getECSOrgLocationValue(clusterName: string, clusterNumber: string): string { + // Find the position of the identifier in the input string + const identifierPosition = clusterName.indexOf("il" + clusterNumber); + + // If the identifier is not found, return an empty string + if (identifierPosition === -1) { + return ''; + } + + // Calculate the starting position of the substring "SIN" or "SEAS" or "SFR" in the input string + const startPosition = identifierPosition + clusterNumber.length; + + // Extract the substring "sin" from the input string + const extractedSubstring = clusterName.substring(startPosition); + + return extractedSubstring; +} diff --git a/src/web/client/WebExtensionContext.ts b/src/web/client/WebExtensionContext.ts index a67b95cad..3128fa2ed 100644 --- a/src/web/client/WebExtensionContext.ts +++ b/src/web/client/WebExtensionContext.ts @@ -109,6 +109,7 @@ class WebExtensionContext implements IWebExtensionContext { private _websiteLanguageCode: string; private _geoName: string; private _geoLongName: string; + private _clusterLocation: string; private _serviceEndpointCategory: ServiceEndpointCategory; private _telemetry: WebExtensionTelemetry; private _npsEligibility: boolean; @@ -206,6 +207,12 @@ class WebExtensionContext implements IWebExtensionContext { public set geoLongName(name: string) { this._geoLongName = name; } + public get clusterLocation() { + return this._clusterLocation; + } + public set clusterLocation(name: string) { + this._clusterLocation = name; + } public get serviceEndpointCategory() { return this._serviceEndpointCategory; } @@ -281,6 +288,7 @@ class WebExtensionContext implements IWebExtensionContext { this._websiteLanguageCode = ""; this._geoName = ""; this._geoLongName = ""; + this._clusterLocation = ""; this._serviceEndpointCategory = ServiceEndpointCategory.NONE; this._telemetry = new WebExtensionTelemetry(); this._npsEligibility = false; diff --git a/src/web/client/extension.ts b/src/web/client/extension.ts index b135a292f..967617de1 100644 --- a/src/web/client/extension.ts +++ b/src/web/client/extension.ts @@ -43,8 +43,8 @@ import { PowerPagesAppName, PowerPagesClientName } from "../../common/ecs-featur import { IPortalWebExtensionInitQueryParametersTelemetryData } from "../../common/OneDSLoggerTelemetry/web/client/webExtensionTelemetryInterface"; import { ArtemisService } from "../../common/services/ArtemisService"; import { showErrorDialog } from "../../common/utilities/errorHandlerUtil"; -import { ServiceEndpointCategory } from "../../common/services/Constants"; import { EXTENSION_ID } from "../../common/constants"; +import { getECSOrgLocationValue } from "../../common/utilities/Utils"; export function activate(context: vscode.ExtensionContext): void { // setup telemetry @@ -156,7 +156,8 @@ export function activate(context: vscode.ExtensionContext): void { EnvID: queryParamsMap.get(queryParameters.ENV_ID) as string, UserID: WebExtensionContext.userId, TenantID: queryParamsMap.get(queryParameters.TENANT_ID) as string, - Region: queryParamsMap.get(queryParameters.REGION) as string + Region: queryParamsMap.get(queryParameters.REGION) as string, + Location: queryParamsMap.get(queryParameters.GEO) as string }, PowerPagesClientName); @@ -666,17 +667,19 @@ function isActiveDocument(fileFsPath: string): boolean { async function fetchArtemisData(orgId: string) { const artemisResponse = await ArtemisService.getArtemisResponse(orgId, WebExtensionContext.telemetry.getTelemetryReporter(), ""); - if (artemisResponse === null) { + if (artemisResponse === null || artemisResponse.response === null) { WebExtensionContext.telemetry.sendErrorTelemetry( webExtensionTelemetryEventNames.WEB_EXTENSION_ARTEMIS_RESPONSE_FAILED, fetchArtemisData.name, ARTEMIS_RESPONSE_FAILED ); + return; } - WebExtensionContext.geoName = artemisResponse?.response?.geoName ?? ""; - WebExtensionContext.geoLongName = artemisResponse?.response?.geoLongName ?? ""; - WebExtensionContext.serviceEndpointCategory = artemisResponse?.stamp ?? ServiceEndpointCategory.NONE; + WebExtensionContext.geoName = artemisResponse.response.geoName; + WebExtensionContext.geoLongName = artemisResponse.response.geoLongName; + WebExtensionContext.serviceEndpointCategory = artemisResponse.stamp; + WebExtensionContext.clusterLocation = getECSOrgLocationValue(artemisResponse.response.clusterName, artemisResponse.response.clusterNumber); } function logOneDSLogger(queryParamsMap: Map) {