diff --git a/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/src/Listeners/EventHubMetricsProvider.cs b/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/src/Listeners/EventHubMetricsProvider.cs index 52bb424b36fc..920a8afc6a86 100644 --- a/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/src/Listeners/EventHubMetricsProvider.cs +++ b/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/src/Listeners/EventHubMetricsProvider.cs @@ -72,7 +72,7 @@ public async Task GetMetricsAsync() } await Task.WhenAll(partitionPropertiesTasks).ConfigureAwait(false); - EventProcessorCheckpoint[] checkpoints; + EventProcessorCheckpoint[] checkpoints = null; try { @@ -81,7 +81,6 @@ public async Task GetMetricsAsync() catch { // GetCheckpointsAsync would log - return metrics; } return CreateTriggerMetrics(partitionPropertiesTasks.Select(t => t.Result).ToList(), checkpoints); @@ -103,7 +102,11 @@ private EventHubsTriggerMetrics CreateTriggerMetrics(List p { var partitionProperties = partitionRuntimeInfo[i]; - var checkpoint = (BlobCheckpointStoreInternal.BlobStorageCheckpoint)checkpoints.SingleOrDefault(c => c?.PartitionId == partitionProperties.Id); + BlobCheckpointStoreInternal.BlobStorageCheckpoint checkpoint = null; + if (checkpoints != null) + { + checkpoint = (BlobCheckpointStoreInternal.BlobStorageCheckpoint)checkpoints.SingleOrDefault(c => c?.PartitionId == partitionProperties.Id); + } // Check for the unprocessed messages when there are messages on the Event Hub partition // In that case, LastEnqueuedSequenceNumber will be >= 0 diff --git a/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/tests/EventHubsMetricsProviderTests.cs b/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/tests/EventHubsMetricsProviderTests.cs index 807edc3ba860..023a280be946 100644 --- a/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/tests/EventHubsMetricsProviderTests.cs +++ b/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/tests/EventHubsMetricsProviderTests.cs @@ -206,7 +206,7 @@ public async Task CreateTriggerMetrics_HandlesExceptions() var metrics = await _metricsProvider.GetMetricsAsync(); Assert.AreEqual(1, metrics.PartitionCount); - Assert.AreEqual(0, metrics.EventCount); + Assert.AreEqual(1, metrics.EventCount); Assert.AreNotEqual(default(DateTime), metrics.Timestamp); // Generic Exception @@ -222,7 +222,7 @@ public async Task CreateTriggerMetrics_HandlesExceptions() metrics = await _metricsProvider.GetMetricsAsync(); Assert.AreEqual(1, metrics.PartitionCount); - Assert.AreEqual(0, metrics.EventCount); + Assert.AreEqual(1, metrics.EventCount); Assert.AreNotEqual(default(DateTime), metrics.Timestamp); _loggerProvider.ClearAllLogMessages();