Skip to content

Commit b7a165f

Browse files
Templates: only add health checks in development (#3111)
* Templates: only add health checks in dev Fixes #3109 * PR feedback
1 parent c87b804 commit b7a165f

File tree

3 files changed

+38
-23
lines changed
  • src/Aspire.ProjectTemplates/templates

3 files changed

+38
-23
lines changed

src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.ServiceDefaults/Extensions.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,22 @@ public static IHostApplicationBuilder AddDefaultHealthChecks(this IHostApplicati
101101

102102
public static WebApplication MapDefaultEndpoints(this WebApplication app)
103103
{
104-
// Uncomment the following line to enable the Prometheus endpoint (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package)
105-
// app.MapPrometheusScrapingEndpoint();
104+
// Adding health checks endpoints to applications in non-development environments has security implications.
105+
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
106+
if (app.Environment.IsDevelopment())
107+
{
108+
// All health checks must pass for app to be considered ready to accept traffic after starting
109+
app.MapHealthChecks("/health");
106110

107-
// All health checks must pass for app to be considered ready to accept traffic after starting
108-
app.MapHealthChecks("/health");
111+
// Only health checks tagged with the "live" tag must pass for app to be considered alive
112+
app.MapHealthChecks("/alive", new HealthCheckOptions
113+
{
114+
Predicate = r => r.Tags.Contains("live")
115+
});
109116

110-
// Only health checks tagged with the "live" tag must pass for app to be considered alive
111-
app.MapHealthChecks("/alive", new HealthCheckOptions
112-
{
113-
Predicate = r => r.Tags.Contains("live")
114-
});
117+
// Uncomment the following line to enable the Prometheus endpoint (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package)
118+
// app.MapPrometheusScrapingEndpoint();
119+
}
115120

116121
return app;
117122
}

src/Aspire.ProjectTemplates/templates/aspire-servicedefaults/Extensions.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,19 @@ public static WebApplication MapDefaultEndpoints(this WebApplication app)
111111
// Uncomment the following line to enable the Prometheus endpoint (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package)
112112
// app.MapPrometheusScrapingEndpoint();
113113

114-
// All health checks must pass for app to be considered ready to accept traffic after starting
115-
app.MapHealthChecks("/health");
116-
117-
// Only health checks tagged with the "live" tag must pass for app to be considered alive
118-
app.MapHealthChecks("/alive", new HealthCheckOptions
114+
// Adding health checks endpoints to applications in non-development environments has security implications.
115+
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
116+
if (app.Environment.IsDevelopment())
119117
{
120-
Predicate = r => r.Tags.Contains("live")
121-
});
118+
// All health checks must pass for app to be considered ready to accept traffic after starting
119+
app.MapHealthChecks("/health");
120+
121+
// Only health checks tagged with the "live" tag must pass for app to be considered alive
122+
app.MapHealthChecks("/alive", new HealthCheckOptions
123+
{
124+
Predicate = r => r.Tags.Contains("live")
125+
});
126+
}
122127

123128
return app;
124129
}

src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.ServiceDefaults/Extensions.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,19 @@ public static WebApplication MapDefaultEndpoints(this WebApplication app)
104104
// Uncomment the following line to enable the Prometheus endpoint (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package)
105105
// app.MapPrometheusScrapingEndpoint();
106106

107-
// All health checks must pass for app to be considered ready to accept traffic after starting
108-
app.MapHealthChecks("/health");
109-
110-
// Only health checks tagged with the "live" tag must pass for app to be considered alive
111-
app.MapHealthChecks("/alive", new HealthCheckOptions
107+
// Adding health checks endpoints to applications in non-development environments has security implications.
108+
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
109+
if (app.Environment.IsDevelopment())
112110
{
113-
Predicate = r => r.Tags.Contains("live")
114-
});
111+
// All health checks must pass for app to be considered ready to accept traffic after starting
112+
app.MapHealthChecks("/health");
113+
114+
// Only health checks tagged with the "live" tag must pass for app to be considered alive
115+
app.MapHealthChecks("/alive", new HealthCheckOptions
116+
{
117+
Predicate = r => r.Tags.Contains("live")
118+
});
119+
}
115120

116121
return app;
117122
}

0 commit comments

Comments
 (0)