Skip to content

Commit 9e8b325

Browse files
authored
Ensure Elastic.Documentation.Api uses Elastic.Documentation.ServiceDefaults (#2307)
* Ensure Elastic.Documentation.Api uses Elastic.Documentation.ServiceDefaults * cleanup
1 parent 5570c23 commit 9e8b325

File tree

6 files changed

+20
-28
lines changed

6 files changed

+20
-28
lines changed

docs-builder.slnx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<File Path="config/legacy-url-mappings.yml" />
2929
<File Path="config/navigation.yml" />
3030
<File Path="config/products.yml" />
31-
<File Path="config/synonyms.yml" />
3231
<File Path="config/versions.yml" />
3332
<File Path="config/search.yml" />
3433
</Folder>

src/Elastic.Documentation.ServiceDefaults/Extensions.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ public static class Extensions
2525

2626
public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
2727
{
28-
_ = builder
29-
.ConfigureOpenTelemetry()
30-
.AddDefaultHealthChecks();
31-
3228
_ = builder.Services
3329
.AddServiceDiscovery()
3430
.ConfigureHttpClientDefaults(http =>
@@ -39,7 +35,7 @@ public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where
3935
return builder;
4036
}
4137

42-
public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
38+
public static TBuilder AddOpenTelemetryDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
4339
{
4440
_ = builder.Logging.AddOpenTelemetry(logging =>
4541
{
@@ -108,23 +104,4 @@ public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) w
108104

109105
return builder;
110106
}
111-
112-
public static WebApplication MapDefaultEndpoints(this WebApplication app)
113-
{
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())
117-
{
118-
// All health checks must pass for app to be considered ready to accept traffic after starting
119-
_ = app.MapHealthChecks(HealthEndpointPath);
120-
121-
// Only health checks tagged with the "live" tag must pass for app to be considered alive
122-
_ = app.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions
123-
{
124-
Predicate = r => r.Tags.Contains("live")
125-
});
126-
}
127-
128-
return app;
129-
}
130107
}

src/api/Elastic.Documentation.Api.Lambda/Elastic.Documentation.Api.Lambda.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24+
<ProjectReference Include="..\..\Elastic.Documentation.ServiceDefaults\Elastic.Documentation.ServiceDefaults.csproj" />
2425
<ProjectReference Include="..\Elastic.Documentation.Api.Core\Elastic.Documentation.Api.Core.csproj"/>
2526
<ProjectReference Include="..\Elastic.Documentation.Api.Infrastructure\Elastic.Documentation.Api.Infrastructure.csproj"/>
2627
</ItemGroup>

src/api/Elastic.Documentation.Api.Lambda/Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
using Elastic.Documentation.Api.Core.Search;
1010
using Elastic.Documentation.Api.Infrastructure;
1111
using Elastic.Documentation.Api.Infrastructure.OpenTelemetry;
12+
using Elastic.Documentation.Configuration.Assembler;
13+
using Elastic.Documentation.ServiceDefaults;
1214

1315
try
1416
{
1517
var builder = WebApplication.CreateSlimBuilder(args);
18+
_ = builder.AddDocumentationServiceDefaults(ref args, (s, p) =>
19+
{
20+
_ = s.AddSingleton(AssemblyConfiguration.Create(p));
21+
});
1622
// Add logging configuration for Lambda
1723
_ = builder.AddDocsApiOpenTelemetry();
1824

@@ -39,6 +45,9 @@
3945
builder.Services.AddElasticDocsApiUsecases(environment);
4046
var app = builder.Build();
4147

48+
if (app.Environment.IsDevelopment())
49+
_ = app.UseDeveloperExceptionPage();
50+
4251
var v1 = app.MapGroup("/docs/_api/v1");
4352
v1.MapElasticDocsApiEndpoints();
4453
Console.WriteLine("API endpoints mapped");

src/tooling/docs-builder/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
{
1818
_ = s.AddSingleton(AssemblyConfiguration.Create(p));
1919
})
20-
.AddDocumentationToolingDefaults();
20+
.AddDocumentationToolingDefaults()
21+
.AddOpenTelemetryDefaults();
2122

2223
var app = builder.ToConsoleAppBuilder();
2324

tests-integration/Elastic.Documentation.Api.IntegrationTests/OtlpProxyIntegrationTests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,11 @@ public async Task OtlpProxyReturnsCollectorErrorStatusCode()
209209

210210
using var factory = ApiWebApplicationFactory.WithMockedServices(services =>
211211
{
212+
#pragma warning disable EXTEXP0001 // Experimental API - needed for test to bypass resilience handlers
212213
_ = services.AddHttpClient(AdotOtlpGateway.HttpClientName)
213-
.ConfigurePrimaryHttpMessageHandler(() => mockHandler);
214+
.ConfigurePrimaryHttpMessageHandler(() => mockHandler)
215+
.RemoveAllResilienceHandlers();
216+
#pragma warning restore EXTEXP0001
214217
});
215218

216219
var client = factory.CreateClient();
@@ -219,8 +222,10 @@ public async Task OtlpProxyReturnsCollectorErrorStatusCode()
219222
// Act
220223
using var response = await client.PostAsync("/docs/_api/v1/o/t", content, TestContext.Current.CancellationToken);
221224

225+
var responseContent = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
222226
// Assert - verify error responses are properly forwarded
223-
response.StatusCode.Should().Be(HttpStatusCode.ServiceUnavailable);
227+
response.StatusCode.Should().Be(HttpStatusCode.ServiceUnavailable, "{0}", responseContent);
228+
224229

225230
// Cleanup mock response
226231
mockResponse.Dispose();

0 commit comments

Comments
 (0)