Wait for and resource health logging isn't visible
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
WaitUntilHealthyAsync and WaitUntilCompletionAsync write to a logger to report status, but the logs aren't visible in the console logs.
The problem is they call GetLogger(IResource) to get a logger, but this logger doesn't include the full resource name with the unique suffix.
e.g. the wait methods write to a logger called basketservice but DCP logs go to, and the dashboard UI gets logs from basketservice-abcxyz.
Expected Behavior
Wait for logs are visible in console logs from the dashboard.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version info
No response
Anything else?
No response
Things work great if you fetch a logger with the complete resource name, e.g. basketservice-abcxyz, like is done when executing a resource command. But it doesn't work when getting a logger using IResource, which just uses name, e.g. basketservice. Because the dashboard uses the complete name, logs written to basketservice are never viewed. WaitFor is getting a logger like this so its logs aren't visible once the resource actually starts. I logged an issue about it: https://github.com/dotnet/aspire/issues/5908
Idea to fix:
The problem is resources have a name that changes when DCP starts. Before: basketservice, After: basketservice-abcxyz. I suggest we fix this by not waiting for a DCP resource to start before generating the complete name. The random suffix is already generated in the host. We can generate this earlier when the model type is created and store it in an annotation. If something is a replica, we can generated multiple at once. This would be like doing what ReplicaInstancesAnnotation does, except in advance instead of waiting for the resource to be returned from DCP watch.
Once we have that annotation, when someone calls GetLogger(IResource), we can resolve the complete name and log to the correct place. If there are multiple replicas then we can return an ILogger that wraps multiple loggers for the different instances so logs are fanned out to all replicas. The complete name would also be sent to the dashboard so it would view the correct console logs by passing the complete name.
This was addressed by https://github.com/dotnet/aspire/pull/6080 and https://github.com/dotnet/aspire/pull/6069