diff --git a/server/charts/historian/templates/historian-configmap.yaml b/server/charts/historian/templates/historian-configmap.yaml index b771e50e130f..efd1c5632ea4 100644 --- a/server/charts/historian/templates/historian-configmap.yaml +++ b/server/charts/historian/templates/historian-configmap.yaml @@ -44,5 +44,6 @@ data: }, "restGitService": { "disableGitCache": {{ .Values.historian.restGitService.disableGitCache }} - } + }, + "storageUrl": "{{ .Values.historian.storageUrl }}" } diff --git a/server/charts/historian/values.yaml b/server/charts/historian/values.yaml index 38da3bb17606..c8f018a8d7fd 100644 --- a/server/charts/historian/values.yaml +++ b/server/charts/historian/values.yaml @@ -17,6 +17,7 @@ historian: cert: historian_cert ingressClass: ingress_class riddler: riddler_url + storageUrl: historian_storage_url error: track: true endpoint: "error_tracking_endpoint" diff --git a/server/historian/packages/historian-base/src/routes/git/blobs.ts b/server/historian/packages/historian-base/src/routes/git/blobs.ts index 9ea0c73d3c4b..83dcaeebe665 100644 --- a/server/historian/packages/historian-base/src/routes/git/blobs.ts +++ b/server/historian/packages/historian-base/src/routes/git/blobs.ts @@ -30,7 +30,13 @@ export function create( tenantId: string, authorization: string, body: git.ICreateBlobParams): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.createBlob(body); } @@ -39,7 +45,13 @@ export function create( authorization: string, sha: string, useCache: boolean): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getBlob(sha, useCache); } @@ -63,7 +75,7 @@ export function create( response, false, 201); - }); + }); /** * Retrieves the given blob from the repository @@ -78,7 +90,7 @@ export function create( blobP, response, useCache); - }); + }); /** * Retrieves the given blob as an image @@ -97,10 +109,10 @@ export function create( } response.status(200).write(Buffer.from(blob.content, "base64"), () => response.end()); }, - (error) => { - response.status(error?.code ?? 400).json(error?.message ?? error); - }); - }); + (error) => { + response.status(error?.code ?? 400).json(error?.message ?? error); + }); + }); return router; } diff --git a/server/historian/packages/historian-base/src/routes/git/commits.ts b/server/historian/packages/historian-base/src/routes/git/commits.ts index a5c925af9bb0..ef54cc78b506 100644 --- a/server/historian/packages/historian-base/src/routes/git/commits.ts +++ b/server/historian/packages/historian-base/src/routes/git/commits.ts @@ -30,7 +30,13 @@ export function create( tenantId: string, authorization: string, params: ICreateCommitParams): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.createCommit(params); } @@ -39,7 +45,13 @@ export function create( authorization: string, sha: string, useCache: boolean): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getCommit(sha, useCache); } diff --git a/server/historian/packages/historian-base/src/routes/git/refs.ts b/server/historian/packages/historian-base/src/routes/git/refs.ts index e99e1b00ad33..f6a0c9454e68 100644 --- a/server/historian/packages/historian-base/src/routes/git/refs.ts +++ b/server/historian/packages/historian-base/src/routes/git/refs.ts @@ -28,12 +28,24 @@ export function create( }; async function getRefs(tenantId: string, authorization: string): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getRefs(); } async function getRef(tenantId: string, authorization: string, ref: string): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getRef(ref); } @@ -41,7 +53,13 @@ export function create( tenantId: string, authorization: string, params: ICreateRefParamsExternal): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.createRef(params); } @@ -50,7 +68,13 @@ export function create( authorization: string, ref: string, params: IPatchRefParamsExternal): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.updateRef(ref, params); } @@ -58,7 +82,13 @@ export function create( tenantId: string, authorization: string, ref: string): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.deleteRef(ref); } diff --git a/server/historian/packages/historian-base/src/routes/git/tags.ts b/server/historian/packages/historian-base/src/routes/git/tags.ts index 17c2f4716f24..2d05d5262279 100644 --- a/server/historian/packages/historian-base/src/routes/git/tags.ts +++ b/server/historian/packages/historian-base/src/routes/git/tags.ts @@ -30,12 +30,24 @@ export function create( tenantId: string, authorization: string, params: git.ICreateTagParams): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.createTag(params); } async function getTag(tenantId: string, authorization: string, tag: string): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getTag(tag); } diff --git a/server/historian/packages/historian-base/src/routes/git/trees.ts b/server/historian/packages/historian-base/src/routes/git/trees.ts index 7bf2de24ae48..1e604d203baa 100644 --- a/server/historian/packages/historian-base/src/routes/git/trees.ts +++ b/server/historian/packages/historian-base/src/routes/git/trees.ts @@ -30,7 +30,13 @@ export function create( tenantId: string, authorization: string, params: git.ICreateTreeParams): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.createTree(params); } @@ -40,7 +46,13 @@ export function create( sha: string, recursive: boolean, useCache: boolean): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getTree(sha, recursive, useCache); } diff --git a/server/historian/packages/historian-base/src/routes/repository/commits.ts b/server/historian/packages/historian-base/src/routes/repository/commits.ts index cc147d4745f3..38ec312ad81d 100644 --- a/server/historian/packages/historian-base/src/routes/repository/commits.ts +++ b/server/historian/packages/historian-base/src/routes/repository/commits.ts @@ -31,7 +31,13 @@ export function create( authorization: string, sha: string, count: number): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getCommits(sha, count); } diff --git a/server/historian/packages/historian-base/src/routes/repository/contents.ts b/server/historian/packages/historian-base/src/routes/repository/contents.ts index d550c621ef50..fdcbf11c8dc9 100644 --- a/server/historian/packages/historian-base/src/routes/repository/contents.ts +++ b/server/historian/packages/historian-base/src/routes/repository/contents.ts @@ -30,7 +30,13 @@ export function create( authorization: string, path: string, ref: string): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getContent(path, ref); } diff --git a/server/historian/packages/historian-base/src/routes/repository/headers.ts b/server/historian/packages/historian-base/src/routes/repository/headers.ts index 45f34b25654f..91e54f2134c2 100644 --- a/server/historian/packages/historian-base/src/routes/repository/headers.ts +++ b/server/historian/packages/historian-base/src/routes/repository/headers.ts @@ -31,7 +31,13 @@ export function create( authorization: string, sha: string, useCache: boolean): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getHeader(sha, useCache); } @@ -40,7 +46,13 @@ export function create( authorization: string, sha: string, useCache: boolean): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getFullTree(sha, useCache); } diff --git a/server/historian/packages/historian-base/src/routes/summaries.ts b/server/historian/packages/historian-base/src/routes/summaries.ts index 1b4926e59844..73256981331d 100644 --- a/server/historian/packages/historian-base/src/routes/summaries.ts +++ b/server/historian/packages/historian-base/src/routes/summaries.ts @@ -4,7 +4,7 @@ */ import { AsyncLocalStorage } from "async_hooks"; -import { IWholeFlatSummary, IWholeSummaryPayload, IWriteSummaryResponse} from "@fluidframework/server-services-client"; +import { IWholeFlatSummary, IWholeSummaryPayload, IWriteSummaryResponse } from "@fluidframework/server-services-client"; import { IThrottler } from "@fluidframework/server-services-core"; import { IThrottleMiddlewareOptions, throttle, getParam } from "@fluidframework/server-services-utils"; import { Router } from "express"; @@ -32,7 +32,13 @@ export function create( authorization: string, sha: string, useCache: boolean): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.getSummary(sha, useCache); } @@ -40,7 +46,13 @@ export function create( tenantId: string, authorization: string, params: IWholeSummaryPayload): Promise { - const service = await utils.createGitService(tenantId, authorization, tenantService, cache, asyncLocalStorage); + const service = await utils.createGitService( + config, + tenantId, + authorization, + tenantService, + cache, + asyncLocalStorage); return service.createSummary(params); } @@ -49,6 +61,7 @@ export function create( authorization: string, softDelete: boolean): Promise { const service = await utils.createGitService( + config, tenantId, authorization, tenantService, @@ -74,7 +87,7 @@ export function create( response, // Browser caching for summary data should be disabled for now. false); - }); + }); router.post("/repos/:ignored?/:tenantId/git/summaries", throttle(throttler, winston, commonThrottleOptions), @@ -87,7 +100,7 @@ export function create( false, undefined, 201); - }); + }); router.delete("/repos/:ignored?/:tenantId/git/summaries", throttle(throttler, winston, commonThrottleOptions), @@ -102,7 +115,7 @@ export function create( summaryP, response, false); - }); + }); return router; } diff --git a/server/historian/packages/historian-base/src/routes/utils.ts b/server/historian/packages/historian-base/src/routes/utils.ts index 20121ebe9002..f324e03fa322 100644 --- a/server/historian/packages/historian-base/src/routes/utils.ts +++ b/server/historian/packages/historian-base/src/routes/utils.ts @@ -6,6 +6,7 @@ import { AsyncLocalStorage } from "async_hooks"; import { RequestHandler, Response } from "express"; import * as jwt from "jsonwebtoken"; +import * as nconf from "nconf"; import { ITokenClaims } from "@fluidframework/protocol-definitions"; import { NetworkError } from "@fluidframework/server-services-client"; import { ICache, ITenantService, RestGitService, ITenantCustomDataExternal } from "../services"; @@ -53,6 +54,7 @@ import { containsPathTraversal, parseToken } from "../utils"; } export async function createGitService( + config: nconf.Provider, tenantId: string, authorization: string, tenantService: ITenantService, @@ -66,19 +68,20 @@ export async function createGitService( const writeToExternalStorage = !!customData?.externalStorageData; const storageName = customData?.storageName; const decoded = jwt.decode(token) as ITokenClaims; + const storageUrl = config.get("storageUrl") as string | undefined; if (containsPathTraversal(decoded.documentId)) { // Prevent attempted directory traversal. throw new NetworkError(400, `Invalid document id: ${decoded.documentId}`); } - const service = new RestGitService( - details.storage, - writeToExternalStorage, - tenantId, - decoded.documentId, - cache, - asyncLocalStorage, - storageName); - + const service = new RestGitService( + details.storage, + writeToExternalStorage, + tenantId, + decoded.documentId, + cache, + asyncLocalStorage, + storageName, + storageUrl); return service; } diff --git a/server/historian/packages/historian-base/src/services/restGitService.ts b/server/historian/packages/historian-base/src/services/restGitService.ts index fe93db1eed4c..c0f41f3abcaf 100644 --- a/server/historian/packages/historian-base/src/services/restGitService.ts +++ b/server/historian/packages/historian-base/src/services/restGitService.ts @@ -58,7 +58,8 @@ export class RestGitService { private readonly documentId: string, private readonly cache?: ICache, private readonly asyncLocalStorage?: AsyncLocalStorage, - private readonly storageName?: string) { + private readonly storageName?: string, + private readonly storageUrl?: string) { let defaultHeaders: AxiosRequestHeaders; if (storageName !== undefined) { defaultHeaders = { @@ -81,9 +82,11 @@ export class RestGitService { [BaseTelemetryProperties.documentId]: this.documentId, }; + const baseUrl = this.storageUrl || storage.url; + winston.info( `Created RestGitService: ${JSON.stringify({ - "BaseUrl": storage.url, + "BaseUrl": baseUrl, "Storage-Routing-Id": this.getStorageRoutingHeaderValue(), "Storage-Name": this.storageName, })}`, @@ -91,7 +94,7 @@ export class RestGitService { Lumberjack.info( `Created RestGitService: ${JSON.stringify({ - "BaseUrl": storage.url, + "BaseUrl": baseUrl, "Storage-Routing-Id": this.getStorageRoutingHeaderValue(), "Storage-Name": this.storageName, })}`, @@ -99,7 +102,7 @@ export class RestGitService { ); this.restWrapper = new BasicRestWrapper( - storage.url, + baseUrl, undefined, undefined, undefined, diff --git a/server/historian/packages/historian/config.json b/server/historian/packages/historian/config.json index a4ee899b8746..b48642e91086 100644 --- a/server/historian/packages/historian/config.json +++ b/server/historian/packages/historian/config.json @@ -28,5 +28,6 @@ }, "restGitService": { "disableGitCache": false - } + }, + "storageUrl": "" } diff --git a/server/routerlicious/kubernetes/routerlicious/templates/fluid-configmap.yaml b/server/routerlicious/kubernetes/routerlicious/templates/fluid-configmap.yaml index 8f68df317fe7..a74b08398e09 100644 --- a/server/routerlicious/kubernetes/routerlicious/templates/fluid-configmap.yaml +++ b/server/routerlicious/kubernetes/routerlicious/templates/fluid-configmap.yaml @@ -58,7 +58,8 @@ data: "endpoint": "{{ .Values.zookeeper.url }}" }, "storage": { - "enableWholeSummaryUpload": {{ .Values.storage.enableWholeSummaryUpload }} + "enableWholeSummaryUpload": {{ .Values.storage.enableWholeSummaryUpload }}, + "storageUrl": "{{ .Values.storage.storageUrl }}", }, "alfred": { "kafkaClientId": "{{ template "alfred.fullname" . }}", diff --git a/server/routerlicious/kubernetes/routerlicious/values.yaml b/server/routerlicious/kubernetes/routerlicious/values.yaml index f1d70b003c3d..26b3082bffba 100644 --- a/server/routerlicious/kubernetes/routerlicious/values.yaml +++ b/server/routerlicious/kubernetes/routerlicious/values.yaml @@ -38,6 +38,8 @@ alfred: enforceServerGeneratedDocumentId: false storage: enableWholeSummaryUpload: false + storageUrl: storage_url + deli: name: deli replicas: 8 diff --git a/server/routerlicious/packages/routerlicious-base/src/alfred/runnerFactory.ts b/server/routerlicious/packages/routerlicious-base/src/alfred/runnerFactory.ts index 0c79102559c0..b86117f82139 100644 --- a/server/routerlicious/packages/routerlicious-base/src/alfred/runnerFactory.ts +++ b/server/routerlicious/packages/routerlicious-base/src/alfred/runnerFactory.ts @@ -209,7 +209,8 @@ export class AlfredResourcesFactory implements core.IResourcesFactory { const authEndpoint = config.get("auth:endpoint"); - const tenantManager = new services.TenantManager(authEndpoint); + const internalHistorianUrl = config.get("worker:internalBlobStorageUrl"); + const tenantManager = new services.TenantManager(authEndpoint, internalHistorianUrl); const foremanConfig = config.get("foreman"); const messageSender = services.createMessageSender(config.get("rabbitmq"), foremanConfig); diff --git a/server/routerlicious/packages/routerlicious/src/scribe/index.ts b/server/routerlicious/packages/routerlicious/src/scribe/index.ts index c266741670c7..9d29417ce149 100644 --- a/server/routerlicious/packages/routerlicious/src/scribe/index.ts +++ b/server/routerlicious/packages/routerlicious/src/scribe/index.ts @@ -35,10 +35,11 @@ export async function scribeCreate(config: Provider): Promise { @@ -71,7 +71,7 @@ export class TenantManager implements core.ITenantManager { }); }; const defaultHeaders = getDefaultHeaders(); - const baseUrl = `${details.storage.internalHistorianUrl}/repos/${encodeURIComponent(tenantId)}`; + const baseUrl = `${this.internalHistorianUrl}/repos/${encodeURIComponent(tenantId)}`; const tenantRestWrapper = new BasicRestWrapper( baseUrl, defaultQueryString, @@ -83,7 +83,7 @@ export class TenantManager implements core.ITenantManager { getDefaultHeaders, getCorrelationId); const historian = new Historian( - `${details.storage.internalHistorianUrl}/repos/${encodeURIComponent(tenantId)}`, + `${this.internalHistorianUrl}/repos/${encodeURIComponent(tenantId)}`, true, false, tenantRestWrapper);