This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging dev to master to release version 4.2.0 (#82)
* Add EventHub output logging. Fixes #60. * Unifying logging of exceptions. Fixes #59. * Fix nuget errors on pack (#73) * Increasing max message size and batch size. Fixes #29 * User configurable initial offset support (#79) * Instructions via Readme.md for setting up local environment to run integration tests Co-authored-by: Alexey Rodionov <alrod@microsoft.com> Co-authored-by: Pragna Gopa <pgopa@microsoft.com> Co-authored-by: Sid Krishna <sidkri@microsoft.com>
- Loading branch information
1 parent
daab3ae
commit 738c799
Showing
18 changed files
with
442 additions
and
75 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
### Release notes | ||
<!-- Please add your release notes in the following format: | ||
- My change description (#PR) | ||
--> | ||
#### Version 4.2.0 | ||
- User configurable initial offset support [#79](https://github.com/Azure/azure-functions-eventhubs-extension/pull/79) | ||
|
||
**Release sprint:** Sprint 87 | ||
[ [bugs](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+87%22+label%3Abug+is%3Aclosed) | [features](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+87%22+label%3Afeature+is%3Aclosed) ] |
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
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
24 changes: 24 additions & 0 deletions
24
src/Microsoft.Azure.WebJobs.Extensions.EventHubs/Config/InitialOffsetOptions.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,24 @@ | ||
// 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.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Text; | ||
using Microsoft.Azure.EventHubs; | ||
using Microsoft.Azure.EventHubs.Processor; | ||
using Microsoft.Azure.WebJobs.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Options; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.Azure.WebJobs.EventHubs | ||
{ | ||
public class InitialOffsetOptions | ||
{ | ||
public string Type { get; set; } = ""; | ||
public string EnqueuedTimeUTC { get; set; } = ""; | ||
} | ||
} |
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
100 changes: 100 additions & 0 deletions
100
src/Microsoft.Azure.WebJobs.Extensions.EventHubs/Utility.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,100 @@ | ||
// 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 Microsoft.Azure.EventHubs; | ||
using Microsoft.Azure.EventHubs.Processor; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.WindowsAzure.Storage; | ||
using LogLevel = Microsoft.Extensions.Logging.LogLevel; | ||
|
||
namespace Microsoft.Azure.WebJobs.EventHubs | ||
{ | ||
internal class Utility | ||
{ | ||
public static void LogException(Exception ex, string message, ILogger logger) | ||
{ | ||
try | ||
{ | ||
// Sometimes EventHub SDK aggregates an exception | ||
AggregateException ae = ex as AggregateException; | ||
if (ae != null && ae.InnerExceptions != null && ae.InnerExceptions.Count == 1) | ||
{ | ||
ex = ae.InnerExceptions[0]; | ||
} | ||
|
||
LogLevel logLevel = GetLevel(ex); | ||
if (logLevel == LogLevel.Information) | ||
{ | ||
message = $"{message} An exception of type '{ex.GetType().Name}' was thrown. This exception type is typically a result of Event Hub processor rebalancing or a transient error and can be safely ignored."; | ||
} | ||
logger?.Log(logLevel, 0, message, ex, (s, exc) => message); | ||
} | ||
catch | ||
{ | ||
// best effort logging | ||
} | ||
} | ||
|
||
private static LogLevel GetLevel(Exception ex) | ||
{ | ||
if (ex == null) | ||
{ | ||
throw new ArgumentNullException("ex"); | ||
} | ||
|
||
if (ex is ReceiverDisconnectedException || ex is LeaseLostException | ||
|| IsConflictLeaseIdMismatchWithLeaseOperation(ex)) | ||
{ | ||
// For EventProcessorHost these exceptions can happen as part | ||
// of normal partition balancing across instances, so we want to | ||
// trace them, but not treat them as errors. | ||
return LogLevel.Information; | ||
} | ||
|
||
var ehex = ex as EventHubsException; | ||
if (!(ex is OperationCanceledException) && (ehex == null || !ehex.IsTransient)) | ||
{ | ||
// any non-transient exceptions or unknown exception types | ||
// we want to log as errors | ||
return LogLevel.Error; | ||
} | ||
else | ||
{ | ||
// transient messaging errors we log as info so we have a record | ||
// of them, but we don't treat them as actual errors | ||
return LogLevel.Information; | ||
} | ||
} | ||
|
||
public static bool IsConflictLeaseIdMismatchWithLeaseOperation(Exception ex) | ||
{ | ||
StorageException exception = ex as StorageException; | ||
if (exception == null) | ||
{ | ||
return false; | ||
} | ||
|
||
RequestResult result = exception.RequestInformation; | ||
|
||
if (result == null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (result.HttpStatusCode != 409) | ||
{ | ||
return false; | ||
} | ||
|
||
StorageExtendedErrorInformation extendedInformation = result.ExtendedErrorInformation; | ||
|
||
if (extendedInformation == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return extendedInformation.ErrorCode == "LeaseIdMismatchWithLeaseOperation"; | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.