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

Draft: Introducing configuration #8496

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
95f333d
initial config provider
anthony-murphy Nov 8, 2021
3c0238c
initial config provider
anthony-murphy Nov 8, 2021
a744c44
Merge branch 'config-provider' of https://github.com/anthony-murphy/F…
anthony-murphy Nov 8, 2021
35df44a
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
anthony-murphy Nov 8, 2021
80baf21
alpha
anthony-murphy Nov 9, 2021
0cbebb1
mixin with child logger
anthony-murphy Nov 9, 2021
d31bc25
add debug logging
anthony-murphy Nov 9, 2021
1346d85
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
anthony-murphy Nov 24, 2021
072350e
improve typing
anthony-murphy Nov 24, 2021
4e901a8
checkpoint
andre4i Dec 1, 2021
ee39887
Add some tests
andre4i Dec 1, 2021
5905c48
Add more tests
andre4i Dec 1, 2021
4d9e79b
Override with breakglass
andre4i Dec 2, 2021
6780154
Fix all instances of old API
andre4i Dec 2, 2021
feaf781
Fix another usage of old API
andre4i Dec 2, 2021
902f092
sessionStorage may not be defined
andre4i Dec 2, 2021
2a246eb
Merge branch 'main' into config-provider
andre4i Dec 2, 2021
f2c16fb
Fix sessionstorage vs storage ref
andre4i Dec 2, 2021
cbe2925
Fix undefined sessionstorage
andre4i Dec 2, 2021
48e6e19
moving some stuff around
andre4i Dec 2, 2021
b9d9fb1
SettingsProvider bridge
andre4i Dec 2, 2021
05fd94c
Some comments here and there
andre4i Dec 3, 2021
d8f4c41
Merge branch 'main' into config-provider
andre4i Dec 7, 2021
217b15a
Fix region name
andre4i Dec 7, 2021
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
2 changes: 2 additions & 0 deletions api-report/container-loader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IAudience } from '@fluidframework/container-definitions';
import { IClientConfiguration } from '@fluidframework/protocol-definitions';
import { IClientDetails } from '@fluidframework/protocol-definitions';
import { ICodeLoader } from '@fluidframework/container-definitions';
import { IConfigProviderBase } from '@fluidframework/telemetry-utils';
import { IContainer } from '@fluidframework/container-definitions';
import { IContainerEvents } from '@fluidframework/container-definitions';
import { IContainerLoadMode } from '@fluidframework/container-definitions';
Expand Down Expand Up @@ -163,6 +164,7 @@ export interface ILoaderOptions extends ILoaderOptions_2 {
// @public
export interface ILoaderProps {
readonly codeLoader: ICodeDetailsLoader | ICodeLoader;
readonly configProvider?: IConfigProviderBase;
readonly detachedBlobStorage?: IDetachedBlobStorage;
readonly documentServiceFactory: IDocumentServiceFactory;
readonly logger?: ITelemetryBaseLogger;
Expand Down
3 changes: 2 additions & 1 deletion api-report/driver-base.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ISignalClient } from '@fluidframework/protocol-definitions';
import { ISignalMessage } from '@fluidframework/protocol-definitions';
import { ITelemetryLogger } from '@fluidframework/common-definitions';
import { ITokenClaims } from '@fluidframework/protocol-definitions';
import { TelemetryLoggerWithConfig } from '@fluidframework/telemetry-utils';
import { TypedEventEmitter } from '@fluidframework/common-utils';

// @public
Expand Down Expand Up @@ -62,7 +63,7 @@ export class DocumentDeltaConnection extends TypedEventEmitter<IDocumentDeltaCon
// (undocumented)
protected readonly isBatchManagerDisabled: boolean;
// (undocumented)
protected readonly logger: ITelemetryLogger;
protected readonly logger: TelemetryLoggerWithConfig;
get maxMessageSize(): number;
get mode(): ConnectionMode;
// (undocumented)
Expand Down
63 changes: 63 additions & 0 deletions api-report/telemetry-utils.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ITelemetryGenericEvent } from '@fluidframework/common-definitions';
import { ITelemetryLogger } from '@fluidframework/common-definitions';
import { ITelemetryPerformanceEvent } from '@fluidframework/common-definitions';
import { ITelemetryProperties } from '@fluidframework/common-definitions';
import { Lazy } from '@fluidframework/common-utils';
import { TelemetryEventCategory } from '@fluidframework/common-definitions';
import { TelemetryEventPropertyType } from '@fluidframework/common-definitions';
import { TypedEventEmitter } from '@fluidframework/common-utils';
Expand All @@ -29,6 +30,29 @@ export class ChildLogger extends TelemetryLogger {
send(event: ITelemetryBaseEvent): void;
}

// @public
export class ConfigProvider implements IConfigProvider {
// (undocumented)
static create(namespace: string | undefined, orderedBaseProviders: (IConfigProviderBase | ITelemetryBaseLogger | undefined)[]): IConfigProvider;
// (undocumented)
getBoolean(name: string, defaultValue?: boolean): boolean | undefined;
// (undocumented)
getBooleanArray(name: string, defaultValue?: boolean[]): boolean[] | undefined;
// (undocumented)
getNumber(name: string, defaultValue?: number): number | undefined;
// (undocumented)
getNumberArray(name: string, defaultValue?: number[]): number[] | undefined;
// (undocumented)
getRawConfig(name: string): ConfigTypes;
// (undocumented)
getString(name: string, defaultValue?: string): string | undefined;
// (undocumented)
getStringArray(name: string, defaultValue?: string[]): string[] | undefined;
}

// @public (undocumented)
export type ConfigTypes = string | number | boolean | number[] | string[] | boolean[] | undefined;

// @public (undocumented)
export const connectedEventName = "connected";

Expand Down Expand Up @@ -68,6 +92,28 @@ export const hasErrorInstanceId: (x: any) => x is {
errorInstanceId: string;
};

// @public
export interface IConfigProvider extends IConfigProviderBase {
// (undocumented)
getBoolean(name: string, defaultValue?: boolean): boolean | undefined;
// (undocumented)
getBooleanArray(name: string, defaultValue?: boolean[]): boolean[] | undefined;
// (undocumented)
getNumber(name: string, defaultValue?: number): number | undefined;
// (undocumented)
getNumberArray(name: string, defaultValue?: number[]): number[] | undefined;
// (undocumented)
getString(name: string, defaultValue?: string): string | undefined;
// (undocumented)
getStringArray(name: string, defaultValue?: string[]): string[] | undefined;
}

// @public
export interface IConfigProviderBase {
// (undocumented)
getRawConfig(name: string): ConfigTypes;
}

// @public
export interface IFluidErrorAnnotations {
props?: ITelemetryProperties;
Expand All @@ -85,6 +131,9 @@ export interface IFluidErrorBase extends Error {
readonly stack?: string;
}

// @public
export const inMemoryConfigProvider: (storage?: Storage | undefined, namespaceOverride?: string | undefined) => Lazy<IConfigProviderBase | undefined>;

// @public
export interface IPerformanceEventMarkers {
// (undocumented)
Expand Down Expand Up @@ -133,6 +182,12 @@ export class LoggingError extends Error implements ILoggingError, Pick<IFluidErr
// @public
export function logIfFalse(condition: any, logger: ITelemetryBaseLogger, event: string | ITelemetryGenericEvent): condition is true;

// @public
export function mixinChildLoggerWithConfigProvider(logger: ITelemetryBaseLogger, namespace?: string, properties?: ITelemetryLoggerPropertyBags): TelemetryLoggerWithConfig;

// @public
export function mixinConfigProvider<T extends ITelemetryBaseLogger>(logger: T, config: IConfigProvider): TelemetryLoggerWithConfig<T>;

// @public
export class MockLogger extends TelemetryLogger implements ITelemetryLogger {
constructor();
Expand Down Expand Up @@ -182,6 +237,9 @@ export function raiseConnectedEvent(logger: ITelemetryLogger, emitter: EventEmit
// @public (undocumented)
export function safeRaiseEvent(emitter: EventEmitter, logger: ITelemetryLogger, event: string, ...args: any[]): void;

// @public
export const sessionStorageConfigProvider: (namespaceOverride?: string | undefined) => Lazy<IConfigProviderBase | undefined>;

// @public
export class TaggedLoggerAdapter implements ITelemetryBaseLogger {
constructor(logger: ITelemetryBaseLogger);
Expand Down Expand Up @@ -224,6 +282,11 @@ export abstract class TelemetryLogger implements ITelemetryLogger {
}, error?: any): void;
}

// @public
export type TelemetryLoggerWithConfig<T extends ITelemetryBaseLogger = ITelemetryLogger> = T & {
readonly config: IConfigProvider;
};

// @public
export class TelemetryUTLogger implements ITelemetryLogger {
// (undocumented)
Expand Down
20 changes: 7 additions & 13 deletions packages/drivers/driver-base/src/documentDeltaConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
ScopeType,
} from "@fluidframework/protocol-definitions";
import { IDisposable, ITelemetryLogger } from "@fluidframework/common-definitions";
import { ChildLogger } from "@fluidframework/telemetry-utils";
import {
TelemetryLoggerWithConfig,
mixinChildLoggerWithConfigProvider,
} from "@fluidframework/telemetry-utils";

// Local storage key to disable the BatchManager
const batchManagerDisabledKey = "FluidDisableBatchManager";
Expand Down Expand Up @@ -103,7 +106,7 @@ export class DocumentDeltaConnection
* After disconnection, we flip this to prevent any stale messages from being emitted.
*/
protected _disposed: boolean = false;
protected readonly logger: ITelemetryLogger;
protected readonly logger: TelemetryLoggerWithConfig;
protected readonly isBatchManagerDisabled: boolean = false;

public get details(): IConnected {
Expand All @@ -124,7 +127,7 @@ export class DocumentDeltaConnection
) {
super();

this.logger = ChildLogger.create(logger, "DeltaConnection");
this.logger = mixinChildLoggerWithConfigProvider(logger, "DeltaConnection");

this.submitManager = new BatchManager<IDocumentMessage[]>(
(submitType, work) => this.emitMessages(submitType, work));
Expand Down Expand Up @@ -157,7 +160,7 @@ export class DocumentDeltaConnection
}
});

this.isBatchManagerDisabled = DocumentDeltaConnection.disabledBatchManagerFeatureGate;
this.isBatchManagerDisabled = this.logger.config.getBoolean(batchManagerDisabledKey, false) === true;
}

/**
Expand Down Expand Up @@ -288,15 +291,6 @@ export class DocumentDeltaConnection
}
}

private static get disabledBatchManagerFeatureGate() {
try {
return localStorage !== undefined
&& typeof localStorage === "object"
&& localStorage.getItem(batchManagerDisabledKey) === "1";
} catch (e) { }
return false;
}

protected submitCore(type: string, messages: IDocumentMessage[]) {
if (this.isBatchManagerDisabled) {
this.emitMessages(type, [messages]);
Expand Down
22 changes: 8 additions & 14 deletions packages/drivers/odsp-driver/src/odspDocumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

import { ITelemetryLogger } from "@fluidframework/common-definitions";
import { performance } from "@fluidframework/common-utils";
import { ChildLogger, TelemetryLogger } from "@fluidframework/telemetry-utils";
import {
TelemetryLoggerWithConfig,
mixinChildLoggerWithConfigProvider,
} from "@fluidframework/telemetry-utils";
import {
IDocumentDeltaConnection,
IDocumentDeltaStorageService,
Expand Down Expand Up @@ -40,16 +43,6 @@ import { OpsCache } from "./opsCaching";
import { RetryErrorsStorageAdapter } from "./retryErrorsStorageAdapter";

// Gate that when set to "1", instructs to fetch the binary format snapshot from the spo.
function gatesBinaryFormatSnapshot() {
try {
if (typeof localStorage === "object" && localStorage !== null) {
if (localStorage.binaryFormatSnapshot === "1") {
return true;
}
}
} catch (e) {}
return false;
}

/**
* The DocumentService manages the Socket.IO connection and manages routing requests to connected
Expand Down Expand Up @@ -98,7 +91,7 @@ export class OdspDocumentService implements IDocumentService {

private storageManager?: OdspDocumentStorageService;

private readonly logger: TelemetryLogger;
private readonly logger: TelemetryLoggerWithConfig;

private readonly joinSessionKey: string;

Expand Down Expand Up @@ -139,7 +132,8 @@ export class OdspDocumentService implements IDocumentService {
};

this.joinSessionKey = `${this.odspResolvedUrl.hashedDocumentId}/joinsession`;
this.logger = ChildLogger.create(logger,
this.logger = mixinChildLoggerWithConfigProvider(
logger,
undefined,
{
all: {
Expand All @@ -148,7 +142,7 @@ export class OdspDocumentService implements IDocumentService {
});

this.hostPolicy = hostPolicy;
this.hostPolicy.fetchBinarySnapshotFormat ??= gatesBinaryFormatSnapshot();
this.hostPolicy.fetchBinarySnapshotFormat ??= this.logger.config.getBoolean("binaryFormatSnapshot");
if (this.odspResolvedUrl.summarizer) {
this.hostPolicy = { ...this.hostPolicy, summarizerClient: true };
}
Expand Down
31 changes: 10 additions & 21 deletions packages/drivers/odsp-driver/src/odspSummaryUploadManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
* Licensed under the MIT License.
*/

import { ITelemetryLogger } from "@fluidframework/common-definitions";
import { assert, Uint8ArrayToString, unreachableCase } from "@fluidframework/common-utils";
import { ISummaryContext } from "@fluidframework/driver-definitions";
import { getGitType } from "@fluidframework/protocol-base";
import * as api from "@fluidframework/protocol-definitions";
import { InstrumentedStorageTokenFetcher } from "@fluidframework/odsp-driver-definitions";
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
import {
TelemetryLoggerWithConfig,
mixinChildLoggerWithConfigProvider,
PerformanceEvent,
} from "@fluidframework/telemetry-utils";
import { ITelemetryLogger } from "@fluidframework/common-definitions";
import {
IOdspSummaryPayload,
IWriteSummaryResponse,
Expand All @@ -24,37 +28,22 @@ import { getWithRetryForTokenRefresh } from "./odspUtils";

/* eslint-disable max-len */

// Gate that when flipped, instructs to mark unreferenced nodes as such in the summary sent to SPO.
function gatesMarkUnreferencedNodes() {
try {
// Leave override for testing purposes
if (typeof localStorage === "object" && localStorage !== null) {
if (localStorage.FluidMarkUnreferencedNodes === "1") {
return true;
}
if (localStorage.FluidMarkUnreferencedNodes === "0") {
return false;
}
}
} catch (e) {}

return true;
}

/**
* This class manages a summary upload. When it receives a call to upload summary, it converts the summary tree into
* a snapshot tree and then uploads that to the server.
*/
export class OdspSummaryUploadManager {
// Last proposed handle of the uploaded app summary.
private lastSummaryProposalHandle: string | undefined;
private readonly logger: TelemetryLoggerWithConfig;

constructor(
private readonly snapshotUrl: string,
private readonly getStorageToken: InstrumentedStorageTokenFetcher,
private readonly logger: ITelemetryLogger,
logger: ITelemetryLogger,
private readonly epochTracker: EpochTracker,
) {
this.logger = mixinChildLoggerWithConfigProvider(logger);
}

public async writeSummaryTree(tree: api.ISummaryTree, context: ISummaryContext) {
Expand Down Expand Up @@ -145,7 +134,7 @@ export class OdspSummaryUploadManager {
tree: api.ISummaryTree,
rootNodeName: string,
path: string = "",
markUnreferencedNodes: boolean = gatesMarkUnreferencedNodes(),
markUnreferencedNodes: boolean = this.logger.config.getBoolean("FluidMarkUnreferencedNodes") ?? true,
) {
const snapshotTree: IOdspSummaryTree = {
type: "tree",
Expand Down
Loading