From e6a3d0b085a3f1f46a11f26b708147df1e3aa023 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Mon, 16 Oct 2023 15:19:42 +0200 Subject: [PATCH] Update high watermark settings for Elasticsearch Integration tests (#2198) --- .github/workflows/test-linux.yml | 2 + ...Elastic.Clients.Elasticsearch.Tests.csproj | 5 +++ .../ElasticsearchTestFixture.cs | 37 ++++++++++++++++++- .../ElasticsearchTests.cs | 14 ++++--- .../xunit.runner.json | 4 ++ 5 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 test/instrumentations/Elastic.Clients.Elasticsearch.Tests/xunit.runner.json diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml index 43c486f92..56edc5952 100644 --- a/.github/workflows/test-linux.yml +++ b/.github/workflows/test-linux.yml @@ -148,6 +148,8 @@ jobs: - name: 'Tests: Profiler' uses: ./.github/workflows/test + #temporarily disable profiler tests + if: false with: name: 'profiler' project: 'test/profiler/Elastic.Apm.Profiler.Managed.Tests/Elastic.Apm.Profiler.Managed.Tests.csproj' diff --git a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/Elastic.Clients.Elasticsearch.Tests.csproj b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/Elastic.Clients.Elasticsearch.Tests.csproj index c50230a69..3c75cf2b9 100644 --- a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/Elastic.Clients.Elasticsearch.Tests.csproj +++ b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/Elastic.Clients.Elasticsearch.Tests.csproj @@ -16,5 +16,10 @@ + + + + + diff --git a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTestFixture.cs b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTestFixture.cs index 4446277f8..087c6fb0e 100644 --- a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTestFixture.cs +++ b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTestFixture.cs @@ -7,25 +7,60 @@ using Elastic.Transport; using Testcontainers.Elasticsearch; using Xunit; +using Xunit.Abstractions; +using Xunit.Sdk; +using HttpMethod = Elastic.Transport.HttpMethod; namespace Elastic.Clients.Elasticsearch.Tests; public sealed class ElasticsearchTestFixture : IAsyncLifetime { - public ElasticsearchContainer Container { get; } = new ElasticsearchBuilder().Build(); + private readonly IMessageSink _sink; + public ElasticsearchContainer Container { get; } public ElasticsearchClient? Client { get; private set; } + public ElasticsearchTestFixture(IMessageSink sink) + { + _sink = sink; + Container = new ElasticsearchBuilder() + .Build(); + } + + public async Task InitializeAsync() { await Container.StartAsync(); + var (stdOut, stdErr) = await Container.GetLogsAsync(); + + _sink.OnMessage(new DiagnosticMessage(stdOut)); + _sink.OnMessage(new DiagnosticMessage(stdErr)); + var settings = new ElasticsearchClientSettings(new Uri(Container.GetConnectionString())); settings.ServerCertificateValidationCallback(CertificateValidations.AllowAll); Client = new ElasticsearchClient(settings); if (Client == null) throw new Exception("`new ElasticsearchClient(settings)` returned `null`"); + + //Increase Elasticsearch high disk watermarks, Github Actions container typically has around + //~7GB free (8%) of the available space. + var response = await Client.Transport.RequestAsync(HttpMethod.PUT, "_cluster/settings", PostData.String(@"{ + ""persistent"": { + ""cluster.routing.allocation.disk.watermark.low"": ""90%"", + ""cluster.routing.allocation.disk.watermark.low.max_headroom"": ""100GB"", + ""cluster.routing.allocation.disk.watermark.high"": ""98%"", + ""cluster.routing.allocation.disk.watermark.high.max_headroom"": ""2GB"", + ""cluster.routing.allocation.disk.watermark.flood_stage"": ""99%"", + ""cluster.routing.allocation.disk.watermark.flood_stage.max_headroom"": ""1GB"", + ""cluster.routing.allocation.disk.watermark.flood_stage.frozen"": ""99%"", + ""cluster.routing.allocation.disk.watermark.flood_stage.frozen.max_headroom"": ""1GB"" + } + }")); + + if (!response.ApiCallDetails.HasSuccessfulStatusCode) + throw new Exception(response.ToString()); } async Task IAsyncLifetime.DisposeAsync() diff --git a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs index 692dc7c50..59b1d0927 100644 --- a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs +++ b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs @@ -3,8 +3,11 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information +using DotNet.Testcontainers; +using DotNet.Testcontainers.Configurations; using Elastic.Apm; using Elastic.Apm.Api; +using Elastic.Apm.AspNetCore.Tests; using Elastic.Apm.DiagnosticSource; using Elastic.Apm.Elasticsearch; using Elastic.Apm.Tests.Utilities; @@ -21,6 +24,7 @@ public class ElasticsearchTests : IClassFixture private readonly ElasticsearchTestFixture _esClientListenerFixture; private readonly ElasticsearchClient _client; + public ElasticsearchTests(ITestOutputHelper testOutputHelper, ElasticsearchTestFixture esClientListenerFixture) { _testOutputHelper = testOutputHelper; @@ -208,14 +212,14 @@ private async Task IndexDataAsync() var response = await _client.IndexAsync(tweet, request => request.Index("my-tweet-index")); - response.IsSuccess().Should().BeTrue(); + response.IsSuccess().Should().BeTrue("{0}", response.DebugInformation); } private async Task GetDocumentAsync() { var response = await _client.GetAsync(1, idx => idx.Index("my-tweet-index")); - response.IsSuccess().Should().BeTrue(); + response.IsSuccess().Should().BeTrue("{0}", response.DebugInformation); var tweet = response.Source; tweet.Should().NotBeNull(); } @@ -241,14 +245,14 @@ private async Task SearchDocumentAsync() private async Task UpdateDocumentAsync(Tweet tweet) { tweet.Message = "This is a new message"; - var response2 = await _client.UpdateAsync("my-tweet-index", 1, u => u + var response = await _client.UpdateAsync("my-tweet-index", 1, u => u .Doc(tweet)); - response2.IsValidResponse.Should().BeTrue(); + response.IsValidResponse.Should().BeTrue("{0}", response.DebugInformation); } private async Task DeleteDocumentAsync() { var response = await _client.DeleteAsync("my-tweet-index", 1); - response.IsValidResponse.Should().BeTrue(); + response.IsValidResponse.Should().BeTrue("{0}", response.DebugInformation); } } diff --git a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/xunit.runner.json b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/xunit.runner.json new file mode 100644 index 000000000..68790c3cc --- /dev/null +++ b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "diagnosticMessages": true +} \ No newline at end of file