From 28decc8e9d9646502048d90754c412b630a8050d Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Sun, 22 Sep 2024 13:58:18 -0400 Subject: [PATCH 1/3] Wire ExcludeRegions for ReadMany. --- .../Resource/Container/ContainerInlineCore.cs | 4 +-- .../CosmosMultiRegionDiagnosticsTests.cs | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs index 2f9184527e..2bf366e577 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs @@ -442,7 +442,7 @@ public override Task ReadManyItemsStreamAsync( containerName: this.Id, databaseName: this.Database.Id, operationType: Documents.OperationType.Read, - requestOptions: null, + requestOptions: readManyRequestOptions, task: (trace) => base.ReadManyItemsStreamAsync(items, trace, readManyRequestOptions, cancellationToken), openTelemetry: new (OpenTelemetryConstants.Operations.ReadManyItems, (response) => new OpenTelemetryResponse(responseMessage: response))); } @@ -457,7 +457,7 @@ public override Task> ReadManyItemsAsync( containerName: this.Id, databaseName: this.Database.Id, operationType: Documents.OperationType.Read, - requestOptions: null, + requestOptions: readManyRequestOptions, task: (trace) => base.ReadManyItemsAsync(items, trace, readManyRequestOptions, cancellationToken), openTelemetry: new (OpenTelemetryConstants.Operations.ReadManyItems, (response) => new OpenTelemetryResponse(responseMessage: response))); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosMultiRegionDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosMultiRegionDiagnosticsTests.cs index 67859724c6..57c5361316 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosMultiRegionDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosMultiRegionDiagnosticsTests.cs @@ -65,6 +65,33 @@ public async Task ExlcudeRegionDiagnosticsTest() Assert.IsTrue(excludeRegionsList.Contains("East US")); } + [TestMethod] + [TestCategory("MultiRegion")] + public async Task ExcludeRegionWithReadManyDiagnosticsTest() + { + this.container = this.database.GetContainer(CosmosMultiRegionDiagnosticsTests.containerName); + + FeedResponse itemResponse = await this.container.ReadManyItemsAsync( + new List<(string, PartitionKey)>() + { + ("testId", new PartitionKey("pk")), + ("testId2", new PartitionKey("pk2")), + ("testId3", new PartitionKey("pk3")), + ("testId4", new PartitionKey("pk4")) + }, + new ReadManyRequestOptions() + { + ExcludeRegions = new List() { "North Central US", "East US" } + }); + + List excludeRegionsList; + CosmosTraceDiagnostics traceDiagnostic = itemResponse.Diagnostics as CosmosTraceDiagnostics; + traceDiagnostic.Value.Data.TryGetValue("ExcludedRegions", out object excludeRegionObject); + excludeRegionsList = excludeRegionObject as List; + Assert.IsTrue(excludeRegionsList.Contains("North Central US")); + Assert.IsTrue(excludeRegionsList.Contains("East US")); + } + [TestMethod] [TestCategory("MultiRegion")] public async Task HedgeNestingDiagnosticsTest() From 90830fbdf014804a520deef25db915e8ed259017 Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Sun, 22 Sep 2024 14:01:43 -0400 Subject: [PATCH 2/3] Wire ExcludeRegions for ReadMany. --- .../CosmosMultiRegionDiagnosticsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosMultiRegionDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosMultiRegionDiagnosticsTests.cs index 57c5361316..848af2adee 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosMultiRegionDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosMultiRegionDiagnosticsTests.cs @@ -71,7 +71,7 @@ public async Task ExcludeRegionWithReadManyDiagnosticsTest() { this.container = this.database.GetContainer(CosmosMultiRegionDiagnosticsTests.containerName); - FeedResponse itemResponse = await this.container.ReadManyItemsAsync( + FeedResponse feedResonse = await this.container.ReadManyItemsAsync( new List<(string, PartitionKey)>() { ("testId", new PartitionKey("pk")), @@ -85,7 +85,7 @@ public async Task ExcludeRegionWithReadManyDiagnosticsTest() }); List excludeRegionsList; - CosmosTraceDiagnostics traceDiagnostic = itemResponse.Diagnostics as CosmosTraceDiagnostics; + CosmosTraceDiagnostics traceDiagnostic = feedResonse.Diagnostics as CosmosTraceDiagnostics; traceDiagnostic.Value.Data.TryGetValue("ExcludedRegions", out object excludeRegionObject); excludeRegionsList = excludeRegionObject as List; Assert.IsTrue(excludeRegionsList.Contains("North Central US")); From b2c5009e65d38511e0d2246e4066cf414c3c8ded Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Sun, 22 Sep 2024 16:13:40 -0400 Subject: [PATCH 3/3] Wire ExcludeRegions for ReadMany. --- Microsoft.Azure.Cosmos/src/ReadManyRequestOptions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/src/ReadManyRequestOptions.cs b/Microsoft.Azure.Cosmos/src/ReadManyRequestOptions.cs index 842faaca76..7535d1c6bd 100644 --- a/Microsoft.Azure.Cosmos/src/ReadManyRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/ReadManyRequestOptions.cs @@ -68,7 +68,8 @@ internal QueryRequestOptions ConvertToQueryRequestOptions() IfMatchEtag = this.IfMatchEtag, IfNoneMatchEtag = this.IfNoneMatchEtag, Properties = this.Properties, - AddRequestHeaders = this.AddRequestHeaders + AddRequestHeaders = this.AddRequestHeaders, + ExcludeRegions = this.ExcludeRegions }; } }