Skip to content
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

Container not able to export telemetry to dashboard and environment variable not set correctly #927

Closed
jp1482 opened this issue Nov 17, 2023 · 8 comments
Assignees

Comments

@jp1482
Copy link

jp1482 commented Nov 17, 2023

Environment

  • Windows 10
  • WSL 2 with Ubuntu 22.04
    - Docker is running inside WSL 2

Installation Steps

  • Installed .net 8 SDK.
  • install workload aspire
    Note: This all works fine.

Project Creation

  • This is inside WSL 2 Ubuntu 22.04.
mkdir two  ( Success)
cd two  ( Success)
sudo dotnet new aspire-starter ( Success)
sudo dotnet restore (Success)
sudo dotnet build (Success)
sudo dotnet run ( Success)

Till above point everything works and success. I am able to see dashboard and frontend and API project. Also they are able to communicate with each other.

I want to experiment with container support. So I have create docker image of api project created by aspire-starter. That also works fine.

cd two.ApiService
sudo dotnet publish --os linux --arch x64 /t:PublishContainer -c Release 

Now I have changed the two.AppHost to add container. (Program.cs)

var builder = DistributedApplication.CreateBuilder(args);

// I disabled this project.
// var apiservice = builder.AddProject<Projects.two_ApiService>("apiservice");

// Added this line
var containerApi = builder.AddContainer("TwoApiContainer","two-apiservice")
                    .WithServiceBinding(8080,10005,"http","twoapicontainer")
                    .WithOtlpExporter();

builder.AddProject<Projects.two_Web>("webfrontend").WithReference(containerApi.GetEndpoint("twoapicontainer"));    

builder.Build().Run();

Also change frontend as container service name change so to give correct name.

Change in project two.web (Program.cs)

// Following line I have changed service name to twoapicontainer. 
builder.Services.AddHttpClient<WeatherApiClient>(client=> client.BaseAddress = new("http://twoapicontainer"));

ISSUES

  • Now container even if telemetry enable , it is not able to export or communicate with telemetry endpoint as it is localhost and may required to add in servicediscovery but not sure how.
  • Also when I check environment variable of container , some of the markup value not change for ( For this image is attached.)

image

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Nov 17, 2023
@davidfowl
Copy link
Member

@karolz-ms do you know why those environment variables wouldn't get resolved by dcp for containers?

@jp1482
Copy link
Author

jp1482 commented Nov 17, 2023

@davidfowl @karolz-ms

Issue 1 (Seems to resolve): I was able to resolve one issue related to container not able to publish metrics to aspire dashboard. In this issue is url is http://localhost:16227 so it try to listen on localhost , 127,0,0,1 and 0.0.0.0 and none will work for container. So in two.AppHost project there is lauchSettings.json and I have updated environment variable like following.

Before

 "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "DOTNET_ENVIRONMENT": "Development",
        "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16227"
      }

After ( I replace actual ip address with WSL ip address)

 "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "DOTNET_ENVIRONMENT": "Development",
        "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://<actual ip address>:16227"   
      }

After this it works fine.

Issue 2: Environment variable not resolve for UID and servicename and this issue still persists.

image

@karolz-ms
Copy link
Member

@jp1482 thank you for submitting the issue 🤗

The simple answer to the question "why aren't variables properly expanded for container environment variable templates" is that is simply not implemented yet; these env var templates only work for executables/projects currently.

In the preview 1 of Aspire containers were primarily designed for running dependencies such as databases, async communication facilities like Redis, and similar. Not really for running application services.

@jp1482 can you describe what is the reason you want to run your API inside a container (as opposed to running it as ordinary process, as the startup solution does)?

@DamianEdwards
Copy link
Member

@karolz-ms running services in container is one of the patterns we expect folks to do as part of #829

@jp1482
Copy link
Author

jp1482 commented Nov 21, 2023

@karolz-ms

There are multiple reason behind it.

  1. In Microservices scenario, each team works on individual service and it is possible that other team might not have access to codebase of that service but other team provide their service as docker image.

  2. Also currently problem is that those environment variable not set so it display wrong in environment UI ( as provided image above) and also it may possible that consume image also export metrics so name and other parts needs to be correct.

@karolz-ms
Copy link
Member

@jp1482 makes sense, thanks for explanation!

@DamianEdwards DamianEdwards added area-orchestrator and removed area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication labels Nov 22, 2023
@davidfowl
Copy link
Member

davidfowl commented Nov 22, 2023

This is pretty important to make it possible to use containers from other services. I think we should investigate for preview2

@karolz-ms
Copy link
Member

This should be fixed in preview2 (specifically, DCP 0.1.45, which preview2 will use under the covers, should have support for env var template functions)

@github-actions github-actions bot locked and limited conversation to collaborators Apr 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants