Skip to content

Commit

Permalink
Add the session unit tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Zhu committed Jan 8, 2025
1 parent 3162e2d commit a14a863
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
10 changes: 7 additions & 3 deletions server/routerlicious/packages/lambdas/src/nexus/networkHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
/* eslint-disable unicorn/prefer-ternary */

import * as core from "@fluidframework/server-services-core";
import { getNetworkInformationFromIP } from "@fluidframework/server-services-client";

// eslint-disable-next-line jsdoc/require-description
/**
* @returns NetworkInformation
* Check the network information to determine if the socket should connect.
*
* @param tenantManager - The tenant manager to use to get the tenant information.
* @param socket - The socket to check the network information for.
* @returns A promise that resolves to an object containing a message and a boolean indicating if the socket should connect.
*/
export async function checkNetworkInformation(
tenantManager: core.ITenantManager,
Expand All @@ -23,13 +25,15 @@ export async function checkNetworkInformation(
const networkInfo = getNetworkInformationFromIP(clientIPAddress);
if (networkInfo.isPrivateLink) {
const accountLinkID = tenantInfo?.customData?.accountLinkID;
// eslint-disable-next-line unicorn/prefer-ternary
if (networkInfo.privateLinkId === accountLinkID) {
return { message: "This is a private link socket connection", shouldConnect: true };
} else {
return { message: "private link should not connect", shouldConnect: false };
}
} else {
const accountLinkID = tenantInfo?.customData?.accountLinkID;
// eslint-disable-next-line unicorn/prefer-ternary
if (accountLinkID) {
return {
message:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
IWebSocketTracker,
IServiceMessageResourceManager,
IFluidAccessTokenGenerator,
IReadinessCheck,
} from "@fluidframework/server-services-core";
import { IRedisClientConnectionManager } from "@fluidframework/server-services-utils";
import { IDocumentDeleteService } from "./services";
import { IReadinessCheck } from "@fluidframework/server-services-core";
import { ITenantRepository } from "../riddler";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,35 @@ export function create(
async (request, response, next) => {
const documentId = request.params.id;
const tenantId = request.params.tenantId;

const lumberjackProperties = getLumberBaseProperties(documentId, tenantId);
const getSessionMetric: Lumber<LumberEventName.GetSession> = Lumberjack.newLumberMetric(
LumberEventName.GetSession,
lumberjackProperties,
);
// Tracks the different stages of getSessionMetric
const connectionTrace = new StageTrace<string>("GetSession");

// Reject get session request on existing, inactive sessions if cluster is in draining process.
if (
clusterDrainingChecker &&
(await clusterDrainingChecker.isClusterDraining().catch((error) => {
Lumberjack.error("Failed to get cluster draining status", undefined, error);
return false;
}))
) {
Lumberjack.info("Cluster is in draining process. Reject get session request.");
connectionTrace?.stampStage("ClusterIsDraining");
const error = createFluidServiceNetworkError(503, {
message: "Server is unavailable. Please retry session discovery later.",
internalErrorCode: InternalErrorCode.ClusterDraining,
});
handleResponse(Promise.reject(error), response);
}
connectionTrace?.stampStage("ClusterDrainingChecked");
const readDocumentRetryDelay: number = config.get("getSession:readDocumentRetryDelay");
const readDocumentMaxRetries: number = config.get("getSession:readDocumentMaxRetries");

const clientIPAddress = request.ip ? request.ip : "";
const networkInfo = getNetworkInformationFromIP(clientIPAddress);
const documentUrls = getDocumentUrlsfromNetworkInfo(
Expand All @@ -425,14 +454,6 @@ export function create(
networkInfo.isPrivateLink,
);

const lumberjackProperties = getLumberBaseProperties(documentId, tenantId);
const getSessionMetric: Lumber<LumberEventName.GetSession> = Lumberjack.newLumberMetric(
LumberEventName.GetSession,
lumberjackProperties,
);
// Tracks the different stages of getSessionMetric
const connectionTrace = new StageTrace<string>("GetSession");

const session = getSession(
documentUrls.documentOrdererUrl,
documentUrls.documentHistorianUrl,
Expand All @@ -445,6 +466,8 @@ export function create(
clusterDrainingChecker,
ephemeralDocumentTTLSec,
connectionTrace,
readDocumentRetryDelay,
readDocumentMaxRetries,
);

const onSuccess = (result: ISession): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,9 @@
},
"clusterDraining": {
"enable": false
},
"getSession": {
"readDocumentRetryDelay": 150,
"readDocumentMaxRetries": 2
}
}

0 comments on commit a14a863

Please sign in to comment.