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: add fixes from 0.12.x #223

Closed
wants to merge 17 commits into from
Closed
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
12 changes: 4 additions & 8 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 @@ -215,7 +218,7 @@ jobs:
tls: ${{ matrix.tls }}
mtls: ${{ matrix.mtls }}
ext-csharp-version: ${{ needs.versionning.outputs.version }}
core-version: 0.14.0-SNAPSHOT.138.2c9f7407
core-version: 0.14.3

- name: Setup hosts file
run : echo -e "$(kubectl get svc ingress -n armonik -o jsonpath={.status.loadBalancer.ingress[0].ip})\tarmonik.local" | sudo tee -a /etc/hosts
Expand Down Expand Up @@ -263,13 +266,6 @@ jobs:
name: "IntegrationTests tls:${{ matrix.tls }} mtls:${{ matrix.mtls }} val:${{ matrix.sslvalidation }} ca:${{ matrix.useca }}"
path: ./Tests/ArmoniK.EndToEndTests/ArmoniK.EndToEndTests.Client/TestResults/test-results.trx
reporter: dotnet-trx

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

canMerge:
needs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ArmoniK.Api.Client" Version="3.10.0" />
<PackageReference Include="ArmoniK.Api.Client" Version="3.11.0" />
<PackageReference Include="Grpc.Core" Version="2.46.6" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
Expand Down
70 changes: 62 additions & 8 deletions Client/src/Common/Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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 @@ -109,17 +113,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 @@ -153,6 +163,35 @@ public Properties(IConfiguration configuration,
ClientKeyFilePem = clientKeyFilePem ?? sectionGrpc?[SectionClientKey];
ClientP12File = clientP12 ?? sectionGrpc?[SectionClientCertP12];

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 @@ -278,4 +317,19 @@ public string ConnectionString
/// The target name of the endpoint when ssl validation is disabled. Automatic if not set.
/// </summary>
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);
}
6 changes: 6 additions & 0 deletions Client/src/Common/Submitter/BaseClientSubmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ public void WaitForTasksCompletion(IEnumerable<string> taskIds)
});
},
true,
Logger,
typeof(IOException),
typeof(RpcException));
}
Expand Down Expand Up @@ -409,6 +410,7 @@ public ResultStatusCollection GetResultStatus(IEnumerable<string> taskIds,
return resultStatusReply.IdStatuses;
},
true,
Logger,
typeof(IOException),
typeof(RpcException));

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

Expand Down Expand Up @@ -543,6 +546,7 @@ public byte[] GetResult(string taskId,
}
},
true,
Logger,
typeof(IOException),
typeof(RpcException));

Expand All @@ -552,6 +556,7 @@ public byte[] GetResult(string taskId,
cancellationToken)
.Result,
true,
Logger,
typeof(IOException),
typeof(RpcException));

Expand Down Expand Up @@ -746,6 +751,7 @@ public byte[] TryGetResult(string taskId,
}
},
true,
Logger,
typeof(IOException),
typeof(RpcException));

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

var currentBackoff = properties.RetryInitialBackoff;
for (var retry = 0; retry < maxRetries; retry++)
{
try
Expand Down Expand Up @@ -214,11 +215,14 @@ public Service(Properties properties,

Logger?.LogWarning(e,
"Fail to submit, {retry}/{maxRetries} retrying",
retry,
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 @@ -674,6 +678,7 @@ private void ProxyTryGetResults(IEnumerable<string> taskIds,
.Result;
},
true,
Logger,
typeof(IOException),
typeof(RpcException)));
}
Expand Down
69 changes: 68 additions & 1 deletion Common/src/Common/RetryAction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is part of the ArmoniK project
// This file is part of the ArmoniK project
//
// Copyright (C) ANEO, 2021-2023.All rights reserved.
//
Expand All @@ -18,6 +18,10 @@
using System.Linq;
using System.Threading;

using JetBrains.Annotations;

using Microsoft.Extensions.Logging;

namespace ArmoniK.DevelopmentKit.Common;

/// <summary>
Expand Down Expand Up @@ -67,6 +71,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,
[CanBeNull] 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 +114,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 +124,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 +156,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,
[CanBeNull] 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 +198,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 +208,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
Loading
Loading