Skip to content

Commit

Permalink
Fix the dapr sample (#370)
Browse files Browse the repository at this point in the history
- HTTPS redirection is too aggressive on the dashboard. It'll only come into play if all endpoints are https (including the OTLP endpoint).
- Remove hardcoded insecure flag from dapr side car impl
  • Loading branch information
davidfowl authored Oct 18, 2023
1 parent 915c0c0 commit c7c1713
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions samples/dapr/ServiceA/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
Expand All @@ -37,6 +35,8 @@
.WithName("GetWeatherForecast")
.WithOpenApi();

app.MapDefaultEndpoints();

app.Run();

internal sealed record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
Expand Down
4 changes: 2 additions & 2 deletions samples/dapr/ServiceB/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
Expand All @@ -41,6 +39,8 @@
.WithName("GetWeatherForecast")
.WithOpenApi();

app.MapDefaultEndpoints();

app.Run();

internal sealed record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
Expand Down
7 changes: 5 additions & 2 deletions src/Aspire.Dashboard/DashboardWebApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class DashboardWebApplication : IHostedService
private const string DashboardUrlVariableName = "ASPNETCORE_URLS";
private const string DashboardUrlDefaultValue = "http://localhost:18888";

private readonly bool _isAllHttps;
private readonly WebApplication _app;

public DashboardWebApplication(Action<IServiceCollection> configureServices)
Expand All @@ -39,6 +40,8 @@ public DashboardWebApplication(Action<IServiceCollection> configureServices)
throw new InvalidOperationException("Only one URL for Aspire dashboard OTLP endpoint is supported.");
}

_isAllHttps = dashboardHttpsPort is not null && IsHttps(otlpUris[0]);

builder.WebHost.ConfigureKestrel(kestrelOptions =>
{
ConfigureListenAddresses(kestrelOptions, dashboardUris);
Expand All @@ -53,7 +56,7 @@ public DashboardWebApplication(Action<IServiceCollection> configureServices)
builder.WebHost.UseStaticWebAssets();
}

if (dashboardHttpsPort is not null)
if (_isAllHttps)
{
// Explicitly configure the HTTPS redirect port as we're possibly listening on multiple HTTPS addresses
// if the dashboard OTLP URL is configured to use HTTPS too
Expand Down Expand Up @@ -86,7 +89,7 @@ public DashboardWebApplication(Action<IServiceCollection> configureServices)
_app.UseExceptionHandler("/Error");
}

if (dashboardHttpsPort is not null)
if (_isAllHttps)
{
_app.UseHttpsRedirection();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,6 @@ public Task BeforeStartAsync(DistributedApplicationModel appModel, CancellationT
if (this._options.EnableTelemetry != false)
{
OtlpConfigurationExtensions.AddOtlpEnvironment(resource, _configuration, _environment);

// Explicitly specify OTEL endpoint is insecure and use gRPC to sidecar.
resource.Annotations.Add(
new EnvironmentCallbackAnnotation(
env =>
{
env["OTEL_EXPORTER_OTLP_INSECURE"] = "true";
env["OTEL_EXPORTER_OTLP_PROTOCOL"] = "grpc";
}));
}

resource.Annotations.Add(
Expand Down

0 comments on commit c7c1713

Please sign in to comment.