add performance logging on demand, fix minion issues

This commit is contained in:
rootdarkarchon
2023-02-19 16:11:40 +01:00
parent 6cf0ecdef1
commit 44450b24b4
29 changed files with 580 additions and 294 deletions

View File

@@ -21,7 +21,7 @@ public partial class ApiController
{
private readonly Dictionary<string, DateTime> _verifiedUploadedHashes;
private readonly ConcurrentDictionary<Guid, bool> _downloadReady = new();
private bool currentUploadCancelled = false;
private bool _currentUploadCancelled = false;
private int _downloadId = 0;
public async Task<bool> CancelUpload()
@@ -148,7 +148,7 @@ public partial class ApiController
}
catch (HttpRequestException ex)
{
_logger.LogWarning($"Error during download of {requestUrl}, HttpStatusCode: {ex.StatusCode}");
_logger.LogWarning(ex, $"Error during download of {requestUrl}, HttpStatusCode: {ex.StatusCode}");
if (ex.StatusCode is HttpStatusCode.NotFound or HttpStatusCode.Unauthorized)
{
throw new Exception($"Http error {ex.StatusCode} (cancelled: {ct.IsCancellationRequested}): {requestUrl}", ex);
@@ -178,7 +178,7 @@ public partial class ApiController
}
catch (Exception ex)
{
_logger.LogWarning($"Error during file download of {requestUrl}", ex);
_logger.LogWarning(ex, $"Error during file download of {requestUrl}");
try
{
if (!tempPath.IsNullOrEmpty())
@@ -235,7 +235,7 @@ public partial class ApiController
}
catch (Exception ex)
{
_logger.LogCritical("Error during SendRequestInternal for " + requestMessage.RequestUri, ex);
_logger.LogCritical(ex, "Error during SendRequestInternal for " + requestMessage.RequestUri);
throw;
}
}
@@ -302,7 +302,7 @@ public partial class ApiController
}
catch (Exception ex)
{
_logger.LogCritical("Error during download of " + file.Hash, ex);
_logger.LogError(ex, "Error during download of " + file.Hash);
return;
}
@@ -329,9 +329,7 @@ public partial class ApiController
}
catch (Exception ex)
{
_logger.LogWarning("Issue adding file to the DB");
_logger.LogWarning(ex.Message);
_logger.LogWarning(ex.StackTrace);
_logger.LogWarning(ex, "Issue creating cache entry");
}
}
}).ConfigureAwait(false);
@@ -346,7 +344,7 @@ public partial class ApiController
try
{
currentUploadCancelled = await CancelUpload().ConfigureAwait(false);
_currentUploadCancelled = await CancelUpload().ConfigureAwait(false);
_uploadCancellationTokenSource = new CancellationTokenSource();
var uploadToken = _uploadCancellationTokenSource.Token;
@@ -366,12 +364,12 @@ public partial class ApiController
}
catch (Exception ex)
{
_logger.LogWarning("Error during upload of files", ex);
_logger.LogWarning(ex, "Error during upload of files");
}
finally
{
if (!currentUploadCancelled)
currentUploadCancelled = await CancelUpload().ConfigureAwait(false);
if (!_currentUploadCancelled)
_currentUploadCancelled = await CancelUpload().ConfigureAwait(false);
}
}
@@ -413,7 +411,7 @@ public partial class ApiController
}
catch (Exception ex)
{
_logger.LogWarning("Tried to request file " + file.Hash + " but file was not present", ex);
_logger.LogWarning(ex, "Tried to request file " + file.Hash + " but file was not present");
}
}

View File

@@ -22,7 +22,7 @@ public partial class ApiController
}
catch (Exception ex)
{
_logger.LogWarning("Failed to Push character data: " + ex.Message);
_logger.LogWarning(ex, "Failed to Push character data");
}
}

View File

@@ -19,7 +19,7 @@ public partial class ApiController
}
catch (Exception ex)
{
_logger.LogCritical("Error on executing safely", ex);
_logger.LogCritical(ex, "Error on executing safely");
}
}

View File

@@ -107,7 +107,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
get => _serverState;
private set
{
_logger.LogDebug($"New ServerState: {value}, prev ServerState: {_serverState}");
_logger.LogDebug("New ServerState: {value}, prev ServerState: {_serverState}", value, _serverState);
_serverState = value;
}
}
@@ -209,23 +209,21 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
}
catch (HttpRequestException ex)
{
_logger.LogWarning("HttpRequestException on Connection", ex);
_logger.LogWarning(ex, "HttpRequestException on Connection");
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
await StopConnection(token, ServerState.Unauthorized).ConfigureAwait(false);
return;
}
else
{
ServerState = ServerState.Reconnecting;
_logger.LogInformation("Failed to establish connection, retrying");
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token).ConfigureAwait(false);
}
ServerState = ServerState.Reconnecting;
_logger.LogInformation("Failed to establish connection, retrying");
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogWarning("Exception on Connection", ex);
_logger.LogWarning(ex, "Exception on Connection");
_logger.LogInformation("Failed to establish connection, retrying");
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token).ConfigureAwait(false);
@@ -238,7 +236,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
while (!ct.IsCancellationRequested && _mareHub != null)
{
await Task.Delay(TimeSpan.FromSeconds(30), ct).ConfigureAwait(false);
var needsRestart = await CheckClientHealth().ConfigureAwait(false);
_ = await CheckClientHealth().ConfigureAwait(false);
_logger.LogDebug("Checked Client Health State");
}
}
@@ -271,12 +269,12 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
foreach (var userPair in await UserGetPairedClients().ConfigureAwait(false))
{
_logger.LogDebug($"Pair: {userPair}");
_logger.LogDebug("Individual Pair: {userPair}", userPair);
_pairManager.AddUserPair(userPair, addToLastAddedUser: false);
}
foreach (var entry in await GroupsGetAll().ConfigureAwait(false))
{
_logger.LogDebug($"Group: {entry}");
_logger.LogDebug("Group: {entry}", entry);
_pairManager.AddGroup(entry);
}
foreach (var group in _pairManager.GroupPairs.Keys)
@@ -284,7 +282,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
var users = await GroupsGetUsersInGroup(group).ConfigureAwait(false);
foreach (var user in users)
{
_logger.LogDebug($"GroupPair: {user}");
_logger.LogDebug("Group Pair: {user}", user);
_pairManager.AddGroupPair(user);
}
}
@@ -367,7 +365,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
_healthCheckTokenSource?.Cancel();
ServerState = ServerState.Reconnecting;
Mediator.Publish(new NotificationMessage("Connection lost", "Connection lost to " + _serverManager.CurrentServer!.ServerName, NotificationType.Warning, 5000));
_logger.LogWarning("Connection closed... Reconnecting", arg);
_logger.LogWarning(arg, "Connection closed... Reconnecting");
return Task.CompletedTask;
}