dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.84k stars 462 forks source link

Azure Storage component doesn't work with Azure Storage RunAsEmulator #5078

Closed eerhardt closed 3 months ago

eerhardt commented 3 months ago

Repro Steps

In your AppHost:

var builder = DistributedApplication.CreateBuilder(args);

var blobs = builder.AddAzureStorage("Storage")
    // Use the Azurite storage emulator for local development
    .RunAsEmulator()
    .AddBlobs("BlobConnection");

builder.AddProject<Projects.AspireApp21_Web>("webfrontend")
    .WithExternalHttpEndpoints()
    .WithReference(blobs);

In your webfrontend project:

var builder = WebApplication.CreateBuilder(args);

// Add service defaults & Aspire components.
builder.AddServiceDefaults();

// add this line
builder.AddAzureBlobClient("BlobConnection");

F5

hit the webfrontend/health endpoint

Expected results

Healthy

Actual results

Unhealthy

Logs

      client assembly: Azure.Storage.Blobs
2024-07-25T12:37:42.5405046 warn: Azure.Core[8]
      Error response [ab557070-d043-4751-975d-10a24ee30e85] 400 The API version 2024-08-04 is not supported by Azurite. Please upgrade Azurite to latest version and retry. If you are using Azurite in Visual Studio, please check you have installed latest Visual Studio patch. Azurite command line parameter "--skipApiVersionCheck" or Visual Studio Code configuration "Skip Api Version Check" can skip this error.  (00.0s)
      Server:Azurite-Blob/3.30.0
      x-ms-error-code:InvalidHeaderValue
      x-ms-request-id:d221c3a6-dc25-4191-ab4f-0da95f77d798
      Date:Thu, 25 Jul 2024 17:37:42 GMT
      Connection:keep-alive
      Keep-Alive:REDACTED
      Transfer-Encoding:chunked
      Content-Type:application/xml

2024-07-25T12:37:42.5596003 fail: Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService[103]
      Health check Azure_BlobServiceClient with status Unhealthy completed after 69.5226ms with message '(null)'
      Azure.RequestFailedException: The API version 2024-08-04 is not supported by Azurite. Please upgrade Azurite to latest version and retry. If you are using Azurite in Visual Studio, please check you have installed latest Visual Studio patch. Azurite command line parameter "--skipApiVersionCheck" or Visual Studio Code configuration "Skip Api Version Check" can skip this error. 
RequestId:d221c3a6-dc25-4191-ab4f-0da95f77d798
Time:2024-07-25T17:37:42.527Z
      Status: 400 (The API version 2024-08-04 is not supported by Azurite. Please upgrade Azurite to latest version and retry. If you are using Azurite in Visual Studio, please check you have installed latest Visual Studio patch. Azurite command line parameter "--skipApiVersionCheck" or Visual Studio Code configuration "Skip Api Version Check" can skip this error. )
      ErrorCode: InvalidHeaderValue

If we update to image tag 3.31.0 here, the problem goes away:

https://github.com/dotnet/aspire/blob/e0552c0bbf3330c2694e72961a97941a5773e139/src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs#L114-L119

eerhardt commented 3 months ago

I think this is an issue we would service for in an ideal world.

Workaround is to use:

var blobs = builder.AddAzureStorage("Storage")
    // Use the Azurite storage emulator for local development
    .RunAsEmulator(emulator => emulator.WithImageTag("3.31.0"))
    .AddBlobs("BlobConnection");

cc @mitchdenny @joperezr @sebastienros @radical

radical commented 3 months ago

We hit this earlier too - https://github.com/dotnet/aspire/issues/4646 !

eerhardt commented 3 months ago

We hit this earlier too - #4646 !

We need a test here, if it broke us twice.

joperezr commented 3 months ago

Great find. I agree that we should have a test for this. Is the fix essentially to bump the tag to the new version then? If so we can just do that and ship next month, and folks hitting this can use your workaround.