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

Add AzureFunctionsEndToEnd with prototype implementation #5418

Merged
merged 54 commits into from
Sep 7, 2024

Conversation

captainsafia
Copy link
Member

@captainsafia captainsafia commented Aug 24, 2024

This PR introduces an AzureFunctionsEndToEnd sample application with prototype implementations of certain APIs:

  • APIs that currently target IHostApplicationBuilder have been reimplemented to target HostBuilder. This should be addressed on Azure Functions supports IHostApplicationBuilder.
  • A custom AzureFunctionsProjectResource has been included that launches the func host as an executable resource. This is a temporary implementation until we support modeling a Functions application as a project resource. These APIs are formally proposed in Add AzureFunctionsProjectResource and extension methods #5412. Support for mocking the Functions app as a project resource can be added by updating the mock API definitions as follows:
public class AzureFunctionsProjectResource(string name) 
    : ProjectResource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithServiceDiscovery { }

public static class AzureFunctionsProjectResourceExtensions
  public static IResourceBuilder<FunctionAppResource> AddAzureFunctionsProject<TProject>(this IDistributedApplicationBuilder builder, string name) where TProject : IProjectMetadata, new()
    {
        var projectDirectory = Path.GetDirectoryName(new TProject().ProjectPath)!;
        var resource = new AzureFunctionsProjectResource(name);
        return builder.AddResource(resource)
            .WithAnnotation(new TProject())
            .WithHttpEndpoint(name: "http", env: "AZFUNCHOSTPORT")
            .WithEnvironment("FUNCTIONS_WORKER_RUNTIME", "dotnet-isolated")
            .WithEnvironment("OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES", "true")
            .WithEnvironment("OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES", "true")
            .WithEnvironment("OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY", "in_memory")
            .WithEnvironment("ASPNETCORE_FORWARDEDHEADERS_ENABLED", "true")
            .WithEnvironment("FUNCTIONS_WORKER_RUNTIME", "dotnet-isolated")
            .WithOtlpExporter()
            .WithManifestPublishingCallback(async (context) => {
                context.Writer.WriteString("type", "function.v0");
                context.Writer.WriteString("path", context.GetManifestRelativePath(new TProject().ProjectPath));
                await context.WriteEnvironmentVariablesAsync(resource);
                context.Writer.WriteStartObject("bindings");
                foreach (var s in new string[]{ "http", "https"}) {
                    context.Writer.WriteStartObject(s);
                    context.Writer.WriteString("scheme", s);
                    context.Writer.WriteString("protocol", "tcp");
                    context.Writer.WriteString("transport", "http");
                    context.Writer.WriteBoolean("external", true);
                    context.Writer.WriteEndObject();
                }
                context.Writer.WriteEndObject();
            });
    }
}

And making the following changes to AzureFunctionsEndToEnd.Functions.csproj:

  <PropertyGroup>
    <RunCommand>func</RunCommand>
    <RunArguments>start --no-build --csharp --verbose --worker-runtime dotnetIsolated --port $(AZFUNCHOSTPORT)</RunArguments>
     <RunWorkingDirectory>bin/output</RunWorkingDirectory>
  </PropertyGroup>
Microsoft Reviewers: Open in CodeFlow

Fixes #5412
Fixes #5408

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-integrations Issues pertaining to Aspire Integrations packages label Aug 24, 2024
@radical
Copy link
Member

radical commented Aug 24, 2024

A test should be added for this too, see #5316 for an example.

@davidfowl
Copy link
Member

I'm not sure we want to test this sample yet. This is part of bootstrapping the azure functions work.

{
services.AddOpenTelemetry()
.UseFunctionsWorkerDefaults()
.UseOtlpExporter();
Copy link
Member

Choose a reason for hiding this comment

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

How come this is here and not in .AddServiceDefaults?

Copy link
Member

Choose a reason for hiding this comment

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

IHostBuilder vs IHostApplicationBuilder

Copy link
Member

Choose a reason for hiding this comment

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

AddServiceDefaults (called above) is also implemented in terms of IHostBuilder. It is in the HostBuilderExtensions.cs file.

@captainsafia
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@captainsafia
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@captainsafia
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@captainsafia
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@captainsafia
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@captainsafia
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@captainsafia
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dciborow
Copy link

dciborow commented Sep 7, 2024

standing by ready for to do some testing on our internal project once this is released. Please feel free to reach out - dciborow.

@captainsafia
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@captainsafia
Copy link
Member Author

standing by ready for to do some testing on our internal project once this is released. Please feel free to reach out - dciborow.

Great to hear! I'll give the README another run through today to make sure we've captured all the limitations/setup instructions correctly. This is just the first part of the integration and there will be a few kinks to iron out. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-integrations Issues pertaining to Aspire Integrations packages azure-functions Issues related to the Azure Functions integration
Projects
None yet
5 participants