-
Notifications
You must be signed in to change notification settings - Fork 524
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 custom application model for EventHubs emulator #7005
Conversation
@@ -148,8 +148,7 @@ public static IResourceBuilder<AzureEventHubsResource> RunAsEmulator(this IResou | |||
return builder; | |||
} | |||
|
|||
var configHostFile = Path.Combine(Path.GetTempPath(), "AspireEventHubsEmulator", Path.GetRandomFileName() + ".json"); | |||
Directory.CreateDirectory(Path.GetDirectoryName(configHostFile)!); | |||
var configHostFile = Path.Combine(Directory.CreateTempSubdirectory("AspireEventHubsEmulator").FullName, "Config.json"); |
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.
@eerhardt Longer term we should have a service for doing this that gets cleaned up on exit. @karolz-ms maybe something DCP can provide since it controls the clean up.
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.
Definitely. For example, I can imagine us having the capability for Containers where you can say "here is a blob of JSON that I need to appear as file inside the container, under this path". Sort of like Kubernetes ConfigMaps.
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.
Opened #7029 to track.
This will resolve #5561. |
namespace Aspire.Hosting.Azure.EventHubs; | ||
|
||
/// <summary> | ||
/// Represents an annotation for updating the JSON content of a mounted document. |
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.
What does "a mounted document" mean?
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.
The Config.json file (json document) that is mounted to the container using ContainerMountType.BindMount.
@@ -148,8 +148,7 @@ public static IResourceBuilder<AzureEventHubsResource> RunAsEmulator(this IResou | |||
return builder; | |||
} | |||
|
|||
var configHostFile = Path.Combine(Path.GetTempPath(), "AspireEventHubsEmulator", Path.GetRandomFileName() + ".json"); | |||
Directory.CreateDirectory(Path.GetDirectoryName(configHostFile)!); | |||
var configHostFile = Path.Combine(Directory.CreateTempSubdirectory("AspireEventHubsEmulator").FullName, "Config.json"); |
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.
Opened #7029 to track.
|
||
writer.WriteStartObject(); // { | ||
writer.WriteString("Name", hub); // "Name": "hub", | ||
writer.WriteString("PartitionCount", "2"); // "PartitionCount": "2", |
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.
We used to have "2" as the default, but hub.WriteJsonObjectProperties
now writes "1" by default.
Is this intentional?
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.
AFAIR it was 2 because of the sample they provided. But since the schema states [1-32] I decided to use 1 when the value is not set explicitly.
/// <param name="builder">The builder for the <see cref="AzureEventHubsEmulatorResource"/>.</param> | ||
/// <param name="path">Path to the file on the AppHost where the emulator configuration is located.</param> | ||
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns> | ||
public static IResourceBuilder<AzureEventHubsEmulatorResource> WithConfigurationFile(this IResourceBuilder<AzureEventHubsEmulatorResource> builder, string path) |
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.
Do we have a test for this method?
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.
It was also missing in SB, so I added it. At the same time I tried to simplify the implementation. However I intentionally didn't add support for a custom file provided for config, AND configuration hooks. I would assume if you provide a file, you could have updated it yourself. Hooks are useful when the emulator is generating a file from the resource model and you can't update some section from this model.
|
||
using var builder = TestDistributedApplicationBuilder.Create().WithTestAndResourceLogging(output); | ||
var serviceBus = builder.AddAzureServiceBus("servicebusns") | ||
.RunAsEmulator() | ||
.WithQueue("queue1"); | ||
.WithQueue("queue123"); |
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 this name change?
tests/Aspire.Hosting.Azure.Tests/AzureServiceBusExtensionsTests.cs
Outdated
Show resolved
Hide resolved
tests/Aspire.Hosting.Azure.Tests/AzureServiceBusExtensionsTests.cs
Outdated
Show resolved
Hide resolved
tests/Aspire.Hosting.Azure.Tests/AzureEventHubsExtensionsTests.cs
Outdated
Show resolved
Hide resolved
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.
LGTM once the comments are addressed.
Description
This PR introduces a custom model to configure the emulator and the cloud service.
Counterpart of #6737 for Event Hubs emulator.
Checklist
<remarks />
and<code />
elements on your triple slash comments?breaking-change
template):doc-idea
template):Microsoft Reviewers: Open in CodeFlow