From 13d06011f010f0f5fcccd66c7dd77b760e974e31 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Thu, 15 Aug 2024 13:03:32 +1200 Subject: [PATCH] Test fix? Signed-off-by: Thomas Farr --- .github/actions/build-opensearch/action.yml | 10 ++--- .github/workflows/integration.yml | 9 ++-- .../ClusterBase.cs | 41 ++++++++----------- .../Configuration/NodeConfiguration.cs | 9 ++-- .../OpenSearchNode.cs | 4 +- build/scripts/scripts.fsproj | 6 ++- .../Generator/ApiEndpointFactory.cs | 3 ++ .../_Generated/Descriptors.Cluster.cs | 4 +- .../_Generated/Requests.Cluster.cs | 6 +-- .../RequestParameters.Cluster.cs | 6 +-- .../Clusters/ReadOnlyCluster.cs | 14 +++++-- .../NodeSeeders/DefaultSeeder.cs | 9 ++-- .../CatSegmentReplicationApiTests.cs | 16 ++++++-- 13 files changed, 80 insertions(+), 57 deletions(-) diff --git a/.github/actions/build-opensearch/action.yml b/.github/actions/build-opensearch/action.yml index 8ad36ee266..9c3d640df0 100644 --- a/.github/actions/build-opensearch/action.yml +++ b/.github/actions/build-opensearch/action.yml @@ -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 }} @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 9daf1a834a..b6177c9bec 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -4,7 +4,7 @@ on: push: branches-ignore: - 'dependabot/**' - pull_request: {} + pull_request: { } env: OPENSEARCH_PLUGINS_DIRECTORY: /tmp/opensearch-plugins @@ -57,11 +57,14 @@ jobs: VERSION: ${{ matrix.version }} - name: Upload test report - if: failure() + if: always() + #failure() 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 diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/ClusterBase.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/ClusterBase.cs index 3cdb74e966..c14b11a619 100644 --- a/abstractions/src/OpenSearch.OpenSearch.Managed/ClusterBase.cs +++ b/abstractions/src/OpenSearch.OpenSearch.Managed/ClusterBase.cs @@ -75,29 +75,24 @@ 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 => + { + config.InitialClusterManagerNodes(initialClusterManagerNodes); + ModifyNodeConfiguration(config, config.DesiredPort ?? 9200); + + return new OpenSearchNode(config) { AssumeStartedOnNotEnoughClusterManagerPing = ClusterConfiguration.NumberOfNodes > 1 }; + }) + .ToArray(); Nodes = new ReadOnlyCollection(nodes); } diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeConfiguration.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeConfiguration.cs index 1e379e1470..57d2c33a2e 100644 --- a/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeConfiguration.cs +++ b/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeConfiguration.cs @@ -87,10 +87,13 @@ public Action 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 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}"; diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchNode.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchNode.cs index da8250901a..0ea0a83884 100644 --- a/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchNode.cs +++ b/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchNode.cs @@ -64,7 +64,7 @@ public OpenSearchNode(OpenSearchVersion version, string openSearchHome = null) /// doing the election. /// Useful to speed up starting multi node clusters /// - public bool AssumeStartedOnNotEnoughMasterPing { get; set; } + public bool AssumeStartedOnNotEnoughClusterManagerPing { get; set; } internal IConsoleLineHandler Writer { get; private set; } @@ -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; diff --git a/build/scripts/scripts.fsproj b/build/scripts/scripts.fsproj index e98ae8fc61..253f9523e5 100644 --- a/build/scripts/scripts.fsproj +++ b/build/scripts/scripts.fsproj @@ -32,15 +32,17 @@ license-header-fs.txt + + - + - + diff --git a/src/ApiGenerator/Generator/ApiEndpointFactory.cs b/src/ApiGenerator/Generator/ApiEndpointFactory.cs index 13d3b4887d..5d3f748e6c 100644 --- a/src/ApiGenerator/Generator/ApiEndpointFactory.cs +++ b/src/ApiGenerator/Generator/ApiEndpointFactory.cs @@ -289,6 +289,9 @@ private static string SanitizeDescription(this string description) { if (string.IsNullOrWhiteSpace(description)) return null; + description = Regex.Replace(description, "&", "&"); + description = Regex.Replace(description, "<", "<"); + description = Regex.Replace(description, ">", ">"); description = Regex.Replace(description, @"\s+", " "); if (!description.EndsWith('.')) description += '.'; diff --git a/src/OpenSearch.Client/_Generated/Descriptors.Cluster.cs b/src/OpenSearch.Client/_Generated/Descriptors.Cluster.cs index 426e0af0be..6150a2c27b 100644 --- a/src/OpenSearch.Client/_Generated/Descriptors.Cluster.cs +++ b/src/OpenSearch.Client/_Generated/Descriptors.Cluster.cs @@ -336,7 +336,7 @@ public ClusterHealthDescriptor WaitForActiveShards(string waitforactiveshards) = public ClusterHealthDescriptor WaitForEvents(WaitForEvents? waitforevents) => Qs("wait_for_events", waitforevents); - /// The request waits until the specified number N of nodes is available. It also accepts >=N, <=N, >N and + /// 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. public ClusterHealthDescriptor WaitForNodes(string waitfornodes) => Qs("wait_for_nodes", waitfornodes); @@ -350,7 +350,7 @@ public ClusterHealthDescriptor WaitForNoRelocatingShards( bool? waitfornorelocatingshards = true ) => Qs("wait_for_no_relocating_shards", waitfornorelocatingshards); - /// 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. + /// 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. public ClusterHealthDescriptor WaitForStatus(HealthStatus? waitforstatus) => Qs("wait_for_status", waitforstatus); } diff --git a/src/OpenSearch.Client/_Generated/Requests.Cluster.cs b/src/OpenSearch.Client/_Generated/Requests.Cluster.cs index 2132bd4bfa..60f7645108 100644 --- a/src/OpenSearch.Client/_Generated/Requests.Cluster.cs +++ b/src/OpenSearch.Client/_Generated/Requests.Cluster.cs @@ -458,8 +458,8 @@ public WaitForEvents? WaitForEvents } /// - /// The request waits until the specified number N of nodes is available. It also accepts >=N, <=N, >N and public string WaitForNodes { @@ -489,7 +489,7 @@ public bool? WaitForNoRelocatingShards /// /// 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 > yellow > red. By default, will not wait for any status. /// public HealthStatus? WaitForStatus { diff --git a/src/OpenSearch.Net/_Generated/Api/RequestParameters/RequestParameters.Cluster.cs b/src/OpenSearch.Net/_Generated/Api/RequestParameters/RequestParameters.Cluster.cs index 2c6f2b3b20..6415954714 100644 --- a/src/OpenSearch.Net/_Generated/Api/RequestParameters/RequestParameters.Cluster.cs +++ b/src/OpenSearch.Net/_Generated/Api/RequestParameters/RequestParameters.Cluster.cs @@ -367,8 +367,8 @@ public WaitForEvents? WaitForEvents } /// - /// The request waits until the specified number N of nodes is available. It also accepts >=N, <=N, >N and public string WaitForNodes { @@ -398,7 +398,7 @@ public bool? WaitForNoRelocatingShards /// /// 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 > yellow > red. By default, will not wait for any status. /// public HealthStatus? WaitForStatus { diff --git a/tests/Tests.Core/ManagedOpenSearch/Clusters/ReadOnlyCluster.cs b/tests/Tests.Core/ManagedOpenSearch/Clusters/ReadOnlyCluster.cs index 26186c3351..54172aa520 100644 --- a/tests/Tests.Core/ManagedOpenSearch/Clusters/ReadOnlyCluster.cs +++ b/tests/Tests.Core/ManagedOpenSearch/Clusters/ReadOnlyCluster.cs @@ -41,12 +41,20 @@ 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(); + }) + { + IncludeRemoteCluster = false + }.SeedNode(); } } diff --git a/tests/Tests.Core/ManagedOpenSearch/NodeSeeders/DefaultSeeder.cs b/tests/Tests.Core/ManagedOpenSearch/NodeSeeders/DefaultSeeder.cs index 23cc132c64..c840c5f3ea 100644 --- a/tests/Tests.Core/ManagedOpenSearch/NodeSeeders/DefaultSeeder.cs +++ b/tests/Tests.Core/ManagedOpenSearch/NodeSeeders/DefaultSeeder.cs @@ -66,6 +66,8 @@ public DefaultSeeder(IOpenSearchClient client) : this(client, null) { } private IIndexSettings IndexSettings { get; } + public bool IncludeRemoteCluster { get; set; } = true; + public void SeedNode() { var alreadySeeded = false; @@ -117,12 +119,9 @@ public async Task ClusterSettingsAsync() { "cluster.routing.use_adaptive_replica_selection", true } }; - clusterConfiguration += new RemoteClusterConfiguration - { - { RemoteClusterName, "127.0.0.1:9300" } - }; + if (IncludeRemoteCluster) clusterConfiguration += new RemoteClusterConfiguration { { RemoteClusterName, "127.0.0.1:9300" } }; - var putSettingsResponse = await Client.Cluster.PutSettingsAsync(new ClusterPutSettingsRequest + var putSettingsResponse = await Client.Cluster.PutSettingsAsync(new ClusterPutSettingsRequest { Transient = clusterConfiguration }).ConfigureAwait(false); diff --git a/tests/Tests/Cat/CatSegmentReplication/CatSegmentReplicationApiTests.cs b/tests/Tests/Cat/CatSegmentReplication/CatSegmentReplicationApiTests.cs index 1c5aab5b9e..b57ba1f6d3 100644 --- a/tests/Tests/Cat/CatSegmentReplication/CatSegmentReplicationApiTests.cs +++ b/tests/Tests/Cat/CatSegmentReplication/CatSegmentReplicationApiTests.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading; using FluentAssertions; using OpenSearch.Client; using OpenSearch.Net; @@ -45,9 +46,11 @@ protected override void ExpectResponse(CatResponse 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(); @@ -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 {