Skip to content

Commit

Permalink
[WebJobs][EventHubsExtension] Fix metrics when azure checkpoint conta…
Browse files Browse the repository at this point in the history
…iner does not exist (#43213)
  • Loading branch information
alrod committed Apr 9, 2024
1 parent 944e29d commit 3c07c4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task<EventHubsTriggerMetrics> GetMetricsAsync()
}

await Task.WhenAll(partitionPropertiesTasks).ConfigureAwait(false);
EventProcessorCheckpoint[] checkpoints;
EventProcessorCheckpoint[] checkpoints = null;

try
{
Expand All @@ -81,7 +81,6 @@ public async Task<EventHubsTriggerMetrics> GetMetricsAsync()
catch
{
// GetCheckpointsAsync would log
return metrics;
}

return CreateTriggerMetrics(partitionPropertiesTasks.Select(t => t.Result).ToList(), checkpoints);
Expand All @@ -103,7 +102,11 @@ private EventHubsTriggerMetrics CreateTriggerMetrics(List<PartitionProperties> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit 3c07c4f

Please sign in to comment.