Skip to content

Commit

Permalink
Update high watermark settings for Elasticsearch Integration tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Oct 16, 2023
1 parent 583f085 commit e6a3d0b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
<ProjectReference Include="$(SrcInstrumentations)\Elastic.Apm.Elasticsearch\Elastic.Apm.Elasticsearch.csproj" />
<ProjectReference Include="$(SolutionRoot)\src\Elastic.Apm\Elastic.Apm.csproj" />
<ProjectReference Include="$(SolutionRoot)\test\Elastic.Apm.Tests.Utilities\Elastic.Apm.Tests.Utilities.csproj" />
<ProjectReference Include="..\..\integrations\Elastic.Apm.AspNetCore.Tests\Elastic.Apm.AspNetCore.Tests.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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<StringResponse>(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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +24,7 @@ public class ElasticsearchTests : IClassFixture<ElasticsearchTestFixture>
private readonly ElasticsearchTestFixture _esClientListenerFixture;
private readonly ElasticsearchClient _client;


public ElasticsearchTests(ITestOutputHelper testOutputHelper, ElasticsearchTestFixture esClientListenerFixture)
{
_testOutputHelper = testOutputHelper;
Expand Down Expand Up @@ -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<Tweet>(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();
}
Expand All @@ -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<Tweet, object>("my-tweet-index", 1, u => u
var response = await _client.UpdateAsync<Tweet, object>("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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"diagnosticMessages": true
}

0 comments on commit e6a3d0b

Please sign in to comment.