@fluid-experimental/attributor 2.0.0-rc.3.0.3 → 2.0.0-rc.4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/api-report/attributor.api.md +0 -21
- package/dist/attributor.d.ts +3 -5
- package/dist/attributor.d.ts.map +1 -1
- package/dist/attributor.js +7 -9
- package/dist/attributor.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/mixinAttributor.d.ts +1 -0
- package/dist/mixinAttributor.d.ts.map +1 -1
- package/dist/mixinAttributor.js +6 -6
- package/dist/mixinAttributor.js.map +1 -1
- package/lib/attributor.d.ts +3 -5
- package/lib/attributor.d.ts.map +1 -1
- package/lib/attributor.js +7 -9
- package/lib/attributor.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/mixinAttributor.d.ts +1 -0
- package/lib/mixinAttributor.d.ts.map +1 -1
- package/lib/mixinAttributor.js +6 -6
- package/lib/mixinAttributor.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +21 -21
- package/src/attributor.ts +12 -10
- package/src/index.ts +1 -1
- package/src/mixinAttributor.ts +13 -9
package/CHANGELOG.md
CHANGED
|
@@ -7,22 +7,6 @@
|
|
|
7
7
|
import { AttributionInfo } from '@fluidframework/runtime-definitions/internal';
|
|
8
8
|
import { AttributionKey } from '@fluidframework/runtime-definitions/internal';
|
|
9
9
|
import { ContainerRuntime } from '@fluidframework/container-runtime/internal';
|
|
10
|
-
import { IAudience } from '@fluidframework/container-definitions';
|
|
11
|
-
import { IDeltaManager } from '@fluidframework/container-definitions';
|
|
12
|
-
import { IDocumentMessage } from '@fluidframework/protocol-definitions';
|
|
13
|
-
import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
|
|
14
|
-
|
|
15
|
-
// @internal
|
|
16
|
-
export class Attributor implements IAttributor {
|
|
17
|
-
constructor(initialEntries?: Iterable<[number, AttributionInfo]>);
|
|
18
|
-
// (undocumented)
|
|
19
|
-
entries(): IterableIterator<[number, AttributionInfo]>;
|
|
20
|
-
getAttributionInfo(key: number): AttributionInfo;
|
|
21
|
-
// (undocumented)
|
|
22
|
-
protected readonly keyToInfo: Map<number, AttributionInfo>;
|
|
23
|
-
// (undocumented)
|
|
24
|
-
tryGetAttributionInfo(key: number): AttributionInfo | undefined;
|
|
25
|
-
}
|
|
26
10
|
|
|
27
11
|
// @internal
|
|
28
12
|
export function createRuntimeAttributor(): IRuntimeAttributor;
|
|
@@ -61,11 +45,6 @@ export interface IRuntimeAttributor extends IProvideRuntimeAttributor {
|
|
|
61
45
|
// @internal
|
|
62
46
|
export const mixinAttributor: (Base?: typeof ContainerRuntime) => typeof ContainerRuntime;
|
|
63
47
|
|
|
64
|
-
// @internal
|
|
65
|
-
export class OpStreamAttributor extends Attributor implements IAttributor {
|
|
66
|
-
constructor(deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>, audience: IAudience, initialEntries?: Iterable<[number, AttributionInfo]>);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
48
|
// (No @packageDocumentation comment for this package)
|
|
70
49
|
|
|
71
50
|
```
|
package/dist/attributor.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { type
|
|
6
|
-
import { type IDocumentMessage, type ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
5
|
+
import { type IDeltaManager } from "@fluidframework/container-definitions/internal";
|
|
6
|
+
import { type IDocumentMessage, type IQuorumClients, type ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
7
7
|
import { type AttributionInfo } from "@fluidframework/runtime-definitions/internal";
|
|
8
8
|
/**
|
|
9
9
|
* Provides lookup between attribution keys and their associated attribution information.
|
|
@@ -28,7 +28,6 @@ export interface IAttributor {
|
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* {@inheritdoc IAttributor}
|
|
31
|
-
* @internal
|
|
32
31
|
*/
|
|
33
32
|
export declare class Attributor implements IAttributor {
|
|
34
33
|
protected readonly keyToInfo: Map<number, AttributionInfo>;
|
|
@@ -52,9 +51,8 @@ export declare class Attributor implements IAttributor {
|
|
|
52
51
|
/**
|
|
53
52
|
* Attributor which listens to an op stream and records entries for each op.
|
|
54
53
|
* Sequence numbers are used as attribution keys.
|
|
55
|
-
* @internal
|
|
56
54
|
*/
|
|
57
55
|
export declare class OpStreamAttributor extends Attributor implements IAttributor {
|
|
58
|
-
constructor(deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,
|
|
56
|
+
constructor(deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>, quorumClients: IQuorumClients, initialEntries?: Iterable<[number, AttributionInfo]>);
|
|
59
57
|
}
|
|
60
58
|
//# sourceMappingURL=attributor.d.ts.map
|
package/dist/attributor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributor.d.ts","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"attributor.d.ts","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAEpF,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAGpF;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;OAIG;IACH,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;IAEjD;;;OAGG;IACH,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IAEhE;;OAEG;IACH,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CAIvD;AAED;;GAEG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC7C,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAE3D;;OAEG;gBACgB,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAIvE;;OAEG;IACI,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe;IAQvD;;OAEG;IACI,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAItE;;OAEG;IACI,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAG7D;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,UAAW,YAAW,WAAW;gBAEvE,YAAY,EAAE,aAAa,CAAC,yBAAyB,EAAE,gBAAgB,CAAC,EACxE,aAAa,EAAE,cAAc,EAC7B,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAqBrD"}
|
package/dist/attributor.js
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.OpStreamAttributor = exports.Attributor = void 0;
|
|
8
8
|
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
9
|
+
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
9
10
|
const internal_2 = require("@fluidframework/telemetry-utils/internal");
|
|
10
11
|
/**
|
|
11
12
|
* {@inheritdoc IAttributor}
|
|
12
|
-
* @internal
|
|
13
13
|
*/
|
|
14
14
|
class Attributor {
|
|
15
15
|
/**
|
|
@@ -45,19 +45,17 @@ exports.Attributor = Attributor;
|
|
|
45
45
|
/**
|
|
46
46
|
* Attributor which listens to an op stream and records entries for each op.
|
|
47
47
|
* Sequence numbers are used as attribution keys.
|
|
48
|
-
* @internal
|
|
49
48
|
*/
|
|
50
49
|
class OpStreamAttributor extends Attributor {
|
|
51
|
-
constructor(deltaManager,
|
|
50
|
+
constructor(deltaManager, quorumClients, initialEntries) {
|
|
52
51
|
super(initialEntries);
|
|
53
52
|
deltaManager.on("op", (message) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
(0, internal_1.assert)(client !== undefined, 0x4af /* Received message from user not in the audience */);
|
|
53
|
+
if (message.type === protocol_definitions_1.MessageType.Operation) {
|
|
54
|
+
(0, internal_1.assert)(typeof message.clientId === "string", 0x966 /* Client id should be present and should be of type string */);
|
|
55
|
+
const client = quorumClients.getMember(message.clientId);
|
|
56
|
+
(0, internal_1.assert)(client !== undefined, 0x967 /* Received message from user not in the quorumClients */);
|
|
59
57
|
this.keyToInfo.set(message.sequenceNumber, {
|
|
60
|
-
user: client.user,
|
|
58
|
+
user: client.client.user,
|
|
61
59
|
timestamp: message.timestamp,
|
|
62
60
|
});
|
|
63
61
|
}
|
package/dist/attributor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributor.js","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA6D;
|
|
1
|
+
{"version":3,"file":"attributor.js","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA6D;AAC7D,+EAK8C;AAE9C,uEAAsE;AA6BtE;;GAEG;AACH,MAAa,UAAU;IAGtB;;OAEG;IACH,YAAmB,cAAoD;QACtE,IAAI,CAAC,SAAS,GAAG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F,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAzBD,gDAyBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type IDeltaManager } from \"@fluidframework/container-definitions/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tMessageType,\n\ttype IDocumentMessage,\n\ttype IQuorumClients,\n\ttype ISequencedDocumentMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport { type AttributionInfo } from \"@fluidframework/runtime-definitions/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\n/**\n * Provides lookup between attribution keys and their associated attribution information.\n * @internal\n */\nexport interface IAttributor {\n\t/**\n\t * Retrieves attribution information associated with a particular key.\n\t * @param key - Attribution key to look up.\n\t * @throws If no attribution information is recorded for that key.\n\t */\n\tgetAttributionInfo(key: number): AttributionInfo;\n\n\t/**\n\t * @param key - Attribution key to look up.\n\t * @returns the attribution information associated with the provided key, or undefined if no information exists.\n\t */\n\ttryGetAttributionInfo(key: number): AttributionInfo | undefined;\n\n\t/**\n\t * @returns an iterable of (attribution key, attribution info) pairs for each stored key.\n\t */\n\tentries(): IterableIterator<[number, AttributionInfo]>;\n\n\t// TODO:\n\t// - GC\n}\n\n/**\n * {@inheritdoc IAttributor}\n */\nexport class Attributor implements IAttributor {\n\tprotected readonly keyToInfo: Map<number, AttributionInfo>;\n\n\t/**\n\t * @param initialEntries - Any entries which should be populated on instantiation.\n\t */\n\tpublic constructor(initialEntries?: Iterable<[number, AttributionInfo]>) {\n\t\tthis.keyToInfo = new Map(initialEntries ?? []);\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.getAttributionInfo}\n\t */\n\tpublic getAttributionInfo(key: number): AttributionInfo {\n\t\tconst result = this.tryGetAttributionInfo(key);\n\t\tif (!result) {\n\t\t\tthrow new UsageError(`Requested attribution information for unstored key: ${key}.`);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.tryGetAttributionInfo}\n\t */\n\tpublic tryGetAttributionInfo(key: number): AttributionInfo | undefined {\n\t\treturn this.keyToInfo.get(key);\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.entries}\n\t */\n\tpublic entries(): IterableIterator<[number, AttributionInfo]> {\n\t\treturn this.keyToInfo.entries();\n\t}\n}\n\n/**\n * Attributor which listens to an op stream and records entries for each op.\n * Sequence numbers are used as attribution keys.\n */\nexport class OpStreamAttributor extends Attributor implements IAttributor {\n\tpublic constructor(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tquorumClients: IQuorumClients,\n\t\tinitialEntries?: Iterable<[number, AttributionInfo]>,\n\t) {\n\t\tsuper(initialEntries);\n\t\tdeltaManager.on(\"op\", (message: ISequencedDocumentMessage) => {\n\t\t\tif (message.type === MessageType.Operation) {\n\t\t\t\tassert(\n\t\t\t\t\ttypeof message.clientId === \"string\",\n\t\t\t\t\t0x966 /* Client id should be present and should be of type string */,\n\t\t\t\t);\n\t\t\t\tconst client = quorumClients.getMember(message.clientId);\n\t\t\t\tassert(\n\t\t\t\t\tclient !== undefined,\n\t\t\t\t\t0x967 /* Received message from user not in the quorumClients */,\n\t\t\t\t);\n\t\t\t\tthis.keyToInfo.set(message.sequenceNumber, {\n\t\t\t\t\tuser: client.client.user,\n\t\t\t\t\ttimestamp: message.timestamp,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
export {
|
|
5
|
+
export { type IAttributor } from "./attributor.js";
|
|
6
6
|
export { createRuntimeAttributor, enableOnNewFileKey, type IProvideRuntimeAttributor, IRuntimeAttributor, mixinAttributor, } from "./mixinAttributor.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EACN,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,eAAe,GACf,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.mixinAttributor = exports.IRuntimeAttributor = exports.enableOnNewFileKey = exports.createRuntimeAttributor =
|
|
8
|
-
var attributor_js_1 = require("./attributor.js");
|
|
9
|
-
Object.defineProperty(exports, "Attributor", { enumerable: true, get: function () { return attributor_js_1.Attributor; } });
|
|
10
|
-
Object.defineProperty(exports, "OpStreamAttributor", { enumerable: true, get: function () { return attributor_js_1.OpStreamAttributor; } });
|
|
7
|
+
exports.mixinAttributor = exports.IRuntimeAttributor = exports.enableOnNewFileKey = exports.createRuntimeAttributor = void 0;
|
|
11
8
|
var mixinAttributor_js_1 = require("./mixinAttributor.js");
|
|
12
9
|
Object.defineProperty(exports, "createRuntimeAttributor", { enumerable: true, get: function () { return mixinAttributor_js_1.createRuntimeAttributor; } });
|
|
13
10
|
Object.defineProperty(exports, "enableOnNewFileKey", { enumerable: true, get: function () { return mixinAttributor_js_1.enableOnNewFileKey; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2DAM8B;AAL7B,6HAAA,uBAAuB,OAAA;AACvB,wHAAA,kBAAkB,OAAA;AAElB,wHAAA,kBAAkB,OAAA;AAClB,qHAAA,eAAe,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { type IAttributor } from \"./attributor.js\";\nexport {\n\tcreateRuntimeAttributor,\n\tenableOnNewFileKey,\n\ttype IProvideRuntimeAttributor,\n\tIRuntimeAttributor,\n\tmixinAttributor,\n} from \"./mixinAttributor.js\";\n"]}
|
|
@@ -37,6 +37,7 @@ export interface IRuntimeAttributor extends IProvideRuntimeAttributor {
|
|
|
37
37
|
has(key: AttributionKey): boolean;
|
|
38
38
|
/**
|
|
39
39
|
* @returns Whether the runtime is currently tracking attribution information for the loaded container.
|
|
40
|
+
* If enabled, the runtime attributor can be asked for the attribution info for different keys.
|
|
40
41
|
* See {@link mixinAttributor} for more details on when this happens.
|
|
41
42
|
*/
|
|
42
43
|
readonly isEnabled: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAe9E,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,cAAc,EAEnB,MAAM,8CAA8C,CAAC;AAoBtD;;GAEG;AACH,eAAO,MAAM,kBAAkB,sCAAsC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,yBAAgD,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAmB,SAAQ,yBAAyB;IACpE;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,eAAe,CAAC;IAE1C;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC;IAElC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,IAAI,kBAAkB,CAE5D;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,UACrB,uBAAuB,KAC3B,uBAqHqC,CAAC"}
|
package/dist/mixinAttributor.js
CHANGED
|
@@ -55,8 +55,8 @@ const mixinAttributor = (Base = internal_1.ContainerRuntime) => class ContainerR
|
|
|
55
55
|
}
|
|
56
56
|
const pendingRuntimeState = context.pendingLocalState;
|
|
57
57
|
const baseSnapshot = pendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;
|
|
58
|
-
const {
|
|
59
|
-
(0, internal_2.assert)(
|
|
58
|
+
const { quorum, deltaManager, taggedLogger } = context;
|
|
59
|
+
(0, internal_2.assert)(quorum !== undefined, 0x968 /* quorum must exist when instantiating attribution-providing runtime */);
|
|
60
60
|
const mc = (0, internal_4.loggerToMonitoringContext)(taggedLogger);
|
|
61
61
|
const shouldTrackAttribution = mc.config.getBoolean(exports.enableOnNewFileKey) ?? false;
|
|
62
62
|
if (shouldTrackAttribution) {
|
|
@@ -87,7 +87,7 @@ const mixinAttributor = (Base = internal_1.ContainerRuntime) => class ContainerR
|
|
|
87
87
|
await internal_4.PerformanceEvent.timedExecAsync(logger, {
|
|
88
88
|
eventName: "initialize",
|
|
89
89
|
}, async (event) => {
|
|
90
|
-
await runtime.runtimeAttributor?.initialize(deltaManager,
|
|
90
|
+
await runtime.runtimeAttributor?.initialize(deltaManager, quorum, baseSnapshot, async (id) => runtime.storage.readBlob(id), shouldTrackAttribution);
|
|
91
91
|
event.end({
|
|
92
92
|
attributionEnabledInConfig: shouldTrackAttribution,
|
|
93
93
|
attributionEnabledInDoc: runtime.runtimeAttributor
|
|
@@ -141,7 +141,7 @@ class RuntimeAttributor {
|
|
|
141
141
|
}
|
|
142
142
|
return this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;
|
|
143
143
|
}
|
|
144
|
-
async initialize(deltaManager,
|
|
144
|
+
async initialize(deltaManager, quorum, baseSnapshot, readBlob, shouldAddAttributorOnNewFile) {
|
|
145
145
|
const attributorTree = baseSnapshot?.trees[attributorTreeName];
|
|
146
146
|
// Existing documents that don't already have a snapshot containing runtime attribution info shouldn't
|
|
147
147
|
// inject any for now--this causes some back-compat integration problems that aren't fully worked out.
|
|
@@ -153,9 +153,9 @@ class RuntimeAttributor {
|
|
|
153
153
|
return;
|
|
154
154
|
}
|
|
155
155
|
this.isEnabled = true;
|
|
156
|
-
this.encoder = (0, encoders_js_1.chain)(new encoders_js_1.AttributorSerializer((entries) => new attributor_js_1.OpStreamAttributor(deltaManager,
|
|
156
|
+
this.encoder = (0, encoders_js_1.chain)(new encoders_js_1.AttributorSerializer((entries) => new attributor_js_1.OpStreamAttributor(deltaManager, quorum, entries), encoders_js_1.deltaEncoder), (0, lz4Encoder_js_1.makeLZ4Encoder)());
|
|
157
157
|
if (attributorTree === undefined) {
|
|
158
|
-
this.opAttributor = new attributor_js_1.OpStreamAttributor(deltaManager,
|
|
158
|
+
this.opAttributor = new attributor_js_1.OpStreamAttributor(deltaManager, quorum);
|
|
159
159
|
}
|
|
160
160
|
else {
|
|
161
161
|
const id = attributorTree.blobs[opBlobName];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixinAttributor.js","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAG9D,yEAA8E;AA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QAAQ,CAAC,EAAE,CAAC,CAAC;YACxC,MAAM,kBAAkB,GAAG,IAAA,6BAAc,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC;YAChE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;SAC5D;IACF,CAAC;IAEM,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACpB,8EAA8E;YAC9E,OAAO,SAAS,CAAC;SACjB;QAED,IAAA,iBAAM,EACL,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,6BAAkB,EAAE,CAAC;QACzC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;QACpE,OAAO,OAAO,CAAC,cAAc,EAAE,CAAC;IACjC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { type IAudience, type IDeltaManager } from \"@fluidframework/container-definitions\";\nimport { type IContainerContext } from \"@fluidframework/container-definitions/internal\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime/internal\";\nimport type { IContainerRuntimeOptions } from \"@fluidframework/container-runtime/internal\";\nimport { type IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport { type FluidObject, type IRequest, type IResponse } from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype IDocumentMessage,\n\ttype ISequencedDocumentMessage,\n\ttype ISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\ttype ISummaryTreeWithStats,\n\ttype ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n\ttype AttributionInfo,\n\ttype AttributionKey,\n\ttype NamedFluidDataStoreRegistryEntries,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tSummaryTreeBuilder,\n\taddSummarizeResultToSummary,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tPerformanceEvent,\n\tUsageError,\n\tcreateChildLogger,\n\tloggerToMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Attributor, type IAttributor, OpStreamAttributor } from \"./attributor.js\";\nimport { AttributorSerializer, type Encoder, chain, deltaEncoder } from \"./encoders.js\";\nimport { makeLZ4Encoder } from \"./lz4Encoder.js\";\n\n// Summary tree keys\nconst attributorTreeName = \".attributor\";\nconst opBlobName = \"op\";\n\n/**\n * @internal\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @internal\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @internal\n */\nexport interface IProvideRuntimeAttributor {\n\treadonly IRuntimeAttributor: IRuntimeAttributor;\n}\n\n/**\n * Provides access to attribution information stored on the container runtime.\n *\n * @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.\n *\n * @sealed\n * @internal\n */\nexport interface IRuntimeAttributor extends IProvideRuntimeAttributor {\n\t/**\n\t * @throws - If no AttributionInfo exists for this key.\n\t */\n\tget(key: AttributionKey): AttributionInfo;\n\n\t/**\n\t * @returns Whether any AttributionInfo exists for the provided key.\n\t */\n\thas(key: AttributionKey): boolean;\n\n\t/**\n\t * @returns Whether the runtime is currently tracking attribution information for the loaded container.\n\t * See {@link mixinAttributor} for more details on when this happens.\n\t */\n\treadonly isEnabled: boolean;\n}\n\n/**\n * Creates an `IRuntimeAttributor` for usage with {@link mixinAttributor}.\n *\n * @remarks The attributor will only be populated with data once it's passed via scope to a container runtime load flow.\n *\n * @internal\n */\nexport function createRuntimeAttributor(): IRuntimeAttributor {\n\treturn new RuntimeAttributor();\n}\n\n/**\n * Mixes in logic to load and store runtime-based attribution functionality.\n *\n * The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.\n *\n * Existing documents without stored attributors will not start storing attribution information: if an\n * IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,\n * that attributor's `has` method will always return `false`.\n * @param Base - base class, inherits from FluidAttributorRuntime\n * @internal\n */\nexport const mixinAttributor = (\n\tBase: typeof ContainerRuntime = ContainerRuntime,\n): typeof ContainerRuntime =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async loadRuntime(params: {\n\t\t\tcontext: IContainerContext;\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries;\n\t\t\texisting: boolean;\n\t\t\truntimeOptions?: IContainerRuntimeOptions;\n\t\t\tcontainerScope?: FluidObject;\n\t\t\tcontainerRuntimeCtor?: typeof ContainerRuntime;\n\t\t\t/**\n\t\t\t * @deprecated Will be removed once Loader LTS version is \"2.0.0-internal.7.0.0\". Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md\n\t\t\t */\n\t\t\trequestHandler?: (request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>;\n\t\t\tprovideEntryPoint: (containerRuntime: IContainerRuntime) => Promise<FluidObject>;\n\t\t}): Promise<ContainerRuntime> {\n\t\t\tconst {\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\texisting,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\tcontainerRuntimeCtor = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t\t} = params;\n\n\t\t\tconst runtimeAttributor = (\n\t\t\t\tcontainerScope as FluidObject<IProvideRuntimeAttributor> | undefined\n\t\t\t)?.IRuntimeAttributor;\n\t\t\tif (!runtimeAttributor) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"ContainerRuntimeWithAttributor must be passed a scope implementing IProvideRuntimeAttributor\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst pendingRuntimeState = context.pendingLocalState as {\n\t\t\t\tbaseSnapshot?: ISnapshotTree;\n\t\t\t};\n\t\t\tconst baseSnapshot: ISnapshotTree | undefined =\n\t\t\t\tpendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;\n\n\t\t\tconst { audience, deltaManager, taggedLogger } = context;\n\t\t\tassert(\n\t\t\t\taudience !== undefined,\n\t\t\t\t0x508 /* Audience must exist when instantiating attribution-providing runtime */,\n\t\t\t);\n\n\t\t\tconst mc = loggerToMonitoringContext(taggedLogger);\n\n\t\t\tconst shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false;\n\t\t\tif (shouldTrackAttribution) {\n\t\t\t\tconst { options } = context;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(options.attribution ??= {}).track = true;\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tconst runtime = (await Base.loadRuntime({\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\t// ! This prop is needed for back-compat. Can be removed in 2.0.0-internal.8.0.0\n\t\t\t\tinitializeEntryPoint: provideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tcontainerRuntimeCtor,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t} as any)) as ContainerRuntimeWithAttributor;\n\t\t\truntime.runtimeAttributor = runtimeAttributor as RuntimeAttributor;\n\n\t\t\tconst logger = createChildLogger({ logger: runtime.logger, namespace: \"Attributor\" });\n\n\t\t\t// Note: this fetches attribution blobs relatively eagerly in the load flow; we may want to optimize\n\t\t\t// this to avoid blocking on such information until application actually requests some op-based attribution\n\t\t\t// info or we need to summarize. All that really needs to happen immediately is to start recording\n\t\t\t// op seq# -> attributionInfo for new ops.\n\t\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"initialize\",\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tawait runtime.runtimeAttributor?.initialize(\n\t\t\t\t\t\tdeltaManager,\n\t\t\t\t\t\taudience,\n\t\t\t\t\t\tbaseSnapshot,\n\t\t\t\t\t\tasync (id) => runtime.storage.readBlob(id),\n\t\t\t\t\t\tshouldTrackAttribution,\n\t\t\t\t\t);\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\tattributionEnabledInConfig: shouldTrackAttribution,\n\t\t\t\t\t\tattributionEnabledInDoc: runtime.runtimeAttributor\n\t\t\t\t\t\t\t? runtime.runtimeAttributor.isEnabled\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn runtime;\n\t\t}\n\n\t\tprivate runtimeAttributor: RuntimeAttributor | undefined;\n\n\t\tprotected addContainerStateToSummary(\n\t\t\tsummaryTree: ISummaryTreeWithStats,\n\t\t\tfullTree: boolean,\n\t\t\ttrackState: boolean,\n\t\t\ttelemetryContext?: ITelemetryContext,\n\t\t): void {\n\t\t\tsuper.addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext);\n\t\t\tconst attributorSummary = this.runtimeAttributor?.summarize();\n\t\t\tif (attributorSummary) {\n\t\t\t\taddSummarizeResultToSummary(summaryTree, attributorTreeName, attributorSummary);\n\t\t\t}\n\t\t}\n\t} as unknown as typeof ContainerRuntime;\n\nclass RuntimeAttributor implements IRuntimeAttributor {\n\tpublic get IRuntimeAttributor(): IRuntimeAttributor {\n\t\treturn this;\n\t}\n\n\tpublic get(key: AttributionKey): AttributionInfo {\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */,\n\t\t);\n\n\t\tif (key.type === \"detached\") {\n\t\t\tthrow new Error(\"Attribution of detached keys is not yet supported.\");\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\t// Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current\n\t\t\t// client id in the audience. However, for read->write client transition, the container might have not yet\n\t\t\t// received a client id. This is left as a TODO as it might be more easily solved once the detached case\n\t\t\t// is settled (e.g. if it's reasonable for the host to know the current user information at container\n\t\t\t// creation time, we could just use that here as well).\n\t\t\tthrow new Error(\"Attribution of local keys is not yet supported.\");\n\t\t}\n\n\t\treturn this.opAttributor.getAttributionInfo(key.seq);\n\t}\n\n\tpublic has(key: AttributionKey): boolean {\n\t\tif (key.type === \"detached\") {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;\n\t}\n\n\tprivate encoder: Encoder<IAttributor, string> = {\n\t\tencode: unreachableCase,\n\t\tdecode: unreachableCase,\n\t};\n\n\tprivate opAttributor: IAttributor | undefined;\n\tpublic isEnabled = false;\n\n\tpublic async initialize(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\taudience: IAudience,\n\t\tbaseSnapshot: ISnapshotTree | undefined,\n\t\treadBlob: (id: string) => Promise<ArrayBufferLike>,\n\t\tshouldAddAttributorOnNewFile: boolean,\n\t): Promise<void> {\n\t\tconst attributorTree = baseSnapshot?.trees[attributorTreeName];\n\t\t// Existing documents that don't already have a snapshot containing runtime attribution info shouldn't\n\t\t// inject any for now--this causes some back-compat integration problems that aren't fully worked out.\n\t\tconst shouldExcludeAttributor =\n\t\t\t(baseSnapshot !== undefined && attributorTree === undefined) ||\n\t\t\t(baseSnapshot === undefined && !shouldAddAttributorOnNewFile);\n\t\tif (shouldExcludeAttributor) {\n\t\t\t// This gives a consistent error for calls to `get` on keys that don't exist.\n\t\t\tthis.opAttributor = new Attributor();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isEnabled = true;\n\t\tthis.encoder = chain(\n\t\t\tnew AttributorSerializer(\n\t\t\t\t(entries) => new OpStreamAttributor(deltaManager, audience, entries),\n\t\t\t\tdeltaEncoder,\n\t\t\t),\n\t\t\tmakeLZ4Encoder(),\n\t\t);\n\n\t\tif (attributorTree === undefined) {\n\t\t\tthis.opAttributor = new OpStreamAttributor(deltaManager, audience);\n\t\t} else {\n\t\t\tconst id = attributorTree.blobs[opBlobName];\n\t\t\tassert(\n\t\t\t\tid !== undefined,\n\t\t\t\t0x50a /* Attributor tree should have op attributor summary blob. */,\n\t\t\t);\n\t\t\tconst blobContents = await readBlob(id);\n\t\t\tconst attributorSnapshot = bufferToString(blobContents, \"utf8\");\n\t\t\tthis.opAttributor = this.encoder.decode(attributorSnapshot);\n\t\t}\n\t}\n\n\tpublic summarize(): ISummaryTreeWithStats | undefined {\n\t\tif (!this.isEnabled) {\n\t\t\t// Loaded existing document without attributor data: avoid injecting any data.\n\t\t\treturn undefined;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x50b /* RuntimeAttributor should be initialized before summarization */,\n\t\t);\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));\n\t\treturn builder.getSummaryTree();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mixinAttributor.js","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAK9D,yEAA8E;AAI9E,kEAA8E;AAgB9E,qEAGgD;AAChD,uEAKkD;AAElD,mDAAmF;AACnF,+CAAwF;AACxF,mDAAiD;AAEjD,oBAAoB;AACpB,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;GAEG;AACU,QAAA,kBAAkB,GAAG,mCAAmC,CAAC;AAEtE;;GAEG;AACU,QAAA,kBAAkB,GAAoC,oBA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YAC9E,OAAO,SAAS,CAAC;SACjB;QAED,IAAA,iBAAM,EACL,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,6BAAkB,EAAE,CAAC;QACzC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;QACpE,OAAO,OAAO,CAAC,cAAc,EAAE,CAAC;IACjC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport {\n\ttype IDeltaManager,\n\ttype IContainerContext,\n} from \"@fluidframework/container-definitions/internal\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime/internal\";\nimport type { IContainerRuntimeOptions } from \"@fluidframework/container-runtime/internal\";\nimport { type IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport { type FluidObject, type IRequest, type IResponse } from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype IDocumentMessage,\n\ttype IQuorumClients,\n\ttype ISequencedDocumentMessage,\n\ttype ISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\ttype ISummaryTreeWithStats,\n\ttype ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n\ttype AttributionInfo,\n\ttype AttributionKey,\n\ttype NamedFluidDataStoreRegistryEntries,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tSummaryTreeBuilder,\n\taddSummarizeResultToSummary,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tPerformanceEvent,\n\tUsageError,\n\tcreateChildLogger,\n\tloggerToMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Attributor, type IAttributor, OpStreamAttributor } from \"./attributor.js\";\nimport { AttributorSerializer, type Encoder, chain, deltaEncoder } from \"./encoders.js\";\nimport { makeLZ4Encoder } from \"./lz4Encoder.js\";\n\n// Summary tree keys\nconst attributorTreeName = \".attributor\";\nconst opBlobName = \"op\";\n\n/**\n * @internal\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @internal\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @internal\n */\nexport interface IProvideRuntimeAttributor {\n\treadonly IRuntimeAttributor: IRuntimeAttributor;\n}\n\n/**\n * Provides access to attribution information stored on the container runtime.\n *\n * @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.\n *\n * @sealed\n * @internal\n */\nexport interface IRuntimeAttributor extends IProvideRuntimeAttributor {\n\t/**\n\t * @throws - If no AttributionInfo exists for this key.\n\t */\n\tget(key: AttributionKey): AttributionInfo;\n\n\t/**\n\t * @returns Whether any AttributionInfo exists for the provided key.\n\t */\n\thas(key: AttributionKey): boolean;\n\n\t/**\n\t * @returns Whether the runtime is currently tracking attribution information for the loaded container.\n\t * If enabled, the runtime attributor can be asked for the attribution info for different keys.\n\t * See {@link mixinAttributor} for more details on when this happens.\n\t */\n\treadonly isEnabled: boolean;\n}\n\n/**\n * Creates an `IRuntimeAttributor` for usage with {@link mixinAttributor}.\n *\n * @remarks The attributor will only be populated with data once it's passed via scope to a container runtime load flow.\n *\n * @internal\n */\nexport function createRuntimeAttributor(): IRuntimeAttributor {\n\treturn new RuntimeAttributor();\n}\n\n/**\n * Mixes in logic to load and store runtime-based attribution functionality.\n *\n * The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.\n *\n * Existing documents without stored attributors will not start storing attribution information: if an\n * IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,\n * that attributor's `has` method will always return `false`.\n * @param Base - base class, inherits from FluidAttributorRuntime\n * @internal\n */\nexport const mixinAttributor = (\n\tBase: typeof ContainerRuntime = ContainerRuntime,\n): typeof ContainerRuntime =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async loadRuntime(params: {\n\t\t\tcontext: IContainerContext;\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries;\n\t\t\texisting: boolean;\n\t\t\truntimeOptions?: IContainerRuntimeOptions;\n\t\t\tcontainerScope?: FluidObject;\n\t\t\tcontainerRuntimeCtor?: typeof ContainerRuntime;\n\t\t\t/**\n\t\t\t * @deprecated Will be removed once Loader LTS version is \"2.0.0-internal.7.0.0\". Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md\n\t\t\t */\n\t\t\trequestHandler?: (request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>;\n\t\t\tprovideEntryPoint: (containerRuntime: IContainerRuntime) => Promise<FluidObject>;\n\t\t}): Promise<ContainerRuntime> {\n\t\t\tconst {\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\texisting,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\tcontainerRuntimeCtor = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t\t} = params;\n\n\t\t\tconst runtimeAttributor = (\n\t\t\t\tcontainerScope as FluidObject<IProvideRuntimeAttributor> | undefined\n\t\t\t)?.IRuntimeAttributor;\n\t\t\tif (!runtimeAttributor) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"ContainerRuntimeWithAttributor must be passed a scope implementing IProvideRuntimeAttributor\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst pendingRuntimeState = context.pendingLocalState as {\n\t\t\t\tbaseSnapshot?: ISnapshotTree;\n\t\t\t};\n\t\t\tconst baseSnapshot: ISnapshotTree | undefined =\n\t\t\t\tpendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;\n\n\t\t\tconst { quorum, deltaManager, taggedLogger } = context;\n\t\t\tassert(\n\t\t\t\tquorum !== undefined,\n\t\t\t\t0x968 /* quorum must exist when instantiating attribution-providing runtime */,\n\t\t\t);\n\n\t\t\tconst mc = loggerToMonitoringContext(taggedLogger);\n\n\t\t\tconst shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false;\n\t\t\tif (shouldTrackAttribution) {\n\t\t\t\tconst { options } = context;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(options.attribution ??= {}).track = true;\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tconst runtime = (await Base.loadRuntime({\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\t// ! This prop is needed for back-compat. Can be removed in 2.0.0-internal.8.0.0\n\t\t\t\tinitializeEntryPoint: provideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tcontainerRuntimeCtor,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t} as any)) as ContainerRuntimeWithAttributor;\n\t\t\truntime.runtimeAttributor = runtimeAttributor as RuntimeAttributor;\n\n\t\t\tconst logger = createChildLogger({ logger: runtime.logger, namespace: \"Attributor\" });\n\n\t\t\t// Note: this fetches attribution blobs relatively eagerly in the load flow; we may want to optimize\n\t\t\t// this to avoid blocking on such information until application actually requests some op-based attribution\n\t\t\t// info or we need to summarize. All that really needs to happen immediately is to start recording\n\t\t\t// op seq# -> attributionInfo for new ops.\n\t\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"initialize\",\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tawait runtime.runtimeAttributor?.initialize(\n\t\t\t\t\t\tdeltaManager,\n\t\t\t\t\t\tquorum,\n\t\t\t\t\t\tbaseSnapshot,\n\t\t\t\t\t\tasync (id) => runtime.storage.readBlob(id),\n\t\t\t\t\t\tshouldTrackAttribution,\n\t\t\t\t\t);\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\tattributionEnabledInConfig: shouldTrackAttribution,\n\t\t\t\t\t\tattributionEnabledInDoc: runtime.runtimeAttributor\n\t\t\t\t\t\t\t? runtime.runtimeAttributor.isEnabled\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn runtime;\n\t\t}\n\n\t\tprivate runtimeAttributor: RuntimeAttributor | undefined;\n\n\t\tprotected addContainerStateToSummary(\n\t\t\tsummaryTree: ISummaryTreeWithStats,\n\t\t\tfullTree: boolean,\n\t\t\ttrackState: boolean,\n\t\t\ttelemetryContext?: ITelemetryContext,\n\t\t): void {\n\t\t\tsuper.addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext);\n\t\t\tconst attributorSummary = this.runtimeAttributor?.summarize();\n\t\t\tif (attributorSummary) {\n\t\t\t\taddSummarizeResultToSummary(summaryTree, attributorTreeName, attributorSummary);\n\t\t\t}\n\t\t}\n\t} as unknown as typeof ContainerRuntime;\n\nclass RuntimeAttributor implements IRuntimeAttributor {\n\tpublic get IRuntimeAttributor(): IRuntimeAttributor {\n\t\treturn this;\n\t}\n\n\tpublic get(key: AttributionKey): AttributionInfo {\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */,\n\t\t);\n\n\t\tif (key.type === \"detached\") {\n\t\t\tthrow new Error(\"Attribution of detached keys is not yet supported.\");\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\t// Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current\n\t\t\t// client id in the audience. However, for read->write client transition, the container might have not yet\n\t\t\t// received a client id. This is left as a TODO as it might be more easily solved once the detached case\n\t\t\t// is settled (e.g. if it's reasonable for the host to know the current user information at container\n\t\t\t// creation time, we could just use that here as well).\n\t\t\tthrow new Error(\"Attribution of local keys is not yet supported.\");\n\t\t}\n\n\t\treturn this.opAttributor.getAttributionInfo(key.seq);\n\t}\n\n\tpublic has(key: AttributionKey): boolean {\n\t\tif (key.type === \"detached\") {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;\n\t}\n\n\tprivate encoder: Encoder<IAttributor, string> = {\n\t\tencode: unreachableCase,\n\t\tdecode: unreachableCase,\n\t};\n\n\tprivate opAttributor: IAttributor | undefined;\n\tpublic isEnabled = false;\n\n\tpublic async initialize(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tquorum: IQuorumClients,\n\t\tbaseSnapshot: ISnapshotTree | undefined,\n\t\treadBlob: (id: string) => Promise<ArrayBufferLike>,\n\t\tshouldAddAttributorOnNewFile: boolean,\n\t): Promise<void> {\n\t\tconst attributorTree = baseSnapshot?.trees[attributorTreeName];\n\t\t// Existing documents that don't already have a snapshot containing runtime attribution info shouldn't\n\t\t// inject any for now--this causes some back-compat integration problems that aren't fully worked out.\n\t\tconst shouldExcludeAttributor =\n\t\t\t(baseSnapshot !== undefined && attributorTree === undefined) ||\n\t\t\t(baseSnapshot === undefined && !shouldAddAttributorOnNewFile);\n\t\tif (shouldExcludeAttributor) {\n\t\t\t// This gives a consistent error for calls to `get` on keys that don't exist.\n\t\t\tthis.opAttributor = new Attributor();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isEnabled = true;\n\t\tthis.encoder = chain(\n\t\t\tnew AttributorSerializer(\n\t\t\t\t(entries) => new OpStreamAttributor(deltaManager, quorum, entries),\n\t\t\t\tdeltaEncoder,\n\t\t\t),\n\t\t\tmakeLZ4Encoder(),\n\t\t);\n\n\t\tif (attributorTree === undefined) {\n\t\t\tthis.opAttributor = new OpStreamAttributor(deltaManager, quorum);\n\t\t} else {\n\t\t\tconst id = attributorTree.blobs[opBlobName];\n\t\t\tassert(\n\t\t\t\tid !== undefined,\n\t\t\t\t0x50a /* Attributor tree should have op attributor summary blob. */,\n\t\t\t);\n\t\t\tconst blobContents = await readBlob(id);\n\t\t\tconst attributorSnapshot = bufferToString(blobContents, \"utf8\");\n\t\t\tthis.opAttributor = this.encoder.decode(attributorSnapshot);\n\t\t}\n\t}\n\n\tpublic summarize(): ISummaryTreeWithStats | undefined {\n\t\tif (!this.isEnabled) {\n\t\t\t// Loaded existing document without attributor data: avoid injecting any data.\n\t\t\treturn undefined;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x50b /* RuntimeAttributor should be initialized before summarization */,\n\t\t);\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));\n\t\treturn builder.getSummaryTree();\n\t}\n}\n"]}
|
package/lib/attributor.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { type
|
|
6
|
-
import { type IDocumentMessage, type ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
5
|
+
import { type IDeltaManager } from "@fluidframework/container-definitions/internal";
|
|
6
|
+
import { type IDocumentMessage, type IQuorumClients, type ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
7
7
|
import { type AttributionInfo } from "@fluidframework/runtime-definitions/internal";
|
|
8
8
|
/**
|
|
9
9
|
* Provides lookup between attribution keys and their associated attribution information.
|
|
@@ -28,7 +28,6 @@ export interface IAttributor {
|
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* {@inheritdoc IAttributor}
|
|
31
|
-
* @internal
|
|
32
31
|
*/
|
|
33
32
|
export declare class Attributor implements IAttributor {
|
|
34
33
|
protected readonly keyToInfo: Map<number, AttributionInfo>;
|
|
@@ -52,9 +51,8 @@ export declare class Attributor implements IAttributor {
|
|
|
52
51
|
/**
|
|
53
52
|
* Attributor which listens to an op stream and records entries for each op.
|
|
54
53
|
* Sequence numbers are used as attribution keys.
|
|
55
|
-
* @internal
|
|
56
54
|
*/
|
|
57
55
|
export declare class OpStreamAttributor extends Attributor implements IAttributor {
|
|
58
|
-
constructor(deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,
|
|
56
|
+
constructor(deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>, quorumClients: IQuorumClients, initialEntries?: Iterable<[number, AttributionInfo]>);
|
|
59
57
|
}
|
|
60
58
|
//# sourceMappingURL=attributor.d.ts.map
|
package/lib/attributor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributor.d.ts","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"attributor.d.ts","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAEpF,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAGpF;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;OAIG;IACH,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;IAEjD;;;OAGG;IACH,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IAEhE;;OAEG;IACH,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CAIvD;AAED;;GAEG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC7C,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAE3D;;OAEG;gBACgB,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAIvE;;OAEG;IACI,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe;IAQvD;;OAEG;IACI,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAItE;;OAEG;IACI,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAG7D;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,UAAW,YAAW,WAAW;gBAEvE,YAAY,EAAE,aAAa,CAAC,yBAAyB,EAAE,gBAAgB,CAAC,EACxE,aAAa,EAAE,cAAc,EAC7B,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAqBrD"}
|
package/lib/attributor.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
6
|
+
import { MessageType, } from "@fluidframework/protocol-definitions";
|
|
6
7
|
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
7
8
|
/**
|
|
8
9
|
* {@inheritdoc IAttributor}
|
|
9
|
-
* @internal
|
|
10
10
|
*/
|
|
11
11
|
export class Attributor {
|
|
12
12
|
/**
|
|
@@ -41,19 +41,17 @@ export class Attributor {
|
|
|
41
41
|
/**
|
|
42
42
|
* Attributor which listens to an op stream and records entries for each op.
|
|
43
43
|
* Sequence numbers are used as attribution keys.
|
|
44
|
-
* @internal
|
|
45
44
|
*/
|
|
46
45
|
export class OpStreamAttributor extends Attributor {
|
|
47
|
-
constructor(deltaManager,
|
|
46
|
+
constructor(deltaManager, quorumClients, initialEntries) {
|
|
48
47
|
super(initialEntries);
|
|
49
48
|
deltaManager.on("op", (message) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
assert(client !== undefined, 0x4af /* Received message from user not in the audience */);
|
|
49
|
+
if (message.type === MessageType.Operation) {
|
|
50
|
+
assert(typeof message.clientId === "string", 0x966 /* Client id should be present and should be of type string */);
|
|
51
|
+
const client = quorumClients.getMember(message.clientId);
|
|
52
|
+
assert(client !== undefined, 0x967 /* Received message from user not in the quorumClients */);
|
|
55
53
|
this.keyToInfo.set(message.sequenceNumber, {
|
|
56
|
-
user: client.user,
|
|
54
|
+
user: client.client.user,
|
|
57
55
|
timestamp: message.timestamp,
|
|
58
56
|
});
|
|
59
57
|
}
|
package/lib/attributor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributor.js","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"attributor.js","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EACN,WAAW,GAIX,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AA6BtE;;GAEG;AACH,MAAM,OAAO,UAAU;IAGtB;;OAEG;IACH,YAAmB,cAAoD;QACtE,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACI,kBAAkB,CAAC,GAAW;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,IAAI,UAAU,CAAC,uDAAuD,GAAG,GAAG,CAAC,CAAC;SACpF;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;OAEG;IACI,qBAAqB,CAAC,GAAW;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACI,OAAO;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,UAAU;IACjD,YACC,YAAwE,EACxE,aAA6B,EAC7B,cAAoD;QAEpD,KAAK,CAAC,cAAc,CAAC,CAAC;QACtB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,OAAkC,EAAE,EAAE;YAC5D,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,SAAS,EAAE;gBAC3C,MAAM,CACL,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,EACpC,KAAK,CAAC,8DAA8D,CACpE,CAAC;gBACF,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBACzD,MAAM,CACL,MAAM,KAAK,SAAS,EACpB,KAAK,CAAC,yDAAyD,CAC/D,CAAC;gBACF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE;oBAC1C,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI;oBACxB,SAAS,EAAE,OAAO,CAAC,SAAS;iBAC5B,CAAC,CAAC;aACH;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type IDeltaManager } from \"@fluidframework/container-definitions/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tMessageType,\n\ttype IDocumentMessage,\n\ttype IQuorumClients,\n\ttype ISequencedDocumentMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport { type AttributionInfo } from \"@fluidframework/runtime-definitions/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\n/**\n * Provides lookup between attribution keys and their associated attribution information.\n * @internal\n */\nexport interface IAttributor {\n\t/**\n\t * Retrieves attribution information associated with a particular key.\n\t * @param key - Attribution key to look up.\n\t * @throws If no attribution information is recorded for that key.\n\t */\n\tgetAttributionInfo(key: number): AttributionInfo;\n\n\t/**\n\t * @param key - Attribution key to look up.\n\t * @returns the attribution information associated with the provided key, or undefined if no information exists.\n\t */\n\ttryGetAttributionInfo(key: number): AttributionInfo | undefined;\n\n\t/**\n\t * @returns an iterable of (attribution key, attribution info) pairs for each stored key.\n\t */\n\tentries(): IterableIterator<[number, AttributionInfo]>;\n\n\t// TODO:\n\t// - GC\n}\n\n/**\n * {@inheritdoc IAttributor}\n */\nexport class Attributor implements IAttributor {\n\tprotected readonly keyToInfo: Map<number, AttributionInfo>;\n\n\t/**\n\t * @param initialEntries - Any entries which should be populated on instantiation.\n\t */\n\tpublic constructor(initialEntries?: Iterable<[number, AttributionInfo]>) {\n\t\tthis.keyToInfo = new Map(initialEntries ?? []);\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.getAttributionInfo}\n\t */\n\tpublic getAttributionInfo(key: number): AttributionInfo {\n\t\tconst result = this.tryGetAttributionInfo(key);\n\t\tif (!result) {\n\t\t\tthrow new UsageError(`Requested attribution information for unstored key: ${key}.`);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.tryGetAttributionInfo}\n\t */\n\tpublic tryGetAttributionInfo(key: number): AttributionInfo | undefined {\n\t\treturn this.keyToInfo.get(key);\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.entries}\n\t */\n\tpublic entries(): IterableIterator<[number, AttributionInfo]> {\n\t\treturn this.keyToInfo.entries();\n\t}\n}\n\n/**\n * Attributor which listens to an op stream and records entries for each op.\n * Sequence numbers are used as attribution keys.\n */\nexport class OpStreamAttributor extends Attributor implements IAttributor {\n\tpublic constructor(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tquorumClients: IQuorumClients,\n\t\tinitialEntries?: Iterable<[number, AttributionInfo]>,\n\t) {\n\t\tsuper(initialEntries);\n\t\tdeltaManager.on(\"op\", (message: ISequencedDocumentMessage) => {\n\t\t\tif (message.type === MessageType.Operation) {\n\t\t\t\tassert(\n\t\t\t\t\ttypeof message.clientId === \"string\",\n\t\t\t\t\t0x966 /* Client id should be present and should be of type string */,\n\t\t\t\t);\n\t\t\t\tconst client = quorumClients.getMember(message.clientId);\n\t\t\t\tassert(\n\t\t\t\t\tclient !== undefined,\n\t\t\t\t\t0x967 /* Received message from user not in the quorumClients */,\n\t\t\t\t);\n\t\t\t\tthis.keyToInfo.set(message.sequenceNumber, {\n\t\t\t\t\tuser: client.client.user,\n\t\t\t\t\ttimestamp: message.timestamp,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
export {
|
|
5
|
+
export { type IAttributor } from "./attributor.js";
|
|
6
6
|
export { createRuntimeAttributor, enableOnNewFileKey, type IProvideRuntimeAttributor, IRuntimeAttributor, mixinAttributor, } from "./mixinAttributor.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EACN,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,eAAe,GACf,MAAM,sBAAsB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -2,6 +2,5 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
export { Attributor, OpStreamAttributor } from "./attributor.js";
|
|
6
5
|
export { createRuntimeAttributor, enableOnNewFileKey, IRuntimeAttributor, mixinAttributor, } from "./mixinAttributor.js";
|
|
7
6
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,uBAAuB,EACvB,kBAAkB,EAElB,kBAAkB,EAClB,eAAe,GACf,MAAM,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { type IAttributor } from \"./attributor.js\";\nexport {\n\tcreateRuntimeAttributor,\n\tenableOnNewFileKey,\n\ttype IProvideRuntimeAttributor,\n\tIRuntimeAttributor,\n\tmixinAttributor,\n} from \"./mixinAttributor.js\";\n"]}
|
package/lib/mixinAttributor.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface IRuntimeAttributor extends IProvideRuntimeAttributor {
|
|
|
37
37
|
has(key: AttributionKey): boolean;
|
|
38
38
|
/**
|
|
39
39
|
* @returns Whether the runtime is currently tracking attribution information for the loaded container.
|
|
40
|
+
* If enabled, the runtime attributor can be asked for the attribution info for different keys.
|
|
40
41
|
* See {@link mixinAttributor} for more details on when this happens.
|
|
41
42
|
*/
|
|
42
43
|
readonly isEnabled: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAe9E,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,cAAc,EAEnB,MAAM,8CAA8C,CAAC;AAoBtD;;GAEG;AACH,eAAO,MAAM,kBAAkB,sCAAsC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,yBAAgD,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAmB,SAAQ,yBAAyB;IACpE;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,eAAe,CAAC;IAE1C;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC;IAElC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,IAAI,kBAAkB,CAE5D;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,UACrB,uBAAuB,KAC3B,uBAqHqC,CAAC"}
|
package/lib/mixinAttributor.js
CHANGED
|
@@ -51,8 +51,8 @@ export const mixinAttributor = (Base = ContainerRuntime) => class ContainerRunti
|
|
|
51
51
|
}
|
|
52
52
|
const pendingRuntimeState = context.pendingLocalState;
|
|
53
53
|
const baseSnapshot = pendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;
|
|
54
|
-
const {
|
|
55
|
-
assert(
|
|
54
|
+
const { quorum, deltaManager, taggedLogger } = context;
|
|
55
|
+
assert(quorum !== undefined, 0x968 /* quorum must exist when instantiating attribution-providing runtime */);
|
|
56
56
|
const mc = loggerToMonitoringContext(taggedLogger);
|
|
57
57
|
const shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false;
|
|
58
58
|
if (shouldTrackAttribution) {
|
|
@@ -83,7 +83,7 @@ export const mixinAttributor = (Base = ContainerRuntime) => class ContainerRunti
|
|
|
83
83
|
await PerformanceEvent.timedExecAsync(logger, {
|
|
84
84
|
eventName: "initialize",
|
|
85
85
|
}, async (event) => {
|
|
86
|
-
await runtime.runtimeAttributor?.initialize(deltaManager,
|
|
86
|
+
await runtime.runtimeAttributor?.initialize(deltaManager, quorum, baseSnapshot, async (id) => runtime.storage.readBlob(id), shouldTrackAttribution);
|
|
87
87
|
event.end({
|
|
88
88
|
attributionEnabledInConfig: shouldTrackAttribution,
|
|
89
89
|
attributionEnabledInDoc: runtime.runtimeAttributor
|
|
@@ -136,7 +136,7 @@ class RuntimeAttributor {
|
|
|
136
136
|
}
|
|
137
137
|
return this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;
|
|
138
138
|
}
|
|
139
|
-
async initialize(deltaManager,
|
|
139
|
+
async initialize(deltaManager, quorum, baseSnapshot, readBlob, shouldAddAttributorOnNewFile) {
|
|
140
140
|
const attributorTree = baseSnapshot?.trees[attributorTreeName];
|
|
141
141
|
// Existing documents that don't already have a snapshot containing runtime attribution info shouldn't
|
|
142
142
|
// inject any for now--this causes some back-compat integration problems that aren't fully worked out.
|
|
@@ -148,9 +148,9 @@ class RuntimeAttributor {
|
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
150
|
this.isEnabled = true;
|
|
151
|
-
this.encoder = chain(new AttributorSerializer((entries) => new OpStreamAttributor(deltaManager,
|
|
151
|
+
this.encoder = chain(new AttributorSerializer((entries) => new OpStreamAttributor(deltaManager, quorum, entries), deltaEncoder), makeLZ4Encoder());
|
|
152
152
|
if (attributorTree === undefined) {
|
|
153
|
-
this.opAttributor = new OpStreamAttributor(deltaManager,
|
|
153
|
+
this.opAttributor = new OpStreamAttributor(deltaManager, quorum);
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
156
156
|
const id = attributorTree.blobs[opBlobName];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixinAttributor.js","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAI9E,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAe9E,OAAO,EACN,kBAAkB,EAClB,2BAA2B,GAC3B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACN,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,yBAAyB,GACzB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,UAAU,EAAoB,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAgB,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,oBAAoB;AACpB,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,mCAAmC,CAAC;AAEtE;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAoC,oBAAoB,CAAC;AAmCxF;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB;IACtC,OAAO,IAAI,iBAAiB,EAAE,CAAC;AAChC,CAAC;AAED;;;;;;;;;;GAUG;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AC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;QACpE,OAAO,OAAO,CAAC,cAAc,EAAE,CAAC;IACjC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { type IAudience, type IDeltaManager } from \"@fluidframework/container-definitions\";\nimport { type IContainerContext } from \"@fluidframework/container-definitions/internal\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime/internal\";\nimport type { IContainerRuntimeOptions } from \"@fluidframework/container-runtime/internal\";\nimport { type IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport { type FluidObject, type IRequest, type IResponse } from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype IDocumentMessage,\n\ttype ISequencedDocumentMessage,\n\ttype ISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\ttype ISummaryTreeWithStats,\n\ttype ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n\ttype AttributionInfo,\n\ttype AttributionKey,\n\ttype NamedFluidDataStoreRegistryEntries,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tSummaryTreeBuilder,\n\taddSummarizeResultToSummary,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tPerformanceEvent,\n\tUsageError,\n\tcreateChildLogger,\n\tloggerToMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Attributor, type IAttributor, OpStreamAttributor } from \"./attributor.js\";\nimport { AttributorSerializer, type Encoder, chain, deltaEncoder } from \"./encoders.js\";\nimport { makeLZ4Encoder } from \"./lz4Encoder.js\";\n\n// Summary tree keys\nconst attributorTreeName = \".attributor\";\nconst opBlobName = \"op\";\n\n/**\n * @internal\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @internal\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @internal\n */\nexport interface IProvideRuntimeAttributor {\n\treadonly IRuntimeAttributor: IRuntimeAttributor;\n}\n\n/**\n * Provides access to attribution information stored on the container runtime.\n *\n * @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.\n *\n * @sealed\n * @internal\n */\nexport interface IRuntimeAttributor extends IProvideRuntimeAttributor {\n\t/**\n\t * @throws - If no AttributionInfo exists for this key.\n\t */\n\tget(key: AttributionKey): AttributionInfo;\n\n\t/**\n\t * @returns Whether any AttributionInfo exists for the provided key.\n\t */\n\thas(key: AttributionKey): boolean;\n\n\t/**\n\t * @returns Whether the runtime is currently tracking attribution information for the loaded container.\n\t * See {@link mixinAttributor} for more details on when this happens.\n\t */\n\treadonly isEnabled: boolean;\n}\n\n/**\n * Creates an `IRuntimeAttributor` for usage with {@link mixinAttributor}.\n *\n * @remarks The attributor will only be populated with data once it's passed via scope to a container runtime load flow.\n *\n * @internal\n */\nexport function createRuntimeAttributor(): IRuntimeAttributor {\n\treturn new RuntimeAttributor();\n}\n\n/**\n * Mixes in logic to load and store runtime-based attribution functionality.\n *\n * The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.\n *\n * Existing documents without stored attributors will not start storing attribution information: if an\n * IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,\n * that attributor's `has` method will always return `false`.\n * @param Base - base class, inherits from FluidAttributorRuntime\n * @internal\n */\nexport const mixinAttributor = (\n\tBase: typeof ContainerRuntime = ContainerRuntime,\n): typeof ContainerRuntime =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async loadRuntime(params: {\n\t\t\tcontext: IContainerContext;\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries;\n\t\t\texisting: boolean;\n\t\t\truntimeOptions?: IContainerRuntimeOptions;\n\t\t\tcontainerScope?: FluidObject;\n\t\t\tcontainerRuntimeCtor?: typeof ContainerRuntime;\n\t\t\t/**\n\t\t\t * @deprecated Will be removed once Loader LTS version is \"2.0.0-internal.7.0.0\". Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md\n\t\t\t */\n\t\t\trequestHandler?: (request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>;\n\t\t\tprovideEntryPoint: (containerRuntime: IContainerRuntime) => Promise<FluidObject>;\n\t\t}): Promise<ContainerRuntime> {\n\t\t\tconst {\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\texisting,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\tcontainerRuntimeCtor = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t\t} = params;\n\n\t\t\tconst runtimeAttributor = (\n\t\t\t\tcontainerScope as FluidObject<IProvideRuntimeAttributor> | undefined\n\t\t\t)?.IRuntimeAttributor;\n\t\t\tif (!runtimeAttributor) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"ContainerRuntimeWithAttributor must be passed a scope implementing IProvideRuntimeAttributor\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst pendingRuntimeState = context.pendingLocalState as {\n\t\t\t\tbaseSnapshot?: ISnapshotTree;\n\t\t\t};\n\t\t\tconst baseSnapshot: ISnapshotTree | undefined =\n\t\t\t\tpendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;\n\n\t\t\tconst { audience, deltaManager, taggedLogger } = context;\n\t\t\tassert(\n\t\t\t\taudience !== undefined,\n\t\t\t\t0x508 /* Audience must exist when instantiating attribution-providing runtime */,\n\t\t\t);\n\n\t\t\tconst mc = loggerToMonitoringContext(taggedLogger);\n\n\t\t\tconst shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false;\n\t\t\tif (shouldTrackAttribution) {\n\t\t\t\tconst { options } = context;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(options.attribution ??= {}).track = true;\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tconst runtime = (await Base.loadRuntime({\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\t// ! This prop is needed for back-compat. Can be removed in 2.0.0-internal.8.0.0\n\t\t\t\tinitializeEntryPoint: provideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tcontainerRuntimeCtor,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t} as any)) as ContainerRuntimeWithAttributor;\n\t\t\truntime.runtimeAttributor = runtimeAttributor as RuntimeAttributor;\n\n\t\t\tconst logger = createChildLogger({ logger: runtime.logger, namespace: \"Attributor\" });\n\n\t\t\t// Note: this fetches attribution blobs relatively eagerly in the load flow; we may want to optimize\n\t\t\t// this to avoid blocking on such information until application actually requests some op-based attribution\n\t\t\t// info or we need to summarize. All that really needs to happen immediately is to start recording\n\t\t\t// op seq# -> attributionInfo for new ops.\n\t\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"initialize\",\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tawait runtime.runtimeAttributor?.initialize(\n\t\t\t\t\t\tdeltaManager,\n\t\t\t\t\t\taudience,\n\t\t\t\t\t\tbaseSnapshot,\n\t\t\t\t\t\tasync (id) => runtime.storage.readBlob(id),\n\t\t\t\t\t\tshouldTrackAttribution,\n\t\t\t\t\t);\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\tattributionEnabledInConfig: shouldTrackAttribution,\n\t\t\t\t\t\tattributionEnabledInDoc: runtime.runtimeAttributor\n\t\t\t\t\t\t\t? runtime.runtimeAttributor.isEnabled\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn runtime;\n\t\t}\n\n\t\tprivate runtimeAttributor: RuntimeAttributor | undefined;\n\n\t\tprotected addContainerStateToSummary(\n\t\t\tsummaryTree: ISummaryTreeWithStats,\n\t\t\tfullTree: boolean,\n\t\t\ttrackState: boolean,\n\t\t\ttelemetryContext?: ITelemetryContext,\n\t\t): void {\n\t\t\tsuper.addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext);\n\t\t\tconst attributorSummary = this.runtimeAttributor?.summarize();\n\t\t\tif (attributorSummary) {\n\t\t\t\taddSummarizeResultToSummary(summaryTree, attributorTreeName, attributorSummary);\n\t\t\t}\n\t\t}\n\t} as unknown as typeof ContainerRuntime;\n\nclass RuntimeAttributor implements IRuntimeAttributor {\n\tpublic get IRuntimeAttributor(): IRuntimeAttributor {\n\t\treturn this;\n\t}\n\n\tpublic get(key: AttributionKey): AttributionInfo {\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */,\n\t\t);\n\n\t\tif (key.type === \"detached\") {\n\t\t\tthrow new Error(\"Attribution of detached keys is not yet supported.\");\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\t// Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current\n\t\t\t// client id in the audience. However, for read->write client transition, the container might have not yet\n\t\t\t// received a client id. This is left as a TODO as it might be more easily solved once the detached case\n\t\t\t// is settled (e.g. if it's reasonable for the host to know the current user information at container\n\t\t\t// creation time, we could just use that here as well).\n\t\t\tthrow new Error(\"Attribution of local keys is not yet supported.\");\n\t\t}\n\n\t\treturn this.opAttributor.getAttributionInfo(key.seq);\n\t}\n\n\tpublic has(key: AttributionKey): boolean {\n\t\tif (key.type === \"detached\") {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;\n\t}\n\n\tprivate encoder: Encoder<IAttributor, string> = {\n\t\tencode: unreachableCase,\n\t\tdecode: unreachableCase,\n\t};\n\n\tprivate opAttributor: IAttributor | undefined;\n\tpublic isEnabled = false;\n\n\tpublic async initialize(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\taudience: IAudience,\n\t\tbaseSnapshot: ISnapshotTree | undefined,\n\t\treadBlob: (id: string) => Promise<ArrayBufferLike>,\n\t\tshouldAddAttributorOnNewFile: boolean,\n\t): Promise<void> {\n\t\tconst attributorTree = baseSnapshot?.trees[attributorTreeName];\n\t\t// Existing documents that don't already have a snapshot containing runtime attribution info shouldn't\n\t\t// inject any for now--this causes some back-compat integration problems that aren't fully worked out.\n\t\tconst shouldExcludeAttributor =\n\t\t\t(baseSnapshot !== undefined && attributorTree === undefined) ||\n\t\t\t(baseSnapshot === undefined && !shouldAddAttributorOnNewFile);\n\t\tif (shouldExcludeAttributor) {\n\t\t\t// This gives a consistent error for calls to `get` on keys that don't exist.\n\t\t\tthis.opAttributor = new Attributor();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isEnabled = true;\n\t\tthis.encoder = chain(\n\t\t\tnew AttributorSerializer(\n\t\t\t\t(entries) => new OpStreamAttributor(deltaManager, audience, entries),\n\t\t\t\tdeltaEncoder,\n\t\t\t),\n\t\t\tmakeLZ4Encoder(),\n\t\t);\n\n\t\tif (attributorTree === undefined) {\n\t\t\tthis.opAttributor = new OpStreamAttributor(deltaManager, audience);\n\t\t} else {\n\t\t\tconst id = attributorTree.blobs[opBlobName];\n\t\t\tassert(\n\t\t\t\tid !== undefined,\n\t\t\t\t0x50a /* Attributor tree should have op attributor summary blob. */,\n\t\t\t);\n\t\t\tconst blobContents = await readBlob(id);\n\t\t\tconst attributorSnapshot = bufferToString(blobContents, \"utf8\");\n\t\t\tthis.opAttributor = this.encoder.decode(attributorSnapshot);\n\t\t}\n\t}\n\n\tpublic summarize(): ISummaryTreeWithStats | undefined {\n\t\tif (!this.isEnabled) {\n\t\t\t// Loaded existing document without attributor data: avoid injecting any data.\n\t\t\treturn undefined;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x50b /* RuntimeAttributor should be initialized before summarization */,\n\t\t);\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));\n\t\treturn builder.getSummaryTree();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mixinAttributor.js","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAK9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAI9E,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAgB9E,OAAO,EACN,kBAAkB,EAClB,2BAA2B,GAC3B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACN,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,yBAAyB,GACzB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,UAAU,EAAoB,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAgB,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,oBAAoB;AACpB,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,mCAAmC,CAAC;AAEtE;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAoC,oBAAoB,CAAC;AAoCxF;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB;IACtC,OAAO,IAAI,iBAA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OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;QACpE,OAAO,OAAO,CAAC,cAAc,EAAE,CAAC;IACjC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport {\n\ttype IDeltaManager,\n\ttype IContainerContext,\n} from \"@fluidframework/container-definitions/internal\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime/internal\";\nimport type { IContainerRuntimeOptions } from \"@fluidframework/container-runtime/internal\";\nimport { type IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport { type FluidObject, type IRequest, type IResponse } from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype IDocumentMessage,\n\ttype IQuorumClients,\n\ttype ISequencedDocumentMessage,\n\ttype ISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\ttype ISummaryTreeWithStats,\n\ttype ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n\ttype AttributionInfo,\n\ttype AttributionKey,\n\ttype NamedFluidDataStoreRegistryEntries,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tSummaryTreeBuilder,\n\taddSummarizeResultToSummary,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tPerformanceEvent,\n\tUsageError,\n\tcreateChildLogger,\n\tloggerToMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Attributor, type IAttributor, OpStreamAttributor } from \"./attributor.js\";\nimport { AttributorSerializer, type Encoder, chain, deltaEncoder } from \"./encoders.js\";\nimport { makeLZ4Encoder } from \"./lz4Encoder.js\";\n\n// Summary tree keys\nconst attributorTreeName = \".attributor\";\nconst opBlobName = \"op\";\n\n/**\n * @internal\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @internal\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @internal\n */\nexport interface IProvideRuntimeAttributor {\n\treadonly IRuntimeAttributor: IRuntimeAttributor;\n}\n\n/**\n * Provides access to attribution information stored on the container runtime.\n *\n * @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.\n *\n * @sealed\n * @internal\n */\nexport interface IRuntimeAttributor extends IProvideRuntimeAttributor {\n\t/**\n\t * @throws - If no AttributionInfo exists for this key.\n\t */\n\tget(key: AttributionKey): AttributionInfo;\n\n\t/**\n\t * @returns Whether any AttributionInfo exists for the provided key.\n\t */\n\thas(key: AttributionKey): boolean;\n\n\t/**\n\t * @returns Whether the runtime is currently tracking attribution information for the loaded container.\n\t * If enabled, the runtime attributor can be asked for the attribution info for different keys.\n\t * See {@link mixinAttributor} for more details on when this happens.\n\t */\n\treadonly isEnabled: boolean;\n}\n\n/**\n * Creates an `IRuntimeAttributor` for usage with {@link mixinAttributor}.\n *\n * @remarks The attributor will only be populated with data once it's passed via scope to a container runtime load flow.\n *\n * @internal\n */\nexport function createRuntimeAttributor(): IRuntimeAttributor {\n\treturn new RuntimeAttributor();\n}\n\n/**\n * Mixes in logic to load and store runtime-based attribution functionality.\n *\n * The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.\n *\n * Existing documents without stored attributors will not start storing attribution information: if an\n * IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,\n * that attributor's `has` method will always return `false`.\n * @param Base - base class, inherits from FluidAttributorRuntime\n * @internal\n */\nexport const mixinAttributor = (\n\tBase: typeof ContainerRuntime = ContainerRuntime,\n): typeof ContainerRuntime =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async loadRuntime(params: {\n\t\t\tcontext: IContainerContext;\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries;\n\t\t\texisting: boolean;\n\t\t\truntimeOptions?: IContainerRuntimeOptions;\n\t\t\tcontainerScope?: FluidObject;\n\t\t\tcontainerRuntimeCtor?: typeof ContainerRuntime;\n\t\t\t/**\n\t\t\t * @deprecated Will be removed once Loader LTS version is \"2.0.0-internal.7.0.0\". Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md\n\t\t\t */\n\t\t\trequestHandler?: (request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>;\n\t\t\tprovideEntryPoint: (containerRuntime: IContainerRuntime) => Promise<FluidObject>;\n\t\t}): Promise<ContainerRuntime> {\n\t\t\tconst {\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\texisting,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\tcontainerRuntimeCtor = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t\t} = params;\n\n\t\t\tconst runtimeAttributor = (\n\t\t\t\tcontainerScope as FluidObject<IProvideRuntimeAttributor> | undefined\n\t\t\t)?.IRuntimeAttributor;\n\t\t\tif (!runtimeAttributor) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"ContainerRuntimeWithAttributor must be passed a scope implementing IProvideRuntimeAttributor\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst pendingRuntimeState = context.pendingLocalState as {\n\t\t\t\tbaseSnapshot?: ISnapshotTree;\n\t\t\t};\n\t\t\tconst baseSnapshot: ISnapshotTree | undefined =\n\t\t\t\tpendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;\n\n\t\t\tconst { quorum, deltaManager, taggedLogger } = context;\n\t\t\tassert(\n\t\t\t\tquorum !== undefined,\n\t\t\t\t0x968 /* quorum must exist when instantiating attribution-providing runtime */,\n\t\t\t);\n\n\t\t\tconst mc = loggerToMonitoringContext(taggedLogger);\n\n\t\t\tconst shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false;\n\t\t\tif (shouldTrackAttribution) {\n\t\t\t\tconst { options } = context;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(options.attribution ??= {}).track = true;\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tconst runtime = (await Base.loadRuntime({\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\t// ! This prop is needed for back-compat. Can be removed in 2.0.0-internal.8.0.0\n\t\t\t\tinitializeEntryPoint: provideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tcontainerRuntimeCtor,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t} as any)) as ContainerRuntimeWithAttributor;\n\t\t\truntime.runtimeAttributor = runtimeAttributor as RuntimeAttributor;\n\n\t\t\tconst logger = createChildLogger({ logger: runtime.logger, namespace: \"Attributor\" });\n\n\t\t\t// Note: this fetches attribution blobs relatively eagerly in the load flow; we may want to optimize\n\t\t\t// this to avoid blocking on such information until application actually requests some op-based attribution\n\t\t\t// info or we need to summarize. All that really needs to happen immediately is to start recording\n\t\t\t// op seq# -> attributionInfo for new ops.\n\t\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"initialize\",\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tawait runtime.runtimeAttributor?.initialize(\n\t\t\t\t\t\tdeltaManager,\n\t\t\t\t\t\tquorum,\n\t\t\t\t\t\tbaseSnapshot,\n\t\t\t\t\t\tasync (id) => runtime.storage.readBlob(id),\n\t\t\t\t\t\tshouldTrackAttribution,\n\t\t\t\t\t);\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\tattributionEnabledInConfig: shouldTrackAttribution,\n\t\t\t\t\t\tattributionEnabledInDoc: runtime.runtimeAttributor\n\t\t\t\t\t\t\t? runtime.runtimeAttributor.isEnabled\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn runtime;\n\t\t}\n\n\t\tprivate runtimeAttributor: RuntimeAttributor | undefined;\n\n\t\tprotected addContainerStateToSummary(\n\t\t\tsummaryTree: ISummaryTreeWithStats,\n\t\t\tfullTree: boolean,\n\t\t\ttrackState: boolean,\n\t\t\ttelemetryContext?: ITelemetryContext,\n\t\t): void {\n\t\t\tsuper.addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext);\n\t\t\tconst attributorSummary = this.runtimeAttributor?.summarize();\n\t\t\tif (attributorSummary) {\n\t\t\t\taddSummarizeResultToSummary(summaryTree, attributorTreeName, attributorSummary);\n\t\t\t}\n\t\t}\n\t} as unknown as typeof ContainerRuntime;\n\nclass RuntimeAttributor implements IRuntimeAttributor {\n\tpublic get IRuntimeAttributor(): IRuntimeAttributor {\n\t\treturn this;\n\t}\n\n\tpublic get(key: AttributionKey): AttributionInfo {\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */,\n\t\t);\n\n\t\tif (key.type === \"detached\") {\n\t\t\tthrow new Error(\"Attribution of detached keys is not yet supported.\");\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\t// Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current\n\t\t\t// client id in the audience. However, for read->write client transition, the container might have not yet\n\t\t\t// received a client id. This is left as a TODO as it might be more easily solved once the detached case\n\t\t\t// is settled (e.g. if it's reasonable for the host to know the current user information at container\n\t\t\t// creation time, we could just use that here as well).\n\t\t\tthrow new Error(\"Attribution of local keys is not yet supported.\");\n\t\t}\n\n\t\treturn this.opAttributor.getAttributionInfo(key.seq);\n\t}\n\n\tpublic has(key: AttributionKey): boolean {\n\t\tif (key.type === \"detached\") {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;\n\t}\n\n\tprivate encoder: Encoder<IAttributor, string> = {\n\t\tencode: unreachableCase,\n\t\tdecode: unreachableCase,\n\t};\n\n\tprivate opAttributor: IAttributor | undefined;\n\tpublic isEnabled = false;\n\n\tpublic async initialize(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tquorum: IQuorumClients,\n\t\tbaseSnapshot: ISnapshotTree | undefined,\n\t\treadBlob: (id: string) => Promise<ArrayBufferLike>,\n\t\tshouldAddAttributorOnNewFile: boolean,\n\t): Promise<void> {\n\t\tconst attributorTree = baseSnapshot?.trees[attributorTreeName];\n\t\t// Existing documents that don't already have a snapshot containing runtime attribution info shouldn't\n\t\t// inject any for now--this causes some back-compat integration problems that aren't fully worked out.\n\t\tconst shouldExcludeAttributor =\n\t\t\t(baseSnapshot !== undefined && attributorTree === undefined) ||\n\t\t\t(baseSnapshot === undefined && !shouldAddAttributorOnNewFile);\n\t\tif (shouldExcludeAttributor) {\n\t\t\t// This gives a consistent error for calls to `get` on keys that don't exist.\n\t\t\tthis.opAttributor = new Attributor();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isEnabled = true;\n\t\tthis.encoder = chain(\n\t\t\tnew AttributorSerializer(\n\t\t\t\t(entries) => new OpStreamAttributor(deltaManager, quorum, entries),\n\t\t\t\tdeltaEncoder,\n\t\t\t),\n\t\t\tmakeLZ4Encoder(),\n\t\t);\n\n\t\tif (attributorTree === undefined) {\n\t\t\tthis.opAttributor = new OpStreamAttributor(deltaManager, quorum);\n\t\t} else {\n\t\t\tconst id = attributorTree.blobs[opBlobName];\n\t\t\tassert(\n\t\t\t\tid !== undefined,\n\t\t\t\t0x50a /* Attributor tree should have op attributor summary blob. */,\n\t\t\t);\n\t\t\tconst blobContents = await readBlob(id);\n\t\t\tconst attributorSnapshot = bufferToString(blobContents, \"utf8\");\n\t\t\tthis.opAttributor = this.encoder.decode(attributorSnapshot);\n\t\t}\n\t}\n\n\tpublic summarize(): ISummaryTreeWithStats | undefined {\n\t\tif (!this.isEnabled) {\n\t\t\t// Loaded existing document without attributor data: avoid injecting any data.\n\t\t\treturn undefined;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x50b /* RuntimeAttributor should be initialized before summarization */,\n\t\t);\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));\n\t\treturn builder.getSummaryTree();\n\t}\n}\n"]}
|
package/lib/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-experimental/attributor",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.4.0.1",
|
|
4
4
|
"description": "Operation attributor",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -47,33 +47,33 @@
|
|
|
47
47
|
"temp-directory": "nyc/.nyc_output"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@fluid-internal/client-utils": ">=2.0.0-rc.
|
|
51
|
-
"@fluidframework/container-definitions": ">=2.0.0-rc.
|
|
52
|
-
"@fluidframework/container-runtime": ">=2.0.0-rc.
|
|
53
|
-
"@fluidframework/container-runtime-definitions": ">=2.0.0-rc.
|
|
54
|
-
"@fluidframework/core-interfaces": ">=2.0.0-rc.
|
|
55
|
-
"@fluidframework/core-utils": ">=2.0.0-rc.
|
|
56
|
-
"@fluidframework/datastore-definitions": ">=2.0.0-rc.
|
|
50
|
+
"@fluid-internal/client-utils": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
51
|
+
"@fluidframework/container-definitions": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
52
|
+
"@fluidframework/container-runtime": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
53
|
+
"@fluidframework/container-runtime-definitions": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
54
|
+
"@fluidframework/core-interfaces": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
55
|
+
"@fluidframework/core-utils": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
56
|
+
"@fluidframework/datastore-definitions": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
57
57
|
"@fluidframework/protocol-definitions": "^3.2.0",
|
|
58
|
-
"@fluidframework/runtime-definitions": ">=2.0.0-rc.
|
|
59
|
-
"@fluidframework/runtime-utils": ">=2.0.0-rc.
|
|
60
|
-
"@fluidframework/telemetry-utils": ">=2.0.0-rc.
|
|
58
|
+
"@fluidframework/runtime-definitions": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
59
|
+
"@fluidframework/runtime-utils": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
60
|
+
"@fluidframework/telemetry-utils": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
61
61
|
"lz4js": "^0.2.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@arethetypeswrong/cli": "^0.15.2",
|
|
65
65
|
"@biomejs/biome": "^1.6.2",
|
|
66
|
-
"@fluid-internal/mocha-test-setup": ">=2.0.0-rc.
|
|
67
|
-
"@fluid-private/stochastic-test-utils": ">=2.0.0-rc.
|
|
68
|
-
"@fluid-tools/build-cli": "^0.
|
|
66
|
+
"@fluid-internal/mocha-test-setup": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
67
|
+
"@fluid-private/stochastic-test-utils": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
68
|
+
"@fluid-tools/build-cli": "^0.38.0",
|
|
69
69
|
"@fluidframework/build-common": "^2.0.3",
|
|
70
|
-
"@fluidframework/build-tools": "^0.
|
|
71
|
-
"@fluidframework/driver-definitions": ">=2.0.0-rc.
|
|
70
|
+
"@fluidframework/build-tools": "^0.38.0",
|
|
71
|
+
"@fluidframework/driver-definitions": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
72
72
|
"@fluidframework/eslint-config-fluid": "^5.1.0",
|
|
73
|
-
"@fluidframework/merge-tree": ">=2.0.0-rc.
|
|
74
|
-
"@fluidframework/sequence": ">=2.0.0-rc.
|
|
75
|
-
"@fluidframework/test-runtime-utils": ">=2.0.0-rc.
|
|
76
|
-
"@microsoft/api-extractor": "^7.
|
|
73
|
+
"@fluidframework/merge-tree": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
74
|
+
"@fluidframework/sequence": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
75
|
+
"@fluidframework/test-runtime-utils": ">=2.0.0-rc.4.0.1 <2.0.0-rc.4.1.0",
|
|
76
|
+
"@microsoft/api-extractor": "^7.43.1",
|
|
77
77
|
"@types/mocha": "^9.1.1",
|
|
78
78
|
"@types/node": "^18.19.0",
|
|
79
79
|
"c8": "^8.0.1",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"test:mocha:esm": "mocha --recursive \"lib/test/**/*.spec.*js\" --exit",
|
|
120
120
|
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
121
121
|
"tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
|
|
122
|
-
"typetests:gen": "
|
|
122
|
+
"typetests:gen": "flub generate typetests --dir . -v --publicFallback",
|
|
123
123
|
"typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
|
|
124
124
|
}
|
|
125
125
|
}
|
package/src/attributor.ts
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { type
|
|
6
|
+
import { type IDeltaManager } from "@fluidframework/container-definitions/internal";
|
|
7
7
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
8
8
|
import {
|
|
9
|
+
MessageType,
|
|
9
10
|
type IDocumentMessage,
|
|
11
|
+
type IQuorumClients,
|
|
10
12
|
type ISequencedDocumentMessage,
|
|
11
13
|
} from "@fluidframework/protocol-definitions";
|
|
12
14
|
import { type AttributionInfo } from "@fluidframework/runtime-definitions/internal";
|
|
@@ -41,7 +43,6 @@ export interface IAttributor {
|
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
45
|
* {@inheritdoc IAttributor}
|
|
44
|
-
* @internal
|
|
45
46
|
*/
|
|
46
47
|
export class Attributor implements IAttributor {
|
|
47
48
|
protected readonly keyToInfo: Map<number, AttributionInfo>;
|
|
@@ -82,26 +83,27 @@ export class Attributor implements IAttributor {
|
|
|
82
83
|
/**
|
|
83
84
|
* Attributor which listens to an op stream and records entries for each op.
|
|
84
85
|
* Sequence numbers are used as attribution keys.
|
|
85
|
-
* @internal
|
|
86
86
|
*/
|
|
87
87
|
export class OpStreamAttributor extends Attributor implements IAttributor {
|
|
88
88
|
public constructor(
|
|
89
89
|
deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,
|
|
90
|
-
|
|
90
|
+
quorumClients: IQuorumClients,
|
|
91
91
|
initialEntries?: Iterable<[number, AttributionInfo]>,
|
|
92
92
|
) {
|
|
93
93
|
super(initialEntries);
|
|
94
94
|
deltaManager.on("op", (message: ISequencedDocumentMessage) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
if (message.type === MessageType.Operation) {
|
|
96
|
+
assert(
|
|
97
|
+
typeof message.clientId === "string",
|
|
98
|
+
0x966 /* Client id should be present and should be of type string */,
|
|
99
|
+
);
|
|
100
|
+
const client = quorumClients.getMember(message.clientId);
|
|
99
101
|
assert(
|
|
100
102
|
client !== undefined,
|
|
101
|
-
|
|
103
|
+
0x967 /* Received message from user not in the quorumClients */,
|
|
102
104
|
);
|
|
103
105
|
this.keyToInfo.set(message.sequenceNumber, {
|
|
104
|
-
user: client.user,
|
|
106
|
+
user: client.client.user,
|
|
105
107
|
timestamp: message.timestamp,
|
|
106
108
|
});
|
|
107
109
|
}
|
package/src/index.ts
CHANGED
package/src/mixinAttributor.ts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { bufferToString } from "@fluid-internal/client-utils";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
type IDeltaManager,
|
|
9
|
+
type IContainerContext,
|
|
10
|
+
} from "@fluidframework/container-definitions/internal";
|
|
9
11
|
import { ContainerRuntime } from "@fluidframework/container-runtime/internal";
|
|
10
12
|
import type { IContainerRuntimeOptions } from "@fluidframework/container-runtime/internal";
|
|
11
13
|
import { type IContainerRuntime } from "@fluidframework/container-runtime-definitions/internal";
|
|
@@ -13,6 +15,7 @@ import { type FluidObject, type IRequest, type IResponse } from "@fluidframework
|
|
|
13
15
|
import { assert, unreachableCase } from "@fluidframework/core-utils/internal";
|
|
14
16
|
import {
|
|
15
17
|
type IDocumentMessage,
|
|
18
|
+
type IQuorumClients,
|
|
16
19
|
type ISequencedDocumentMessage,
|
|
17
20
|
type ISnapshotTree,
|
|
18
21
|
} from "@fluidframework/protocol-definitions";
|
|
@@ -82,6 +85,7 @@ export interface IRuntimeAttributor extends IProvideRuntimeAttributor {
|
|
|
82
85
|
|
|
83
86
|
/**
|
|
84
87
|
* @returns Whether the runtime is currently tracking attribution information for the loaded container.
|
|
88
|
+
* If enabled, the runtime attributor can be asked for the attribution info for different keys.
|
|
85
89
|
* See {@link mixinAttributor} for more details on when this happens.
|
|
86
90
|
*/
|
|
87
91
|
readonly isEnabled: boolean;
|
|
@@ -152,10 +156,10 @@ export const mixinAttributor = (
|
|
|
152
156
|
const baseSnapshot: ISnapshotTree | undefined =
|
|
153
157
|
pendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;
|
|
154
158
|
|
|
155
|
-
const {
|
|
159
|
+
const { quorum, deltaManager, taggedLogger } = context;
|
|
156
160
|
assert(
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
quorum !== undefined,
|
|
162
|
+
0x968 /* quorum must exist when instantiating attribution-providing runtime */,
|
|
159
163
|
);
|
|
160
164
|
|
|
161
165
|
const mc = loggerToMonitoringContext(taggedLogger);
|
|
@@ -197,7 +201,7 @@ export const mixinAttributor = (
|
|
|
197
201
|
async (event) => {
|
|
198
202
|
await runtime.runtimeAttributor?.initialize(
|
|
199
203
|
deltaManager,
|
|
200
|
-
|
|
204
|
+
quorum,
|
|
201
205
|
baseSnapshot,
|
|
202
206
|
async (id) => runtime.storage.readBlob(id),
|
|
203
207
|
shouldTrackAttribution,
|
|
@@ -279,7 +283,7 @@ class RuntimeAttributor implements IRuntimeAttributor {
|
|
|
279
283
|
|
|
280
284
|
public async initialize(
|
|
281
285
|
deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,
|
|
282
|
-
|
|
286
|
+
quorum: IQuorumClients,
|
|
283
287
|
baseSnapshot: ISnapshotTree | undefined,
|
|
284
288
|
readBlob: (id: string) => Promise<ArrayBufferLike>,
|
|
285
289
|
shouldAddAttributorOnNewFile: boolean,
|
|
@@ -299,14 +303,14 @@ class RuntimeAttributor implements IRuntimeAttributor {
|
|
|
299
303
|
this.isEnabled = true;
|
|
300
304
|
this.encoder = chain(
|
|
301
305
|
new AttributorSerializer(
|
|
302
|
-
(entries) => new OpStreamAttributor(deltaManager,
|
|
306
|
+
(entries) => new OpStreamAttributor(deltaManager, quorum, entries),
|
|
303
307
|
deltaEncoder,
|
|
304
308
|
),
|
|
305
309
|
makeLZ4Encoder(),
|
|
306
310
|
);
|
|
307
311
|
|
|
308
312
|
if (attributorTree === undefined) {
|
|
309
|
-
this.opAttributor = new OpStreamAttributor(deltaManager,
|
|
313
|
+
this.opAttributor = new OpStreamAttributor(deltaManager, quorum);
|
|
310
314
|
} else {
|
|
311
315
|
const id = attributorTree.blobs[opBlobName];
|
|
312
316
|
assert(
|