Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
431 stars 184 forks source link

Refactor func metadata to allow multiple sources #2834

Open jviau opened 1 week ago

jviau commented 1 week ago

Issue describing the changes in this PR

resolves #1159

Pull request checklist

Additional information

NOTE: Tests are not updated yet. Will invest the effort on that when/if we accept this approach.

This PR refactors function metadata flow to allow for multiple sources. The general idea is now DefaultFunctionMetadataProvider is now registered as a primary provider, even with source gen. Source gen sets an internal options value which will change the behavior of DefaultFunctionMetadataProvider to skip scanning function.metadata, and only return results from IFunctionMetadataSource implementations. Source gen is now one of those sources.

Concretely, the changes are:

  1. Introduce IFunctionMetadataSource - a new extensibility contract that is expected to be 0 to N implementations by extensions, customers, etc. This allows for providing custom function metadata which is not the typical [Function(name)] flow. IE: durable can now give metadata to directly invoke class-based orchestrations and activities.
  2. Source gen now generates IFunctionMetadataSource along with IFunctionMetadataProvider (provider contract no longer used for this type).
  3. DefaultFunctionMetadataProvider is now updated to perform the following:
    • Unless disabled via options, will scan and provide metadata from functions.metadata file.
    • Aggregates results from all registered IFunctionMetadataSource.

Benefits

This approach offers a significant benefit of being compatible with newer versions of DotnetWorker.Core and old versions of Sdk.Generators. As in this case, we will still outright replace the implementation of IFunctionMetadataProvider with the source-gen implementation. This is a very real scenario customers could get into, and avoiding a subtle behavior regression here is important.

Concerns