Skip to content

Commit

Permalink
Added 7.x Elasticsearch server to services and updated test apps and …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
nr-ahemsath committed Jul 18, 2023
1 parent 561897d commit 02ef9e7
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 23 deletions.
75 changes: 73 additions & 2 deletions tests/Agent/IntegrationTests/Shared/ElasticSearchConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public static string ElasticServer
}
}

public static string ElasticUserName {
public static string ElasticUserName
{
get
{
if (_elasticUserName == null)
Expand All @@ -52,7 +53,8 @@ public static string ElasticUserName {
return _elasticUserName;
}
}
public static string ElasticPassword {
public static string ElasticPassword
{
get
{
if (_elasticPassword == null)
Expand All @@ -72,4 +74,73 @@ public static string ElasticPassword {
}
}
}
public class ElasticSearch7Configuration
{
private static string _elasticServer;
private static string _elasticUserName;
private static string _elasticPassword;

public static string ElasticServer
{
get
{
if (_elasticServer == null)
{
try
{
var testConfiguration =
IntegrationTestConfiguration.GetIntegrationTestConfiguration("ElasticSearch7Tests");
_elasticServer = testConfiguration["Server"];
}
catch (Exception ex)
{
throw new Exception("ElasticServer configuration is invalid.", ex);
}
}

return _elasticServer;
}
}

public static string ElasticUserName
{
get
{
if (_elasticUserName == null)
{
try
{
var testConfiguration =
IntegrationTestConfiguration.GetIntegrationTestConfiguration("ElasticSearch7Tests");
_elasticUserName = testConfiguration["UserName"];
}
catch (Exception ex)
{
throw new Exception("ElasticServer configuration is invalid.", ex);
}
}
return _elasticUserName;
}
}
public static string ElasticPassword
{
get
{
if (_elasticPassword == null)
{
try
{
var testConfiguration =
IntegrationTestConfiguration.GetIntegrationTestConfiguration("ElasticSearch7Tests");
_elasticPassword = testConfiguration["Password"];
}
catch (Exception ex)
{
throw new Exception("ElasticServer configuration is invalid.", ex);
}
}
return _elasticPassword;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,23 @@
<PackageReference Include="StackExchange.Redis" Version="2.6.116" Condition="'$(TargetFramework)' == 'net7.0'" />

<!-- Elasticsearch NEST framework references - only able to test newest 7.x with 8.x server -->
<PackageReference Include="NEST" Version="7.17.5" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="NEST" Version="7.17.5" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="NEST" Version="7.17.5" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="NEST" Version="7.0.0" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="NEST" Version="7.3.0" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="NEST" Version="7.9.0" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="NEST" Version="7.17.5" Condition="'$(TargetFramework)' == 'net481'" />

<!-- Elasticsearch NEST .NET/Core references - only able to test newest 7.x with 8.x server -->
<PackageReference Include="NEST" Version="7.17.5" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="NEST" Version="7.0.0" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="NEST" Version="7.17.5" Condition="'$(TargetFramework)' == 'net7.0'" />

<!-- Elasticsearch.Net framework references - only able to test newest 7.x with 8.x server -->
<PackageReference Include="Elasticsearch.Net" Version="7.17.5" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="Elasticsearch.Net" Version="7.17.5" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="Elasticsearch.Net" Version="7.17.5" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="Elasticsearch.Net" Version="7.0.0" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="Elasticsearch.Net" Version="7.3.0" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="Elasticsearch.Net" Version="7.9.0" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="Elasticsearch.Net" Version="7.17.5" Condition="'$(TargetFramework)' == 'net481'" />

<!-- Elasticsearch.Net .NET/Core references - only able to test newest 7.x with 8.x server -->
<PackageReference Include="Elasticsearch.Net" Version="7.17.5" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="Elasticsearch.Net" Version="7.0.0" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="Elasticsearch.Net" Version="7.17.5" Condition="'$(TargetFramework)' == 'net7.0'" />

<!-- Elastic.Clients.Elasticsearch framework references - only actually testing oldest and newest -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Elastic.Clients.Elasticsearch;
Expand All @@ -13,6 +14,13 @@ namespace MultiFunctionApplicationHelpers.NetStandardLibraries.Elasticsearch
internal class ElasticsearchElasticClient : ElasticsearchTestClient
{
private ElasticsearchClient _client;
protected override Uri Address
{
get
{
return new Uri(ElasticSearchConfiguration.ElasticServer);
}
}

[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public override void Connect()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Elastic.Clients.Elasticsearch;
Expand All @@ -13,13 +14,21 @@ namespace MultiFunctionApplicationHelpers.NetStandardLibraries.Elasticsearch
internal class ElasticsearchNestClient : ElasticsearchTestClient
{
private ElasticClient _client;
protected override Uri Address
{
get
{
return new Uri(ElasticSearch7Configuration.ElasticServer);
}
}


[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public override void Connect()
{
var settings = new ConnectionSettings(Address).
BasicAuthentication(ElasticSearchConfiguration.ElasticUserName,
ElasticSearchConfiguration.ElasticPassword).
BasicAuthentication(ElasticSearch7Configuration.ElasticUserName,
ElasticSearch7Configuration.ElasticPassword).
DefaultIndex(IndexName);

_client = new ElasticClient(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ namespace MultiFunctionApplicationHelpers.NetStandardLibraries.Elasticsearch
internal class ElasticsearchNetClient : ElasticsearchTestClient
{
private ElasticLowLevelClient _client;
protected override Uri Address
{
get
{
return new Uri(ElasticSearch7Configuration.ElasticServer);
}
}


[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public override void Connect()
{
var settings = new ConnectionConfiguration(Address)
.BasicAuthentication(ElasticSearchConfiguration.ElasticUserName,
ElasticSearchConfiguration.ElasticPassword)
.BasicAuthentication(ElasticSearch7Configuration.ElasticUserName,
ElasticSearch7Configuration.ElasticPassword)
.RequestTimeout(TimeSpan.FromMinutes(2));

_client = new ElasticLowLevelClient(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ internal abstract class ElasticsearchTestClient
protected const string IndexName = "flights"; // Must be lowercase!
protected const string BadIndexName = "_ILLEGAL";

protected Uri Address = new Uri(ElasticSearchConfiguration.ElasticServer);
protected abstract Uri Address
{
get;
}

public ElasticsearchTestClient() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected enum ClientType

protected readonly ConsoleDynamicMethodFixture _fixture;

protected readonly string _host = GetHostFromElasticServer(ElasticSearchConfiguration.ElasticServer);
protected readonly string _host;

protected readonly ClientType _clientType;

Expand All @@ -39,13 +39,9 @@ protected ElasticsearchTestsBase(TFixture fixture, ITestOutputHelper output, Cli
_fixture.TestLogger = output;
_clientType = clientType;

_fixture.SetTimeout(TimeSpan.FromMinutes(2));
_host = GetHostFromElasticServer(_clientType);

if (_clientType != ClientType.ElasticClients)
{
// This lets 7.x clients work with an 8.x server
_fixture.SetAdditionalEnvironmentVariable("ELASTIC_CLIENT_APIVERSIONING", "true");
}
_fixture.SetTimeout(TimeSpan.FromMinutes(2));

_fixture.AddCommand($"ElasticsearchExerciser SetClient {clientType}");

Expand Down Expand Up @@ -180,8 +176,10 @@ private void ValidateOperation(string operationName)
);
}

private static string GetHostFromElasticServer(string elasticServer)
private static string GetHostFromElasticServer(ClientType clientType)
{
var elasticServer = clientType == ClientType.ElasticClients ? ElasticSearchConfiguration.ElasticServer : ElasticSearch7Configuration.ElasticServer;

if (elasticServer.StartsWith("https://"))
{
return elasticServer.Remove(0, "https://".Length);
Expand Down
23 changes: 23 additions & 0 deletions tests/Agent/IntegrationTests/UnboundedServices/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,31 @@ services:
memlock:
soft: -1
hard: -1
deploy:
resources:
limits:
memory: 2GB
container_name: ElasticServer

elastic7:
image: elasticsearch:7.17.10
ports:
- 9201:9200
environment:
- discovery.type=single-node
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD:-ElasticPassword}
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=false
ulimits:
memlock:
soft: -1
hard: -1
deploy:
resources:
limits:
memory: 2GB
container_name: Elastic7Server

# have to manually set the password for kibana_user - use curl to hit the correct endpoint
kibana_pw_setup:
image: curlimages/curl
Expand Down

0 comments on commit 02ef9e7

Please sign in to comment.