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

feat(container-loader): Allow setting the container's logger at load time #13779

Merged
merged 11 commits into from
Feb 3, 2023

Conversation

tylerbutler
Copy link
Member

@tylerbutler tylerbutler commented Jan 24, 2023

Feature: set container logger at load time

Developers can now specify a logger that should be used by a container when it is loaded instead of always using the Loader's logger (Loader.services.subLogger).

Use cases and scenarios

Today a container's logger is set based on the logger used in the Loader. This is not ideal in nested container scenarios, where a container is loading a data store within another container, which is itself within another container. Apps/hosts often augment the logger from the loader when loading a container, and when loading a nested container, it makes sense to provide an augmented logger to the container directly rather than using the one from the loader.

Implementation details

This PR enables the scenario by adding a fluid-base-logger request header to the container load request. If set, then the container's subLogger will be set to the header value. If the override isn't set, then the container will use the loader's logger as it does today.

For completeness, we should add a header to the LoaderHeaders enum. Doing so is a breaking change, though, so that will be done in a future commit.

@github-actions github-actions bot added the base: next PRs targeted against next branch label Jan 24, 2023
@tylerbutler tylerbutler changed the title feat(container-loader,container-runtime): Allow setting the container's logger at load time feat(container-loader): Allow setting the container's logger at load time Jan 24, 2023
@@ -542,6 +542,9 @@ export enum LoaderHeader {
reconnect = "fluid-reconnect",
sequenceNumber = "fluid-sequence-number",

// BREAKING CHANGE -- TODO: figure this out
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a breaking change to add a new enum value? I would expect all usages to be against specific enums but maybe there's something I'm not thinking of.

Copy link
Member Author

@tylerbutler tylerbutler Jan 24, 2023

Choose a reason for hiding this comment

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

Enums are a pain from a back-compat perspective. Adding a new value creates type incompatibility between the enum type. For example in our type testing code, this blows up if I add an enum value:

declare function get_current_EnumDeclaration_LoaderHeader():
    TypeOnly<current.LoaderHeader>;
declare function use_old_EnumDeclaration_LoaderHeader(
    use: TypeOnly<old.LoaderHeader>);
use_old_EnumDeclaration_LoaderHeader(
    get_current_EnumDeclaration_LoaderHeader());
Argument of type 'TypeOnly<import("/home/tylerbu/code/release-1/packages/common/container-definitions/src/loader").LoaderHeader>' is not assignable to parameter of type 'TypeOnly<import("/home/tylerbu/code/release-1/node_modules/@fluidframework/container-definitions-previous/dist/loader").LoaderHeader>'.
  Type 'LoaderHeader.cache' is not assignable to type 'TypeOnly<LoaderHeader>'.

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh interesting, right, because one definition does not fit into the other. I wonder if we should come up with a general coding recommendation to avoid these

Copy link

Choose a reason for hiding this comment

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

Yes, enums are not mapping to native JS. I think we have explored two alternatives: string unions (mostly on string types) and objects pattern. ex: https://github.com/microsoft/FluidFramework/pull/10149/files. I don't think we have concluded on one pattern fits all.

@msfluid-bot
Copy link
Collaborator

msfluid-bot commented Jan 24, 2023

@fluid-example/bundle-size-tests: +140 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 425.53 KB 425.53 KB No change
connectionState.js 680 Bytes 680 Bytes No change
containerRuntime.js 220.09 KB 220.09 KB No change
loader.js 158.66 KB 158.8 KB +140 Bytes
map.js 43.85 KB 43.85 KB No change
matrix.js 136.17 KB 136.17 KB No change
odspDriver.js 91.14 KB 91.14 KB No change
odspPrefetchSnapshot.js 42.43 KB 42.43 KB No change
sharedString.js 156.93 KB 156.93 KB No change
Total Size 1.35 MB 1.35 MB +140 Bytes

Baseline commit: 5d071c6

Generated by 🚫 dangerJS against a902e91

@github-actions github-actions bot added area: build Build related issues area: dds Issues related to distributed data structures area: dds: propertydds area: dds: sharedstring area: dds: tree area: dev experience Improving the experience of devs building on top of fluid area: driver Driver related issues area: examples Changes that focus on our examples area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct area: loader Loader related issues area: odsp-driver area: runtime Runtime related issues area: tests Tests to add, test infrastructure improvements, etc public api change Changes to a public API labels Jan 30, 2023
@github-actions github-actions bot removed area: odsp-driver area: dds: propertydds area: build Build related issues area: runtime Runtime related issues area: tests Tests to add, test infrastructure improvements, etc area: dds Issues related to distributed data structures area: driver Driver related issues area: dds: tree area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct area: dds: sharedstring labels Jan 30, 2023
@tylerbutler tylerbutler changed the base branch from next to main January 30, 2023 22:56
@github-actions github-actions bot added base: main PRs targeted against main branch and removed base: next PRs targeted against next branch labels Jan 31, 2023
@tylerbutler tylerbutler marked this pull request as ready for review January 31, 2023 19:10
@tylerbutler tylerbutler requested a review from a team as a code owner January 31, 2023 19:10
Copy link
Contributor

@vladsud vladsud left a comment

Choose a reason for hiding this comment

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

Signing-off but starting a thread on future of Loader as concept.
Let's have a discussion first if we want to keep adding here, or start removing :)

@tylerbutler
Copy link
Member Author

I'm going to merge this because that will "lock in" the change and make it easiest to port to the release branch (less churn to worry about). If it's needed in a patch porting it should be straightforward and quick. Otherwise, we have until next week to change our minds and back it out before our internal 3.1 release.

@tylerbutler tylerbutler merged commit 84755f0 into microsoft:main Feb 3, 2023
@tylerbutler tylerbutler deleted the loop/logger branch February 3, 2023 00:25
tylerbutler added a commit to tylerbutler/FluidFramework that referenced this pull request Feb 3, 2023
…time (microsoft#13779)

Developers can now specify a logger that should be used by a container
when it is loaded instead of always using the Loader's logger
(`Loader.services.subLogger`).

Today a container's logger is set based on the logger used in the
Loader. This is not ideal in nested container scenarios, where a
container is loading a data store within another container, which is
itself within another container. Apps/hosts often augment the logger
from the loader when loading a container, and when loading a nested
container, it makes sense to provide an augmented logger to the
container directly rather than using the one from the loader.

This PR enables the scenario by adding a `fluid-base-logger` request
header to the container load request. If set, then the container's
`subLogger` will be set to the header value. If the override isn't set,
then the container will use the loader's logger as it does today.

For completeness, we should add a header to the LoaderHeaders enum.
Doing so is a breaking change, though, so that will be done in a future
commit.
tylerbutler added a commit that referenced this pull request Feb 3, 2023
…time (#14005)

Cherry-pick of #13779 to the 3.0 release branch.

Developers can now specify a logger that should be used by a container
when it is loaded instead of always using the Loader's logger
(`Loader.services.subLogger`).

Today a container's logger is set based on the logger used in the
Loader. This is not ideal in nested container scenarios, where a
container is loading a data store within another container, which is
itself within another container. Apps/hosts often augment the logger
from the loader when loading a container, and when loading a nested
container, it makes sense to provide an augmented logger to the
container directly rather than using the one from the loader.

This PR enables the scenario by adding a `fluid-base-logger` request
header to the container load request. If set, then the container's
`subLogger` will be set to the header value. If the override isn't set,
then the container will use the loader's logger as it does today.
daesun-park pushed a commit to daesun-park/FluidFramework that referenced this pull request Feb 8, 2023
…time (microsoft#13779)

## Feature: set container logger at load time

Developers can now specify a logger that should be used by a container
when it is loaded instead of always using the Loader's logger
(`Loader.services.subLogger`).

## Use cases and scenarios

Today a container's logger is set based on the logger used in the
Loader. This is not ideal in nested container scenarios, where a
container is loading a data store within another container, which is
itself within another container. Apps/hosts often augment the logger
from the loader when loading a container, and when loading a nested
container, it makes sense to provide an augmented logger to the
container directly rather than using the one from the loader.

## Implementation details

This PR enables the scenario by adding a `fluid-base-logger` request
header to the container load request. If set, then the container's
`subLogger` will be set to the header value. If the override isn't set,
then the container will use the loader's logger as it does today.

For completeness, we should add a header to the LoaderHeaders enum.
Doing so is a breaking change, though, so that will be done in a future
commit.
ChumpChief added a commit that referenced this pull request Feb 10, 2023
…ntime initialization (#14114)

Related: #13779 

Currently, the scope is set once (at Loader creation time). However,
it's possible hosts may want to pass different scope information on a
per-resolve basis. This is particularly true when the load is performed
in a different context, e.g. a top-level container vs. loading a "guest"
container as a sub-part of an experience.

Normally we recommend against using scope, but it does serve a purpose
here of allowing hosts to pass objects to their container runtime at
initialization time. Since the initialization phase (instantiateRuntime)
is buried in the Container, this is the best entrypoint we currently
make available for host customization of that initialization.
ChumpChief added a commit that referenced this pull request Feb 13, 2023
From #14114 

Also a bit of #13779 that was missed in #14005
ChumpChief added a commit that referenced this pull request Feb 16, 2023
…4216)

This change removes the features added in #13779 and #14114, as we've
determined they are not actually needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: loader Loader related issues base: main PRs targeted against main branch public api change Changes to a public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants