Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
  • Loading branch information
Xtansia committed Aug 15, 2024
1 parent 8a14655 commit d371168
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 66 deletions.
10 changes: 5 additions & 5 deletions .github/actions/build-opensearch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inputs:
plugins_output_directory:
description: The directory to output the plugins to
default: ""
outputs:
outputs:
distribution:
description: The path to the OpenSearch distribution
value: ${{ steps.determine.outputs.distribution }}
Expand All @@ -36,11 +36,11 @@ runs:
./opensearch/distribution/archives/linux-tar/build/distributions/opensearch-*.tar.gz
./opensearch/plugins/*/build/distributions/*.zip
build_script: |
./gradlew :distribution:archives:linux-tar:assemble -Dbuild.snapshot=${{ inputs.build_snapshot }}
./gradlew --stacktrace :distribution:archives:linux-tar:assemble -Dbuild.snapshot=${{ inputs.build_snapshot }}
PluginList=("analysis-icu" "analysis-kuromoji" "analysis-nori" "analysis-phonetic" "ingest-attachment" "mapper-murmur3")
for plugin in ${PluginList[*]}; do
./gradlew :plugins:$plugin:assemble -Dbuild.snapshot=${{ inputs.build_snapshot }}
./gradlew --stacktrace :plugins:$plugin:assemble -Dbuild.snapshot=${{ inputs.build_snapshot }}
done
- name: Determine OpenSearch distribution path and version
Expand All @@ -62,7 +62,7 @@ runs:
cache_key_suffix: ${{ inputs.build_snapshot == 'true' && '-snapshot' || '' }}
cached_paths: |
./opensearch-security/build/distributions/opensearch-security-*.zip
build_script: ./gradlew assemble -Dopensearch.version=${{ steps.determine.outputs.version }} -Dbuild.snapshot=${{ inputs.build_snapshot }}
build_script: ./gradlew --stacktrace assemble -Dopensearch.version=${{ steps.determine.outputs.version }} -Dbuild.snapshot=${{ inputs.build_snapshot }}

- name: Restore or Build OpenSearch k-NN
uses: ./client/.github/actions/cached-git-build
Expand All @@ -76,7 +76,7 @@ runs:
./opensearch-knn/build/distributions/opensearch-knn-*.zip
build_script: |
sudo apt-get install -y libopenblas-dev libomp-dev
./gradlew buildJniLib assemble -Dopensearch.version=${{ steps.determine.outputs.version }} -Dbuild.snapshot=${{ inputs.build_snapshot }}
./gradlew --stacktrace buildJniLib assemble -Dopensearch.version=${{ steps.determine.outputs.version }} -Dbuild.snapshot=${{ inputs.build_snapshot }}
distributions=./build/distributions
lib_dir=$distributions/lib
mkdir $lib_dir
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/integration-yaml-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ jobs:
strategy:
fail-fast: false
matrix:
opensearch_ref: ['1.x', '2.x', 'main']
include:
- { opensearch_ref: '1.x', java_version: '11' }
- { opensearch_ref: '2.x', java_version: '17' }
- { opensearch_ref: 'main', java_version: '17' }
steps:
- name: Checkout Client
uses: actions/checkout@v4
Expand All @@ -111,8 +114,8 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
java-version: ${{ matrix.java_version }}

- name: Restore or Build OpenSearch
id: opensearch_build
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ jobs:
restore-keys: |
${{ runner.os }}-nuget-
- run: "./build.sh integrate $VERSION readonly,replicatedreadonly,writable random:test_only_one --report"
# - run: "./build.sh integrate $VERSION readonly,replicatedreadonly,writable random:test_only_one --report"
- run: "./build.sh integrate $VERSION replicatedreadonly random:test_only_one --report"
name: Integration Tests
working-directory: client
env:
Expand All @@ -61,18 +62,20 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: report-${{ matrix.version }}
path: client/build/output/*
path: |
client/build/output/*
/tmp/OpenSearchManaged/opensearch-${{ matrix.version }}/*/logs/**/*
integration-opensearch-unreleased:
name: Integration OpenSearch Unreleased
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
opensearch_ref:
- '1.x'
- '2.x'
- 'main'
include:
- { opensearch_ref: '1.x', java_version: '11' }
- { opensearch_ref: '2.x', java_version: '17' }
- { opensearch_ref: 'main', java_version: '17' }

steps:
- name: Checkout Client
Expand Down Expand Up @@ -100,6 +103,12 @@ jobs:
restore-keys: |
${{ runner.os }}-nuget-
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java_version }}

- name: Restore or Build OpenSearch
id: opensearch
uses: ./client/.github/actions/build-opensearch
Expand Down
49 changes: 26 additions & 23 deletions abstractions/src/OpenSearch.OpenSearch.Managed/ClusterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,32 @@ protected ClusterBase(TConfiguration clusterConfiguration)
ClusterConfiguration = clusterConfiguration;
ClusterMoniker = GetType().Name.Replace("Cluster", "");

NodeConfiguration Modify(NodeConfiguration n, int p)
{
ModifyNodeConfiguration(n, p);
return n;
}

var nodes =
(from port in Enumerable.Range(ClusterConfiguration.StartingPortNumber,
ClusterConfiguration.NumberOfNodes)
let config = new NodeConfiguration(clusterConfiguration, port, ClusterMoniker)
{
ShowOpenSearchOutputAfterStarted =
clusterConfiguration.ShowOpenSearchOutputAfterStarted,
}
let node = new OpenSearchNode(Modify(config, port))
{
AssumeStartedOnNotEnoughMasterPing = ClusterConfiguration.NumberOfNodes > 1,
}
select node).ToList();

var initialMasterNodes = string.Join(",", nodes.Select(n => n.NodeConfiguration.DesiredNodeName));
foreach (var node in nodes)
node.NodeConfiguration.InitialMasterNodes(initialMasterNodes);
var nodeConfigs = Enumerable.Range(ClusterConfiguration.StartingPortNumber, ClusterConfiguration.NumberOfNodes)
.Select(port => new NodeConfiguration(ClusterConfiguration, port, ClusterMoniker)
{
ShowOpenSearchOutputAfterStarted = ClusterConfiguration.ShowOpenSearchOutputAfterStarted
})
.ToArray();

var initialClusterManagerNodes = string.Join(",", nodeConfigs.Select(n => n.DesiredNodeName));

var nodes = nodeConfigs
.Select(config =>
{
if (nodeConfigs.Length > 1)
{
var otherNodes = nodeConfigs
.Where(n => n != config)
.Select(n => $"localhost:{(n.DesiredPort ?? 9200) + 100}");
config.SeedHosts(string.Join(",", otherNodes));
}
config.InitialClusterManagerNodes(initialClusterManagerNodes);
ModifyNodeConfiguration(config, config.DesiredPort ?? 9200);
return new OpenSearchNode(config) { AssumeStartedOnNotEnoughClusterManagerPing = ClusterConfiguration.NumberOfNodes > 1 };
})
.ToArray();

Nodes = new ReadOnlyCollection<OpenSearchNode>(nodes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ public NodeConfiguration(IClusterConfiguration<NodeFileSystem> clusterConfigurat
Settings = new NodeSettings(clusterConfiguration.DefaultNodeSettings);

if (!string.IsNullOrWhiteSpace(DesiredNodeName)) Settings.Add("node.name", DesiredNodeName);
if (DesiredPort.HasValue)
Settings.Add("http.port", DesiredPort.Value.ToString(CultureInfo.InvariantCulture));
}
if (DesiredPort is { } desiredPort)
{
Settings.Add("http.port", desiredPort.ToString(CultureInfo.InvariantCulture));
Settings.Add("transport.port", (desiredPort + 100).ToString(CultureInfo.InvariantCulture));
}
}

private IClusterConfiguration<NodeFileSystem> ClusterConfiguration { get; }

Expand Down Expand Up @@ -87,10 +90,15 @@ public Action<StartArguments> ModifyStartArguments
public OpenSearchVersion Version => ClusterConfiguration.Version;
public string[] CommandLineArguments => Settings.ToCommandLineArguments(Version);

public void InitialMasterNodes(string initialMasterNodes) =>
Settings.Add("cluster.initial_master_nodes", initialMasterNodes, ">=1.0.0");
public void SeedHosts(string seedHosts) => Settings.Add("discovery.seed_hosts", seedHosts);

public void InitialClusterManagerNodes(string initialClusterManagerNodes)
{
Settings.Add("cluster.initial_master_nodes", initialClusterManagerNodes, ">=1.0.0 <2.0.0");
Settings.Add("cluster.initial_cluster_manager_nodes", initialClusterManagerNodes, ">=2.0.0");
}

public string AttributeKey(string attribute)
public string AttributeKey(string attribute)
{
var attr = "attr.";
return $"node.{attr}{attribute}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public OpenSearchNode(OpenSearchVersion version, string openSearchHome = null)
/// doing the election.
/// <para>Useful to speed up starting multi node clusters</para>
/// </summary>
public bool AssumeStartedOnNotEnoughMasterPing { get; set; }
public bool AssumeStartedOnNotEnoughClusterManagerPing { get; set; }

internal IConsoleLineHandler Writer { get; private set; }

Expand Down Expand Up @@ -119,7 +119,7 @@ private static void AppendPathEnvVar(string name, string value)

private bool AssumedStartedStateChecker(string section, string message)
{
if (AssumeStartedOnNotEnoughMasterPing
if (AssumeStartedOnNotEnoughClusterManagerPing
&& section.Contains("ZenDiscovery")
&& message.Contains("not enough master nodes discovered during pinging"))
return true;
Expand Down
6 changes: 4 additions & 2 deletions build/scripts/scripts.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
<Content Include="..\..\.github\license-header-fs.txt"><Link>license-header-fs.txt</Link></Content>
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="8.0.301" />

<PackageReference Include="Bullseye" Version="5.0.0" />
<ProjectReference Include="$(SolutionRoot)\abstractions\src\OpenSearch.OpenSearch.Managed\OpenSearch.OpenSearch.Managed.csproj" />

<PackageReference Include="Fake.Core.Environment" Version="6.1.0" />
<PackageReference Include="Fake.Core.SemVer" Version="6.1.0" />
<PackageReference Include="Fake.IO.FileSystem" Version="6.1.0" />
<PackageReference Include="Fake.IO.Zip" Version="6.1.0" />
<PackageReference Include="Fake.Tools.Git" Version="5.23.1" />

<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

<PackageReference Include="Octokit" Version="13.0.1" />
Expand Down
3 changes: 3 additions & 0 deletions src/ApiGenerator/Generator/ApiEndpointFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ private static string SanitizeDescription(this string description)
{
if (string.IsNullOrWhiteSpace(description)) return null;

description = Regex.Replace(description, "&", "&amp;");
description = Regex.Replace(description, "<", "&lt;");
description = Regex.Replace(description, ">", "&gt;");
description = Regex.Replace(description, @"\s+", " ");

if (!description.EndsWith('.')) description += '.';
Expand Down
4 changes: 2 additions & 2 deletions src/OpenSearch.Client/_Generated/Descriptors.Cluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public ClusterHealthDescriptor WaitForActiveShards(string waitforactiveshards) =
public ClusterHealthDescriptor WaitForEvents(WaitForEvents? waitforevents) =>
Qs("wait_for_events", waitforevents);

/// <summary>The request waits until the specified number N of nodes is available. It also accepts >=N, <=N, >N and <N. Alternatively, it is possible to use ge(N), le(N), gt(N) and lt(N) notation.</summary>
/// <summary>The request waits until the specified number N of nodes is available. It also accepts &gt;=N, &lt;=N, &gt;N and &lt;N. Alternatively, it is possible to use ge(N), le(N), gt(N) and lt(N) notation.</summary>
public ClusterHealthDescriptor WaitForNodes(string waitfornodes) =>
Qs("wait_for_nodes", waitfornodes);

Expand All @@ -350,7 +350,7 @@ public ClusterHealthDescriptor WaitForNoRelocatingShards(
bool? waitfornorelocatingshards = true
) => Qs("wait_for_no_relocating_shards", waitfornorelocatingshards);

/// <summary>One of green, yellow or red. Will wait (until the timeout provided) until the status of the cluster changes to the one provided or better, i.e. green > yellow > red. By default, will not wait for any status.</summary>
/// <summary>One of green, yellow or red. Will wait (until the timeout provided) until the status of the cluster changes to the one provided or better, i.e. green &gt; yellow &gt; red. By default, will not wait for any status.</summary>
public ClusterHealthDescriptor WaitForStatus(HealthStatus? waitforstatus) =>
Qs("wait_for_status", waitforstatus);
}
Expand Down
6 changes: 3 additions & 3 deletions src/OpenSearch.Client/_Generated/Requests.Cluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ public WaitForEvents? WaitForEvents
}

/// <summary>
/// The request waits until the specified number N of nodes is available. It also accepts >=N, <=N, >N and <N. Alternatively, it is possible
/// to use ge(N), le(N), gt(N) and lt(N) notation.
/// The request waits until the specified number N of nodes is available. It also accepts &gt;=N, &lt;=N, &gt;N and &lt;N. Alternatively, it
/// is possible to use ge(N), le(N), gt(N) and lt(N) notation.
/// </summary>
public string WaitForNodes
{
Expand Down Expand Up @@ -489,7 +489,7 @@ public bool? WaitForNoRelocatingShards

/// <summary>
/// One of green, yellow or red. Will wait (until the timeout provided) until the status of the cluster changes to the one provided or better,
/// i.e. green > yellow > red. By default, will not wait for any status.
/// i.e. green &gt; yellow &gt; red. By default, will not wait for any status.
/// </summary>
public HealthStatus? WaitForStatus
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ public WaitForEvents? WaitForEvents
}

/// <summary>
/// The request waits until the specified number N of nodes is available. It also accepts >=N, <=N, >N and <N. Alternatively, it is possible
/// to use ge(N), le(N), gt(N) and lt(N) notation.
/// The request waits until the specified number N of nodes is available. It also accepts &gt;=N, &lt;=N, &gt;N and &lt;N. Alternatively, it
/// is possible to use ge(N), le(N), gt(N) and lt(N) notation.
/// </summary>
public string WaitForNodes
{
Expand Down Expand Up @@ -398,7 +398,7 @@ public bool? WaitForNoRelocatingShards

/// <summary>
/// One of green, yellow or red. Will wait (until the timeout provided) until the status of the cluster changes to the one provided or better,
/// i.e. green > yellow > red. By default, will not wait for any status.
/// i.e. green &gt; yellow &gt; red. By default, will not wait for any status.
/// </summary>
public HealthStatus? WaitForStatus
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ public ReadOnlyCluster() : base(Knn, MapperMurmur3, Security) { }

public class ReplicatedReadOnlyCluster : ClientTestClusterBase
{
public ReplicatedReadOnlyCluster() : base(new ClientTestClusterConfiguration(numberOfNodes: 2, plugins: new[] {Knn, MapperMurmur3, Security})) { }
public ReplicatedReadOnlyCluster() : base(new ClientTestClusterConfiguration(numberOfNodes: 2, plugins: [Knn, MapperMurmur3, Security])
{
NoCleanupAfterNodeStopped = true
}) { }

protected override void SeedNode() => new DefaultSeeder(Client, new IndexSettings
{
NumberOfShards = 2,
NumberOfShards = 1,
NumberOfReplicas = 1
}).SeedNode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public class DefaultSeeder
public const string ProjectsAliasName = "projects-alias";
public const string TestsIndexTemplateName = "osc_tests";

public const string RemoteClusterName = "remote-cluster";

public const string PipelineName = "osc-pipeline";

private readonly IIndexSettings _defaultIndexSettings = new IndexSettings()
Expand Down Expand Up @@ -117,11 +115,6 @@ public async Task ClusterSettingsAsync()
{ "cluster.routing.use_adaptive_replica_selection", true }
};

clusterConfiguration += new RemoteClusterConfiguration
{
{ RemoteClusterName, "127.0.0.1:9300" }
};

var putSettingsResponse = await Client.Cluster.PutSettingsAsync(new ClusterPutSettingsRequest
{
Transient = clusterConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Linq;
using System.Threading;
using FluentAssertions;
using OpenSearch.Client;
using OpenSearch.Net;
Expand Down Expand Up @@ -45,9 +46,11 @@ protected override void ExpectResponse(CatResponse<CatSegmentReplicationRecord>
response.Records.Should().NotBeEmpty().And.AllSatisfy(r => r.ShardId.Should().StartWith($"[{IndexName}]"));

protected override void IntegrationSetup(IOpenSearchClient client, CallUniqueValues values)
{
{
var resp = client.Indices.Create(IndexName, d => d
.Settings(s => s
.NumberOfShards(1)
.NumberOfReplicas(1)
.Setting("index.replication.type", "SEGMENT")));
resp.ShouldBeValid();

Expand All @@ -56,9 +59,16 @@ protected override void IntegrationSetup(IOpenSearchClient client, CallUniqueVal
.IndexMany(Enumerable.Range(0, 10).Select(i => new Doc { Id = i }))
.Refresh(Refresh.WaitFor));
bulkResp.ShouldBeValid();
}

protected override void IntegrationTeardown(IOpenSearchClient client, CallUniqueValues values) => client.Indices.Delete(IndexName);
var healthResp = client.Cluster.Health(IndexName, d => d
.WaitForStatus(HealthStatus.Green)
.WaitForNodes("2")
.Timeout("30s")
.Level(ClusterHealthLevel.Shards)
.WaitForNoInitializingShards()
.WaitForNoRelocatingShards());
healthResp.ShouldBeValid();
}

public class Doc
{
Expand Down

0 comments on commit d371168

Please sign in to comment.