Skip to content

Commit

Permalink
Add location filter to ECS client (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyaginidhi authored Sep 18, 2024
1 parent 07fa433 commit 7eb4100
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions src/common/ecs-features/ecsFeatureFlagFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion src/common/ecs-features/ecsFeatureUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 20 additions & 2 deletions src/common/utilities/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRelatedFiles[]> {
export async function fetchRelatedFiles(activeFileUri: vscode.Uri, componentType: string, fieldType: string, telemetry: ITelemetry, sessionId: string): Promise<IRelatedFiles[]> {
try {
const relatedFileTypes = relatedFilesSchema[componentType]?.[fieldType];
if (!relatedFileTypes) {
Expand All @@ -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 [];
}
}
Expand All @@ -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;
}
8 changes: 8 additions & 0 deletions src/web/client/WebExtensionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions src/web/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<string, string>) {
Expand Down

0 comments on commit 7eb4100

Please sign in to comment.