-
Notifications
You must be signed in to change notification settings - Fork 483
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 support for SignalR emulator #6793
base: main
Are you sure you want to change the base?
Conversation
<ItemGroup> | ||
<ProjectReference Include="..\Aspire.Hosting.Azure\Aspire.Hosting.Azure.csproj" /> | ||
<PackageReference Include="Azure.Provisioning" /> | ||
<PackageReference Include="Azure.Provisioning.SignalR" /> | ||
<PackageReference Include="Microsoft.Azure.SignalR.Management" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a little bit heavy dependency, is it possible to not dependent on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the convention for other services is to use the Service SDK to init a client for healthcheck. In my opinion, it looks more clean that way as well. Also the tests use this SDK to get negotiate URL as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Microsoft.Azure.SignalR.Management is a little bit different story, and it references Microsoft.Azure.SignalR which references aspnetcore SignalR. It sounds too much for a project doing the service provisioning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay makes sense, I'll just try using REST API for the health check in the main code, and maybe use this Management SDK to perform the tests since it's more complicated to test with using just REST API
healthCheckKey, | ||
sp => { | ||
// Use SignalR Management SDK to init a client for health test | ||
var client = new ServiceManagerBuilder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does a simple http call work?
@@ -23,5 +31,7 @@ public class AzureSignalRResource(string name, Action<AzureResourceInfrastructur | |||
/// Gets the connection string template for the manifest for Azure SignalR. | |||
/// </summary> | |||
public ReferenceExpression ConnectionStringExpression => | |||
ReferenceExpression.Create($"Endpoint=https://{HostName};AuthType=azure"); | |||
IsEmulator | |||
? ReferenceExpression.Create($"Endpoint={EmulatorEndpoint.Property(EndpointProperty.Scheme)}://{EmulatorEndpoint.Property(EndpointProperty.Host)}:{EmulatorEndpoint.Property(EndpointProperty.Port)};AccessKey=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGH;Version=1.0;") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we update the emulator to not dependent on "AccessKey" so that we don't need to have the AccessKey in code although it is fake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert the comment. Emulator could be working in an isolated environment, so Microsoft Entra ID should not be a dependency when using Emulator. AccessKey is a best choice for existing SDKs to work seamlessly.
<ItemGroup> | ||
<ProjectReference Include="..\Aspire.Hosting.Azure\Aspire.Hosting.Azure.csproj" /> | ||
<PackageReference Include="Azure.Provisioning" /> | ||
<PackageReference Include="Azure.Provisioning.SignalR" /> | ||
<PackageReference Include="Microsoft.Azure.SignalR.Management" /> | ||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need the signalr client reference? Looks like it's only used in a test, so shouldn't the reference be on the test project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, let me move it to test project
@cqnguy23 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), 1. Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, “Project” means any of the projects owned or managed by .NET Foundation and offered under a license “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any “Submission” means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant .NET Foundation, and those who receive the Submission directly b. Patent License. You grant .NET Foundation, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to .NET Foundation. You agree to notify .NET Foundation in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and .NET Foundation dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. |
@@ -59,4 +63,61 @@ public static IResourceBuilder<AzureSignalRResource> AddAzureSignalR(this IDistr | |||
.WithParameter(AzureBicepResource.KnownParameters.PrincipalType) | |||
.WithManifestPublishingCallback(resource.WriteToManifest); | |||
} | |||
|
|||
/// <summary> | |||
/// Configures an Azure SignalR resource to be emulated. This resource requires an <see cref="AzureSignalRResource"/> to be added to the application model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also emphasize in the comment that the emulator is for Serverless only
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra line
namespace Aspire.Hosting.Azure.Tests; | ||
public class AzureSignalREmulatorFunctionalTest(ITestOutputHelper testOutputHelper) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra line
/// <param name="builder">The Azure storage resource builder.</param> | ||
/// <param name="configureContainer">Callback that exposes underlying container used for emulation to allow for customization.</param> | ||
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns> | ||
public static IResourceBuilder<AzureSignalRResource> RunAsEmulator(this IResourceBuilder<AzureSignalRResource> builder, Action<IResourceBuilder<AzureSignalREmulatorResource>>? configureContainer = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also showing how to use RunAsEmulator in the signalr playground project
using Xunit.Abstractions; | ||
|
||
namespace Aspire.Hosting.Azure.Tests; | ||
public class AzureSignalREmulatorFunctionalTest(ITestOutputHelper testOutputHelper) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add test to check the if the connectionString is expected, similar test see AzureBicepResourceTests.AddAzureCosmosDBEmulator
{ | ||
return builder; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we do some check here to make sure the SignalR service is in Serverless mode?
builder.ConfigureInfrastructure(i =>
{
// Get the SignalRService set by AddAzureSignalR
var resource = i.GetProvisionableResources().OfType<SignalRService>().First(s => s.BicepIdentifier == i.AspireResource.GetBicepIdentifier());
// check if the serviceMode is Serverless
if (resource.Features.Any(feature => feature.Value != null && feature.Value.Flag.Value == SignalRFeatureFlag.ServiceMode && feature.Value.Value.Value != null && feature.Value.Value.Value.Equals("Serverless", StringComparison.OrdinalIgnoreCase)))
{
return;
}
else
{
throw new InvalidOperationException("Emulator works only for Azure SignalR Serverless mode");
}
});
Description
Fixes # (issue)
Checklist
<remarks />
and<code />
elements on your triple slash comments?breaking-change
template):doc-idea
template):Microsoft Reviewers: Open in CodeFlow
Addresses issue #6676