From 7e39fae7b01f4aa292abbe757685f1e60b629977 Mon Sep 17 00:00:00 2001 From: Matias Quaranta Date: Mon, 12 Feb 2024 10:06:27 -0800 Subject: [PATCH] [Cosmos DB] Release 4.5.0 (#884) * Bumping SDK * temporary fix * test * package bump --- build/common.props | 2 +- .../Trigger/CosmosDBMetricsProvider.cs | 8 ++++++++ .../WebJobs.Extensions.CosmosDB.csproj | 2 +- .../Trigger/CosmosDBMetricsProviderTests.cs | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/build/common.props b/build/common.props index 5ed8fc2f2..551a5e2f0 100644 --- a/build/common.props +++ b/build/common.props @@ -3,7 +3,7 @@ 3.0.0$(VersionSuffix) 5.0.0$(VersionSuffix) - 4.4.2$(VersionSuffix) + 4.5.0$(VersionSuffix) 3.2.0$(VersionSuffix) 3.0.0$(VersionSuffix) 3.0.3$(VersionSuffix) diff --git a/src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBMetricsProvider.cs b/src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBMetricsProvider.cs index d1d58e7d0..400e5f6c7 100644 --- a/src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBMetricsProvider.cs +++ b/src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBMetricsProvider.cs @@ -61,6 +61,14 @@ public async Task GetMetricsAsync() partitionCount = partitionWorkList.Count; remainingWork = partitionWorkList.Sum(item => item.EstimatedLag); } + catch (CosmosException cosmosException) when (cosmosException.StatusCode == HttpStatusCode.Gone) + { + // Temporary handling of split issue described in https://github.com/Azure/azure-cosmos-dotnet-v3/issues/4285 + // This happens if the main instance is not running, potentially using Consumption Plan + // In this case, we return a positive value to make the Scale Controller consider spinning at least a single instance + partitionCount = 1; + remainingWork = 1; + } catch (Exception e) when (e is CosmosException || e is InvalidOperationException) { if (!TryHandleCosmosException(e)) diff --git a/src/WebJobs.Extensions.CosmosDB/WebJobs.Extensions.CosmosDB.csproj b/src/WebJobs.Extensions.CosmosDB/WebJobs.Extensions.CosmosDB.csproj index 3c754cd40..f842f6ded 100644 --- a/src/WebJobs.Extensions.CosmosDB/WebJobs.Extensions.CosmosDB.csproj +++ b/src/WebJobs.Extensions.CosmosDB/WebJobs.Extensions.CosmosDB.csproj @@ -19,7 +19,7 @@ - + diff --git a/test/WebJobs.Extensions.CosmosDB.Tests/Trigger/CosmosDBMetricsProviderTests.cs b/test/WebJobs.Extensions.CosmosDB.Tests/Trigger/CosmosDBMetricsProviderTests.cs index 6da53c646..c823e23b8 100644 --- a/test/WebJobs.Extensions.CosmosDB.Tests/Trigger/CosmosDBMetricsProviderTests.cs +++ b/test/WebJobs.Extensions.CosmosDB.Tests/Trigger/CosmosDBMetricsProviderTests.cs @@ -163,5 +163,24 @@ public async Task GetMetrics_HandlesExceptions() warning = _loggerProvider.GetAllLogMessages().Single(p => p.Level == Microsoft.Extensions.Logging.LogLevel.Warning); Assert.Equal("CosmosDBTrigger Exception message: Uh oh again.", warning.FormattedMessage); } + + [Fact] + public async Task GetMetrics_HandleSplit() + { + _estimatorIterator + .SetupSequence(m => m.HasMoreResults) + .Returns(true) + .Returns(false); + + _estimatorIterator + .Setup(m => m.ReadNextAsync(It.IsAny())) + .ThrowsAsync(new CosmosException("Partition is gone", HttpStatusCode.Gone, 1002, string.Empty, 0)); + + var metrics = await _cosmosDbMetricsProvider.GetMetricsAsync(); + + Assert.Equal(1, metrics.PartitionCount); + Assert.Equal(1, metrics.RemainingWork); + Assert.NotEqual(default(DateTime), metrics.Timestamp); + } } }