-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cosmos DB] Adds more Change Feed logs (#753)
This PR adds back the CosmosDBTriggerHealthMonitor leveraging the new Notification APIs to log: When a lease is acquired When a lease is released When changes are delivered to a Function (before user code is processed) When there are errors handling a lease, due to user unhandled exceptions or any Cosmos related failures
- Loading branch information
Showing
5 changed files
with
293 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.CosmosDB | ||
{ | ||
public static class Constants | ||
{ | ||
public const string DefaultConnectionStringName = "CosmosDB"; | ||
} | ||
|
||
internal static class Events | ||
{ | ||
public static readonly EventId OnError = new EventId(1, "OnTriggerError"); | ||
public static readonly EventId OnAcquire = new EventId(2, "OnTriggerAcquire"); | ||
public static readonly EventId OnRelease = new EventId(3, "OnTriggerRelease"); | ||
public static readonly EventId OnDelivery = new EventId(4, "OnTriggerDelivery"); | ||
public static readonly EventId OnListenerStopError = new EventId(5, "OnTriggerListenerStopError"); | ||
public static readonly EventId OnScaling = new EventId(6, "OnScaling"); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBTriggerHealthMonitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Cosmos; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.CosmosDB | ||
{ | ||
internal class CosmosDBTriggerHealthMonitor | ||
{ | ||
private readonly ILogger logger; | ||
|
||
public CosmosDBTriggerHealthMonitor(ILogger logger) | ||
{ | ||
this.logger = logger; | ||
} | ||
|
||
public Task OnErrorAsync(string leaseToken, Exception exception) | ||
{ | ||
switch (exception) | ||
{ | ||
case ChangeFeedProcessorUserException userException: | ||
this.logger.LogWarning(Events.OnError, userException.InnerException, "Lease {LeaseToken} encountered an unhandled user exception during processing.", leaseToken); | ||
this.logger.LogDebug(Events.OnError, "Lease {LeaseToken} has error diagnostics {Diagnostics}", leaseToken, userException.ChangeFeedProcessorContext.Diagnostics); | ||
break; | ||
case CosmosException cosmosException when cosmosException.StatusCode == HttpStatusCode.RequestTimeout || cosmosException.StatusCode == HttpStatusCode.ServiceUnavailable: | ||
this.logger.LogWarning(Events.OnError, cosmosException, "Lease {LeaseToken} experiencing transient connectivity issues.", leaseToken); | ||
break; | ||
default: | ||
this.logger.LogError(Events.OnError, exception, "Lease {LeaseToken} experienced an error during processing.", leaseToken); | ||
break; | ||
} | ||
|
||
if (exception is CosmosException asCosmosException) | ||
{ | ||
this.logger.LogDebug(Events.OnError, "Lease {LeaseToken} has error diagnostics {Diagnostics}", leaseToken, asCosmosException.Diagnostics); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Task OnLeaseAcquireAsync(string leaseToken) | ||
{ | ||
this.logger.LogDebug(Events.OnAcquire, "Lease {LeaseToken} was acquired to start processing.", leaseToken); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task OnLeaseReleaseAsync(string leaseToken) | ||
{ | ||
this.logger.LogDebug(Events.OnRelease, "Lease {LeaseToken} was released.", leaseToken); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public void OnChangesDelivered(ChangeFeedProcessorContext context) | ||
{ | ||
this.logger.LogDebug(Events.OnDelivery, "Events delivered to lease {LeaseToken} with diagnostics {Diagnostics}", context.LeaseToken, context.Diagnostics); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.