Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Convert attributor to IFluidDataStoreChannel #22120

Merged
merged 12 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { IModelContainerRuntimeEntryPoint } from "@fluid-example/example-utils";
import { createRuntimeAttributor, mixinAttributor } from "@fluid-experimental/attributor";
import { mixinAttributor } from "@fluid-experimental/attributor";
import {
IContainer,
IContainerContext,
Expand Down Expand Up @@ -54,7 +54,6 @@ export abstract class ModelContainerRuntimeFactoryWithAttribution<ModelType>
this.createModel(containerRuntime, container),
}),
runtimeOptions: this.runtimeOptions,
containerScope: { IRuntimeAttributor: createRuntimeAttributor() },
existing,
});

Expand Down
1 change: 1 addition & 0 deletions packages/framework/attributor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@fluidframework/container-runtime-definitions": "workspace:~",
"@fluidframework/core-interfaces": "workspace:~",
"@fluidframework/core-utils": "workspace:~",
"@fluidframework/datastore": "workspace:~",
"@fluidframework/datastore-definitions": "workspace:~",
"@fluidframework/driver-definitions": "workspace:~",
"@fluidframework/runtime-definitions": "workspace:~",
Expand Down
61 changes: 61 additions & 0 deletions packages/framework/attributor/src/attributorContracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

import {
type AttributionInfo,
type AttributionKey,
} from "@fluidframework/runtime-definitions/internal";

// Summary tree keys
export const opBlobName = "opAttributor";

/**
* @internal
*/
export const enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";

/**
* @internal
*/
export const IRuntimeAttributor: keyof IProvideRuntimeAttributor = "IRuntimeAttributor";

/**
* @internal
*/
export interface IProvideRuntimeAttributor {
readonly IRuntimeAttributor: IRuntimeAttributor;
}

/**
* @internal
*/
export const attributorDataStoreAlias = "attributor-cf9b6fe4-4c50-4a5d-9045-eb73b886f740";

/**
* Provides access to attribution information stored on the container runtime.
*
* @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.
*
* @sealed
* @internal
*/
export interface IRuntimeAttributor extends IProvideRuntimeAttributor {
/**
* @throws - If no AttributionInfo exists for this key.
*/
get(key: AttributionKey): AttributionInfo;

/**
* @returns Whether any AttributionInfo exists for the provided key.
*/
has(key: AttributionKey): boolean;

/**
* @returns Whether the runtime is currently tracking attribution information for the loaded container.
* If enabled, the runtime attributor can be asked for the attribution info for different keys.
* See {@link mixinAttributor} for more details on when this happens.
*/
readonly isEnabled: boolean;
}
6 changes: 3 additions & 3 deletions packages/framework/attributor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/

export { type IAttributor } from "./attributor.js";
export { mixinAttributor, getRuntimeAttributor } from "./mixinAttributor.js";
Copy link
Member

Choose a reason for hiding this comment

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

Are we going to fully remove mixinAttributor in a later change?

Copy link
Member

Choose a reason for hiding this comment

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

All that mixinAttributor does now is override loadRuntime (yay, it doesn't have to mix in summarization stuff anymore!).

All that loadRuntime is doing inside can be flipped around and done outside/around the call to ContainerRuntime.loadRuntime, with one exception - adding the IRuntimeAttributor getter. I don't think we want that anyway - getRuntimeAttributor should be used instead.

So instead of using the mixin pattern, we can just have a helper function loadRuntimeWithAttribution which does everything that the loadRuntime override does, besides messing with the private field (which no longer applies / is needed).

I would not suggest doing this in this PR, but I would suggest/request we do it soon after. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the getter on the container runtime as we can use the utility method to get it. But we do need to mixin as we need to inject the registry and tracking options for the attributor before container runtime is loaded, although we did remove a lot of stuff already.

Copy link
Member

Choose a reason for hiding this comment

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

I think what I'm saying still works though - when you have a minute, try moving ContainerRuntimeWithAttributor.loadRuntime to be a free function. It should work fine and you can remove the whole ContainerRuntimeWithAttributor class.

Then where today callers have to call mixinRuntime and then call loadRuntime on the result, they can instead just call that one function (instead of calling loadRuntime directly)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look here how we use it here in the tests:

The benefit of overriding the ctor is that you can just use the override while creating the runtime factory rather than having to differentiate what to use much later/down the line when the runtime is getting created?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Abe27342 Any suggestions here?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, interesting. Yeah that would take some untangling. Worth doing later IMO, none of this is blocking this PR, the shrinking you did on that mixin is awesome.

export {
createRuntimeAttributor,
attributorDataStoreAlias,
enableOnNewFileKey,
type IProvideRuntimeAttributor,
IRuntimeAttributor,
mixinAttributor,
} from "./mixinAttributor.js";
} from "./attributorContracts.js";
Loading
Loading