Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract customData simplification & retrieving in historian with customization #23208

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/historian/packages/historian-base/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IThrottler,
IRevokedTokenChecker,
IDocumentManager,
Expand Down Expand Up @@ -40,6 +41,7 @@ export function create(
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
readinessCheck?: IReadinessCheck,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
) {
// Express app configuration
const app: express.Express = express();
Expand Down Expand Up @@ -110,6 +112,7 @@ export function create(
revokedTokenChecker,
denyList,
ephemeralDocumentTTLSec,
simplifiedCustomDataRetriever,
);
app.use(apiRoutes.git.blobs);
app.use(apiRoutes.git.refs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IRevokedTokenChecker,
IReadinessCheck,
} from "@fluidframework/server-services-core";
Expand All @@ -16,4 +17,5 @@ export interface IHistorianResourcesCustomizations {
redisClientConnectionManager?: IRedisClientConnectionManager;
redisClientConnectionManagerForThrottling?: IRedisClientConnectionManager;
readinessCheck?: IReadinessCheck;
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as git from "@fluidframework/gitresources";
import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IThrottler,
IRevokedTokenChecker,
IDocumentManager,
Expand Down Expand Up @@ -34,6 +35,7 @@ export function create(
revokedTokenChecker?: IRevokedTokenChecker,
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
): Router {
const router: Router = Router();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { ICommit, ICreateCommitParams } from "@fluidframework/gitresources";
import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IThrottler,
IRevokedTokenChecker,
IDocumentManager,
Expand Down Expand Up @@ -34,6 +35,7 @@ export function create(
revokedTokenChecker?: IRevokedTokenChecker,
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
): Router {
const router: Router = Router();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as git from "@fluidframework/gitresources";
import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IThrottler,
IRevokedTokenChecker,
IDocumentManager,
Expand Down Expand Up @@ -34,6 +35,7 @@ export function create(
revokedTokenChecker?: IRevokedTokenChecker,
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
): Router {
const router: Router = Router();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as git from "@fluidframework/gitresources";
import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IThrottler,
IRevokedTokenChecker,
IDocumentManager,
Expand Down Expand Up @@ -34,6 +35,7 @@ export function create(
revokedTokenChecker?: IRevokedTokenChecker,
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
): Router {
const router: Router = Router();

Expand Down
2 changes: 2 additions & 0 deletions server/historian/packages/historian-base/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IThrottler,
IRevokedTokenChecker,
IDocumentManager,
Expand Down Expand Up @@ -52,6 +53,7 @@ export function create(
revokedTokenChecker?: IRevokedTokenChecker,
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
): IRoutes {
const commonRouteParams: CommonRouteParams = [
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as git from "@fluidframework/gitresources";
import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IThrottler,
IRevokedTokenChecker,
IDocumentManager,
Expand Down Expand Up @@ -34,6 +35,7 @@ export function create(
revokedTokenChecker?: IRevokedTokenChecker,
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
): Router {
const router: Router = Router();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IThrottler,
IRevokedTokenChecker,
IDocumentManager,
Expand Down Expand Up @@ -33,6 +34,7 @@ export function create(
revokedTokenChecker?: IRevokedTokenChecker,
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
): Router {
const router: Router = Router();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { IHeader } from "@fluidframework/gitresources";
import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IThrottler,
IRevokedTokenChecker,
IDocumentManager,
Expand Down Expand Up @@ -34,6 +35,7 @@ export function create(
revokedTokenChecker?: IRevokedTokenChecker,
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
): Router {
const router: Router = Router();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "@fluidframework/server-services-client";
import {
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IThrottler,
IRevokedTokenChecker,
IDocumentManager,
Expand Down Expand Up @@ -39,6 +40,7 @@ export function create(
revokedTokenChecker?: IRevokedTokenChecker,
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
): Router {
const router: Router = Router();
const ignoreIsEphemeralFlag: boolean = config.get("ignoreEphemeralFlag") ?? true;
Expand Down Expand Up @@ -129,6 +131,7 @@ export function create(
isEphemeralContainer,
denyList,
ephemeralDocumentTTLSec,
simplifiedCustomDataRetriever,
});
return service.createSummary(params, initial);
}
Expand Down
6 changes: 6 additions & 0 deletions server/historian/packages/historian-base/src/routes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
runWithRetry,
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IRevokedTokenChecker,
IDocumentManager,
IDocumentStaticProperties,
Expand Down Expand Up @@ -45,6 +46,7 @@ export type CommonRouteParams = [
revokedTokenChecker?: IRevokedTokenChecker,
denyList?: IDenyList,
ephemeralDocumentTTLSec?: number,
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
];

export class createGitServiceArgs {
Expand All @@ -61,6 +63,7 @@ export class createGitServiceArgs {
isEphemeralContainer?: boolean = false;
ephemeralDocumentTTLSec?: number = 60 * 60 * 24; // 24 hours
denyList?: IDenyList;
simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever;
}

function getEphemeralContainerCacheKey(documentId: string): string {
Expand Down Expand Up @@ -250,6 +253,7 @@ export async function createGitService(createArgs: createGitServiceArgs): Promis
isEphemeralContainer,
ephemeralDocumentTTLSec,
denyList,
simplifiedCustomDataRetriever,
} = createArgs;
const token = parseToken(tenantId, authorization);
const decoded = decode(token) as ITokenClaims;
Expand All @@ -263,6 +267,7 @@ export async function createGitService(createArgs: createGitServiceArgs): Promis
}
const details = await tenantService.getTenant(tenantId, token, allowDisabledTenant);
const customData: ITenantCustomDataExternal = details.customData;
const simplifiedCustomData = simplifiedCustomDataRetriever?.get(customData);
Copy link
Contributor Author

@zhajie zhajie Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At runtime, retrieve simplified CustomData here with customized FRS implementation here.

const writeToExternalStorage = !!customData?.externalStorageData;
const storageUrl = config.get("storageUrl") as string | undefined;
const ignoreEphemeralFlag: boolean = config.get("ignoreEphemeralFlag");
Expand Down Expand Up @@ -297,6 +302,7 @@ export async function createGitService(createArgs: createGitServiceArgs): Promis
storageUrl,
isEphemeral,
maxCacheableSummarySize,
simplifiedCustomData,
);
return service;
}
Expand Down
3 changes: 3 additions & 0 deletions server/historian/packages/historian-base/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
IRunner,
IRevokedTokenChecker,
IStorageNameRetriever,
ISimplifiedCustomDataRetriever,
IDocumentManager,
IReadinessCheck,
} from "@fluidframework/server-services-core";
Expand Down Expand Up @@ -39,6 +40,7 @@ export class HistorianRunner implements IRunner {
private readonly denyList?: IDenyList,
private readonly ephemeralDocumentTTLSec?: number,
private readonly readinessCheck?: IReadinessCheck,
private readonly simplifiedCustomDataRetriever?: ISimplifiedCustomDataRetriever,
) {}

// eslint-disable-next-line @typescript-eslint/promise-function-async
Expand All @@ -58,6 +60,7 @@ export class HistorianRunner implements IRunner {
this.denyList,
this.ephemeralDocumentTTLSec,
this.readinessCheck,
this.simplifiedCustomDataRetriever,
);
historian.set("port", this.port);

Expand Down
3 changes: 3 additions & 0 deletions server/historian/packages/historian-base/src/runnerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class HistorianResources implements core.IResources {
public readonly denyList?: historianServices.IDenyList,
public readonly ephemeralDocumentTTLSec?: number,
public readonly readinessCheck?: core.IReadinessCheck,
public readonly simplifiedCustomDataRetriever?: core.ISimplifiedCustomDataRetriever,
) {
const httpServerConfig: services.IHttpServerConfig = config.get("system:httpServer");
this.webServerFactory = new services.BasicWebServerFactory(httpServerConfig);
Expand Down Expand Up @@ -226,6 +227,7 @@ export class HistorianResourcesFactory implements core.IResourcesFactory<Histori
denyList,
ephemeralDocumentTTLSec,
customizations?.readinessCheck,
customizations?.simplifiedCustomDataRetriever,
);
}
}
Expand All @@ -247,6 +249,7 @@ export class HistorianRunnerFactory implements core.IRunnerFactory<HistorianReso
resources.denyList,
resources.ephemeralDocumentTTLSec,
resources.readinessCheck,
resources.simplifiedCustomDataRetriever,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class RestGitService {
private readonly storageUrl?: string,
private readonly isEphemeralContainer?: boolean,
private readonly maxCacheableSummarySize?: number,
private readonly simplifiedCustomData?: string,
) {
const defaultHeaders: RawAxiosRequestHeaders =
storageName !== undefined
Expand All @@ -83,6 +84,9 @@ export class RestGitService {
);
defaultHeaders.Authorization = `Basic ${token.toString("base64")}`;
}
if (this.simplifiedCustomData) {
defaultHeaders[Constants.simplifiedCustomData] = this.simplifiedCustomData;
}

// We set the flag only for ephemeral containers
if (this.isEphemeralContainer) {
Expand Down
1 change: 1 addition & 0 deletions server/historian/packages/historian-base/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const Constants = Object.freeze({
generalRestCallThrottleIdPrefix: "generalRestCall",
IsEphemeralContainer: "Is-Ephemeral-Container",
isInitialSummary: "isInitialSummary",
simplifiedCustomData: "simplifiedCustomData",
});

export function getTokenLifetimeInSec(token: string): number {
Expand Down
1 change: 1 addition & 0 deletions server/routerlicious/packages/services-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export {
ICollaborationSessionManager,
ICollaborationSessionTracker,
} from "./collabSession";
export { ISimplifiedCustomDataRetriever } from "./simplifiedCustomDataRetriever";
export { IStorageNameAllocator } from "./storageNameAllocator";
export { IStorageNameRetriever } from "./storageNameRetriever";
export {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

import type { ITenantCustomData } from "./tenant";

/**
* @internal
*/
export interface ISimplifiedCustomDataRetriever {
get(customData: ITenantCustomData): string;
}
1 change: 1 addition & 0 deletions server/routerlicious/packages/services/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { RedisThrottleAndUsageStorageManager } from "./redisThrottleAndUsageStor
export { SecretManager } from "./secretManager";
export { CollaborationSessionTracker } from "./sessionTracker";
export { SocketIoRedisPublisher, SocketIoRedisTopic } from "./socketIoRedisPublisher";
export { SimplifiedCustomDataRetriever } from "./simplifiedCustomDataRetriever";
export { StorageNameRetriever } from "./storageNameRetriever";
export { Tenant, TenantManager } from "./tenant";
export { Throttler } from "./throttler";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

import {
ISimplifiedCustomDataRetriever,
ITenantCustomData,
} from "@fluidframework/server-services-core";

/**
* Retrieve simplified customData.
* @internal
*/
export class SimplifiedCustomDataRetriever implements ISimplifiedCustomDataRetriever {
public constructor() {}

public get(customData: ITenantCustomData): string {
return undefined;
}
}
Loading