Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: merge 0.12.x fixes to main #224

Merged
merged 19 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ on:
push:
branches:
- main
- "[0-9]+.[0-9]+.x"
pull_request:
branches:
- main
- "[0-9]+.[0-9]+.x"


jobs:
versionning:
Expand Down Expand Up @@ -304,13 +307,6 @@ jobs:
name: end2end-${{ matrix.tls }}-${{ matrix.mtls }}-${{ matrix.sslvalidation }}-${{ matrix.useca }}.tar.gz
path: end2end-${{ matrix.tls }}-${{ matrix.mtls }}-${{ matrix.sslvalidation }}-${{ matrix.useca }}.tar.gz
retention-days: 2

- name: Destroy deployment
if: success() || failure()
uses: aneoconsulting/ArmoniK.Action.Deploy/destroy@main
with:
working-directory: ${{ github.workspace }}/infra
type: localhost


test-container:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<PackageReference Include="ArmoniK.Api.Client" Version="3.11.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
</ItemGroup>

Expand Down
72 changes: 63 additions & 9 deletions Client/src/Common/Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public class Properties
private const string SectionClientCertP12 = "ClientP12";
private const string SectionTargetNameOverride = "EndpointNameOverride";

private const string SectionRetryInitialBackoff = "RetryInitialBackoff";
private const string SectionRetryBackoffMultiplier = "RetryBackoffMultiplier";
private const string SectionRetryMaxBackoff = "RetryMaxBackoff";

/// <summary>
/// The default configuration to submit task in a Session
/// </summary>
Expand Down Expand Up @@ -117,17 +121,23 @@ public Properties(TaskOptions options,
/// <param name="clientKeyFilePem">The client key file in a pem format</param>
/// <param name="clientP12">The client certificate in a P12/Pkcs12/PFX format</param>
/// <param name="sslValidation">Disable the ssl strong validation of ssl certificate (default : enable => true)</param>
/// <param name="retryInitialBackoff">Initial retry backoff delay</param>
/// <param name="retryBackoffMultiplier">Retry backoff multiplier</param>
/// <param name="retryMaxBackoff">Max retry backoff</param>
/// <exception cref="ArgumentException"></exception>
public Properties(IConfiguration configuration,
TaskOptions options,
string? connectionAddress = null,
int connectionPort = 0,
string? protocol = null,
string? clientCertFilePem = null,
string? clientKeyFilePem = null,
string? clientP12 = null,
string? caCertPem = null,
bool? sslValidation = null)
string? connectionAddress = null,
int connectionPort = 0,
string? protocol = null,
string? clientCertFilePem = null,
string? clientKeyFilePem = null,
string? clientP12 = null,
string? caCertPem = null,
bool? sslValidation = null,
TimeSpan retryInitialBackoff = new(),
double retryBackoffMultiplier = 0,
TimeSpan retryMaxBackoff = new())
{
TaskOptions = options;
Configuration = configuration;
Expand Down Expand Up @@ -177,6 +187,35 @@ public Properties(IConfiguration configuration,
ClientKeyFilePem = clientKeyFilePem ?? sectionGrpc[SectionClientKey] ?? string.Empty;
ClientP12File = clientP12 ?? sectionGrpc[SectionClientCertP12] ?? string.Empty;

if (retryInitialBackoff != TimeSpan.Zero)
{
RetryInitialBackoff = retryInitialBackoff;
}
else if (!string.IsNullOrWhiteSpace(sectionGrpc?[SectionRetryInitialBackoff]))
{
RetryInitialBackoff = TimeSpan.Parse(sectionGrpc[SectionRetryInitialBackoff]);
}

if (retryBackoffMultiplier != 0)
{
RetryBackoffMultiplier = retryBackoffMultiplier;
}
else if (!string.IsNullOrWhiteSpace(sectionGrpc?[SectionRetryBackoffMultiplier]))
{
RetryBackoffMultiplier = double.Parse(sectionGrpc[SectionRetryBackoffMultiplier]);
}


if (retryMaxBackoff != TimeSpan.Zero)
{
RetryMaxBackoff = retryMaxBackoff;
}
else if (!string.IsNullOrWhiteSpace(sectionGrpc?[SectionRetryMaxBackoff]))
{
RetryMaxBackoff = TimeSpan.Parse(sectionGrpc[SectionRetryMaxBackoff]);
}


if (connectionPort != 0)
{
ConnectionPort = connectionPort;
Expand Down Expand Up @@ -314,5 +353,20 @@ public string ConnectionString
// TODO: mark as [PublicApi] for setter ?
// ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global
public string TargetNameOverride { get; set; }
public string TargetNameOverride { get; set; } = "";

/// <summary>
/// Initial backoff from retries
/// </summary>
public TimeSpan RetryInitialBackoff { get; } = TimeSpan.FromSeconds(1);

/// <summary>
/// Backoff multiplier for retries
/// </summary>
public double RetryBackoffMultiplier { get; } = 2;

/// <summary>
/// Max backoff for retries
/// </summary>
public TimeSpan RetryMaxBackoff { get; } = TimeSpan.FromSeconds(30);
}
4 changes: 4 additions & 0 deletions Client/src/Common/Submitter/BaseClientSubmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ public void WaitForTasksCompletion(IEnumerable<string> taskIds,
});
},
true,
Logger,
typeof(IOException),
typeof(RpcException));
}
Expand Down Expand Up @@ -449,6 +450,7 @@ public ResultStatusCollection GetResultStatus(IEnumerable<string> taskIds,
return resultStatusReply.IdStatuses;
},
true,
Logger,
typeof(IOException),
typeof(RpcException));

Expand Down Expand Up @@ -518,6 +520,7 @@ public ResultStatusCollection GetResultStatus(IEnumerable<string> taskIds,
.TaskResults);
},
true,
Logger,
typeof(IOException),
typeof(RpcException));

Expand Down Expand Up @@ -798,6 +801,7 @@ public IEnumerable<Tuple<string, byte[]>> GetResults(IEnumerable<string> taskIds
}
},
true,
Logger,
typeof(IOException),
typeof(RpcException));

Expand Down
15 changes: 10 additions & 5 deletions Client/src/Unified/Services/Submitter/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public Service(Properties properties,
request.ResultId = resultsIds[index];
}

var currentBackoff = properties.RetryInitialBackoff;
for (var retry = 0; retry < maxRetries; retry++)
{
try
Expand Down Expand Up @@ -175,13 +176,16 @@ public Service(Properties properties,
throw;
}

Logger.LogWarning(e,
"Fail to submit, {retry}/{maxRetries} retrying",
retry,
maxRetries);
Logger?.LogWarning(e,
"Fail to submit, {retry}/{maxRetries} retrying",
retry + 1,
maxRetries);

//Delay before submission
Task.Delay(TimeSpan.FromMilliseconds(1000));
Task.Delay(currentBackoff)
.Wait();
currentBackoff = TimeSpan.FromSeconds(Math.Min(currentBackoff.TotalSeconds * properties.RetryBackoffMultiplier,
properties.RetryMaxBackoff.TotalSeconds));
}
}

Expand Down Expand Up @@ -585,6 +589,7 @@ private void ProxyTryGetResults(IEnumerable<string> taskIds,
.Result;
},
true,
Logger,
typeof(IOException),
typeof(RpcException))!);
}
Expand Down
1 change: 1 addition & 0 deletions Common/src/Common/ArmoniK.DevelopmentKit.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<PackageReference Include="ArmoniK.Utils" Version="0.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
<PackageReference Include="protobuf-net" Version="3.2.26" />
</ItemGroup>
Expand Down
65 changes: 65 additions & 0 deletions Common/src/Common/RetryAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using System.Linq;
using System.Threading;

using Microsoft.Extensions.Logging;

namespace ArmoniK.DevelopmentKit.Common;

/// <summary>
Expand Down Expand Up @@ -67,6 +69,33 @@ public static void WhileException(int retries,
Action<int> operation,
bool allowDerivedExceptions = false,
params Type[] exceptionType)
=> WhileException(retries,
delayMs,
operation,
allowDerivedExceptions,
null,
exceptionType);

/// <summary>
/// Retry the specified operation the specified number of times, until there are no more retries or it succeeded
/// without an exception.
/// </summary>
/// <param name="retries">The number of times to retry the operation</param>
/// <param name="delayMs">The number of milliseconds to sleep after a failed invocation of the operation</param>
/// <param name="operation">the operation to perform</param>
/// <param name="exceptionType">if not null, ignore any exceptions of this type and subtypes</param>
/// <param name="allowDerivedExceptions">
/// If true, exceptions deriving from the specified exception type are ignored as
/// well. Defaults to False
/// </param>
/// <param name="logger">Logger to log retried exception</param>
/// <returns>When one of the retries succeeds, return the value the operation returned. If not, an exception is thrown.</returns>
public static void WhileException(int retries,
int delayMs,
Action<int> operation,
bool allowDerivedExceptions = false,
ILogger? logger = null,
params Type[] exceptionType)
{
// Do all but one retries in the loop
for (var retry = 1; retry < retries; retry++)
Expand All @@ -83,6 +112,8 @@ public static void WhileException(int retries,
if (exceptionType != null && allowDerivedExceptions && ex is AggregateException &&
exceptionType.Any(e => ex.InnerException != null && ex.InnerException.GetType() == e))
{
logger?.LogDebug("Got exception while executing function to retry : {ex}",
ex);
Thread.Sleep(delayMs);
}
else if (exceptionType == null || exceptionType.Any(e => e == ex.GetType()) || (allowDerivedExceptions && exceptionType.Any(e => ex.GetType()
Expand All @@ -91,6 +122,8 @@ public static void WhileException(int retries,
// Ignore exceptions when exceptionType is not specified OR
// the exception thrown was of the specified exception type OR
// the exception thrown is derived from the specified exception type and we allow that
logger?.LogDebug("Got exception while executing function to retry : {ex}",
ex);
Thread.Sleep(delayMs);
}
else
Expand Down Expand Up @@ -121,6 +154,34 @@ public static T WhileException<T>(int retries,
Func<int, T> operation,
bool allowDerivedExceptions = false,
params Type[] exceptionType)
=> WhileException(retries,
delayMs,
operation,
allowDerivedExceptions,
null,
exceptionType);

/// <summary>
/// Retry the specified operation the specified number of times, until there are no more retries or it succeeded
/// without an exception.
/// </summary>
/// <typeparam name="T">The return type of the exception</typeparam>
/// <param name="retries">The number of times to retry the operation</param>
/// <param name="delayMs">The number of milliseconds to sleep after a failed invocation of the operation</param>
/// <param name="operation">the operation to perform</param>
/// <param name="exceptionType">if not null, ignore any exceptions of this type and subtypes</param>
/// <param name="allowDerivedExceptions">
/// If true, exceptions deriving from the specified exception type are ignored as
/// well. Defaults to False
/// </param>
/// <param name="logger">Logger to log retried exception</param>
/// <returns>When one of the retries succeeds, return the value the operation returned. If not, an exception is thrown.</returns>
public static T WhileException<T>(int retries,
int delayMs,
Func<int, T> operation,
bool allowDerivedExceptions = false,
ILogger? logger = null,
params Type[] exceptionType)
{
// Do all but one retries in the loop
for (var retry = 1; retry < retries; retry++)
Expand All @@ -135,6 +196,8 @@ public static T WhileException<T>(int retries,
if (exceptionType != null && allowDerivedExceptions && ex is AggregateException &&
exceptionType.Any(e => ex.InnerException != null && ex.InnerException.GetType() == e))
{
logger?.LogDebug("Got exception while executing function to retry : {ex}",
ex);
Thread.Sleep(delayMs);
}
else if (exceptionType == null || exceptionType.Any(e => e == ex.GetType()) || (allowDerivedExceptions && exceptionType.Any(e => ex.GetType()
Expand All @@ -143,6 +206,8 @@ public static T WhileException<T>(int retries,
// Ignore exceptions when exceptionType is not specified OR
// the exception thrown was of the specified exception type OR
// the exception thrown is derived from the specified exception type and we allow that
logger?.LogDebug("Got exception while executing function to retry : {ex}",
ex);
Thread.Sleep(delayMs);
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
Expand Down
Loading