Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ public static IResourceBuilder<OpenTelemetryCollectorResource> AddOpenTelemetryC
$@"--config=yaml:receivers::otlp::protocols::grpc::tls::key_file: ""{certKeyPath}""");
}
}

if (!settings.DisableHealthcheck)
{
const int healthPort = 13233;
resourceBuilder.WithEndpoint(targetPort: healthPort, name: "health", scheme: "http")
.WithHttpHealthCheck("/health", endpointName: "health")
.WithArgs(
"--feature-gates=confmap.enableMergeAppendOption",
$"--config=yaml:extensions::health_check/aspire::endpoint: 0.0.0.0:{healthPort}",
"--config=yaml:service::extensions: [ health_check/aspire ]"
);
}
return resourceBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public class OpenTelemetryCollectorSettings
/// Note: this will also setup SSL if Aspire is configured for HTTPS
/// </summary>
public bool EnableHttpEndpoint { get; set; } = true;

/// <summary>
/// Disable the healthcheck on the collector container
/// </summary>
public bool DisableHealthcheck { get; set; } = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public void CanCreateTheCollectorResource()
public async Task CanCreateTheCollectorResourceWithCustomConfig()
{
var builder = DistributedApplication.CreateBuilder();
builder.AddOpenTelemetryCollector("collector")
builder.AddOpenTelemetryCollector("collector", settings =>
{

settings.DisableHealthcheck = true;
})
.WithConfig("./config.yaml")
.WithAppForwarding();

Expand Down Expand Up @@ -137,6 +141,7 @@ public void CanDisableBothEndpoints()
{
settings.EnableHttpEndpoint = false;
settings.EnableGrpcEndpoint = false;
settings.DisableHealthcheck = true;
})
.WithAppForwarding();

Expand All @@ -157,7 +162,10 @@ public async Task ContainerHasAspireEnvironmentVariables()
.WithTestAndResourceLogging(testOutputHelper);
builder.Configuration["APPHOST:ContainerHostname"] = "what.ever";

var collector = builder.AddOpenTelemetryCollector("collector")
var collector = builder.AddOpenTelemetryCollector("collector", settings =>
{
settings.DisableHealthcheck = true;
})
.WithAppForwarding();

using var app = builder.Build();
Expand Down Expand Up @@ -259,6 +267,7 @@ public void CanConfigureOnlyGrpcEndpoint()
{
settings.EnableGrpcEndpoint = true;
settings.EnableHttpEndpoint = false;
settings.DisableHealthcheck = true;
})
.WithAppForwarding();

Expand All @@ -285,6 +294,7 @@ public void CanConfigureOnlyHttpEndpoint()
{
settings.EnableGrpcEndpoint = false;
settings.EnableHttpEndpoint = true;
settings.DisableHealthcheck = true;
})
.WithAppForwarding();

Expand Down Expand Up @@ -618,4 +628,48 @@ public void DevCertificateExecutableResourceHasCorrectConfiguration()
Assert.Contains("Pem", argsContext.Args);
Assert.Contains("--no-password", argsContext.Args);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void CanDisableHealthcheckOnCollectorResource(bool disableHealthcheck)
{
var builder = DistributedApplication.CreateBuilder();

builder.AddOpenTelemetryCollector("collector", settings =>
{
settings.DisableHealthcheck = disableHealthcheck;
})
.WithAppForwarding();

using var app = builder.Build();

var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();

var collectorResource = appModel.Resources.OfType<OpenTelemetryCollectorResource>().SingleOrDefault();
Assert.NotNull(collectorResource);

var hasHealthCheck = collectorResource.Annotations.OfType<HealthCheckAnnotation>().Any();
if (disableHealthcheck)
{
Assert.False(hasHealthCheck);
}
else
{
Assert.True(hasHealthCheck);
var argsAnnotations = collectorResource.Annotations.OfType<CommandLineArgsCallbackAnnotation>().ToList();
Assert.NotEmpty(argsAnnotations);

var argsContext = new CommandLineArgsCallbackContext([]);
foreach (var arg in argsAnnotations)
{
arg.Callback(argsContext);
}

Assert.Contains("--feature-gates=confmap.enableMergeAppendOption", argsContext.Args);
Assert.Contains("--config=yaml:extensions::health_check/aspire::endpoint: 0.0.0.0:13233", argsContext.Args);
Assert.Contains("--config=yaml:service::extensions: [ health_check/aspire ]", argsContext.Args);
}

}
}
Loading