dotnet / docs-aspire

This repository contains .NET Aspire documentation.
https://learn.microsoft.com/dotnet/aspire
MIT License
65 stars 70 forks source link

Aspire: Unable to connect to logs and redis #1152

Open AndyWDev opened 1 week ago

AndyWDev commented 1 week ago

I'm just following through the example for creating an Aspire app. I'm using VS17.10.2 and .Net 8.0.100.

The difference is that I have redis and the aspire logs set up in docker containers using the connection settings. I used the settings from the '.Net Aspire Dashboard Overview' for the logs to set up the docker container for that.

The issue I have is that the tutorial starts by showing how things work by pressing F5 to run the logs locally - when it runs it creates a new logs instance (not sure what it does with redis). However, it gives no indication on which files and settings need to be changed to connect to the redis and logs docker containers.

I have found some settings in launchsettings.json but changing these appears to do nothing. Also, there does not seem to be any references as to what code changes are required (say to extensions.cs) on top of settings/connection strings.

Finally, how does the security work with these containers - for the logs F5 connects automatically, but for the stand-alone containers how does one configure the connection login details (same question for redis).

davidfowl commented 1 week ago

The difference is that I have redis and the aspire logs set up in docker containers using the connection settings. I used the settings from the '.Net Aspire Dashboard Overview' for the logs to set up the docker container for that.

Does this mean you used AddConnectionString? Can you share your code?

AndyWDev commented 1 week ago

The difference is that I have redis and the aspire logs set up in docker containers using the connection settings. I used the settings from the '.Net Aspire Dashboard Overview' for the logs to set up the docker container for that.

Does this mean you used AddConnectionString? Can you share your code? Code is straight out of the box - no modifications so far. All I have done is create a separate redis docker container and log container. I'm now trying to work out which settings/code files I need to change so the app when I hit F5 uses them (and connects using appropriate security).

Currently when I press F5 I see from docker that two new containers are being created at runtime on top of the ones I want to use.

davidfowl commented 1 week ago

Can you share the modifications you've made?

davidfowl commented 1 week ago

It might also help if you attached a video or images of what you're running into.

AndyWDev commented 1 week ago

I have not made any. Straight out of the box - so I basically ran the new project wizard and hit F5 as per the documentation to verify the project builds and runs correctly.

The next step is to swap out the dynamically created (redis/log) containers with the stand-alone containers as per the implication in the dashboard standalone documentation section.

However, I can't find any information on what app/host/config/code settings I need to change, Where do I set the host and port number to configure the redis connection to not create a new dynamic container and use the host provided one and how do I configure the security for it (the same questions for the log dashboard).

davidfowl commented 1 week ago

I have not made any. Straight out of the box - so I basically ran the new project wizard and hit F5 as per the documentation to verify the project builds and runs correctly.

Got it! Does it work?

The next step is to swap out the dynamically created (redis/log) containers with the stand-alone containers as per the implication in the dashboard standalone documentation section.

I'm not sure what this means. Can you clarify?

However, I can't find any information on what app/host/config/code settings I need to change, Where do I set the host and port number to configure the redis connection to not create a new dynamic container and use the host provided one and how do I configure the security for it (the same questions for the log dashboard).

If you want to use an existing connection (container or not) then you use https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/external-parameters.

When you connect to existing connections, there are no logs that will show up in the dashboard for said resource.

AndyWDev commented 1 week ago

If it helps, by default, when pressing F5, the app will compile and build and generate new docker containers for redis and for the dashboard automatically. In a distributed environment these may have already been provisioned (as in my case).

Also, under the documentation section App Host - (Orchistration) there is a diagram in the overview topic that implies to achieve this one configures a connection string. and further down there is a section on references - but again, nothing that mentions what files/code to change for redis and the dashboard (I don't use environment variables so am assuming I need to have an appsettings or hostsettings entry of some kind).

davidfowl commented 1 week ago

(I don't use environment variables so am assuming I need to have an appsettings or hostsettings entry of some kind).

Are you using .NET's configuration system? If yes then you are using environment variables as they are configured by default (https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-8.0#default-application-configuration-sources).

AndyWDev commented 1 week ago

Thanks, I appreciate the suggestions although I'm not sure that is related to my original question on 'where is the missing documentation for ...'. However, in terms of discussion, env vars are not used for internal reasons - I was expecting it to handle graceful degradation, so if no env-var then fall back to the appsettings/hostsetting, then fall back to a default value.

It is the same style of architecture around component-based design - each component ideally would be replaceable - which is the crux of my original question, in an orchestration environment I don't see the need to create new containers on every execution when I already have existing containers that can be used?

davidfowl commented 1 week ago

Thanks, I appreciate the suggestions although I'm not sure that is related to my original question on 'where is the missing documentation for ...'. However, in terms of discussion, env vars are not used for internal reasons - I was expecting it to handle graceful degradation, so if no env-var then fall back to the appsettings/hostsetting, then fall back to a default value.

Right, thats how IConfiguration already works and what aspire takes advantage of. This isn't a new feature of aspire.

There's missing docs for sure but I'm having a hard time understanding what is being asked for.

It is the same style of architecture around component-based design - each component ideally would be replaceable - which is the crux of my original question, in an orchestration environment I don't see the need to create new containers on every execution when I already have existing containers that can be used?

I think we're talking past each other because I think I answered this in the issue, but the documentation (especially in the tutorial) does not talk about how to use the starter app with existing containers that might be running.

When you using AddRedis (or any other container-based resource), you are asking to spin up a container, when you use AddConnectionString (https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/external-parameters) you are taking control of providing the connection information. Containers are created and destroyed on every run, this is a limitation of aspire today. These are the building blocks that exist today in the system. You should be able to use that knowledge to model talking to an existing container.

The apphost sets environment variables that tell the application what connection strings to use:

image