PCRB follow up endpoints
This commit is contained in:
48
MesaFabApproval.API/Utilities/MonInUtils.cs
Normal file
48
MesaFabApproval.API/Utilities/MonInUtils.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using MesaFabApproval;
|
||||
using MesaFabApproval.API;
|
||||
using MesaFabApproval.API.Services;
|
||||
using MesaFabApproval.API.Utilities;
|
||||
using MesaFabApproval.Shared.Models;
|
||||
using MesaFabApproval.Shared.Services;
|
||||
|
||||
namespace MesaFabApproval.API.Utilities;
|
||||
|
||||
public interface IMonInUtils {
|
||||
public void PostMetrics(string metricName,
|
||||
double latency,
|
||||
bool isArgumentError,
|
||||
bool isInternalError);
|
||||
}
|
||||
|
||||
public class MonInUtils : IMonInUtils {
|
||||
private readonly IMonInWorkerClient _monInClient;
|
||||
private readonly ILogger<MonInUtils> _logger;
|
||||
|
||||
public MonInUtils(IMonInWorkerClient monInClient, ILogger<MonInUtils> logger) {
|
||||
_monInClient = monInClient ??
|
||||
throw new ArgumentNullException("IMonInWorkerClient not injected");
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException("ILogger not injected");
|
||||
}
|
||||
|
||||
public void PostMetrics(string metricName,
|
||||
double latency,
|
||||
bool isArgumentError,
|
||||
bool isInternalError) {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to post metrics to MonIn");
|
||||
|
||||
_monInClient.PostAverage(metricName + "Latency", latency);
|
||||
|
||||
if (isArgumentError) {
|
||||
_monInClient.PostStatus(metricName, StatusValue.Ok);
|
||||
} else if (isInternalError) {
|
||||
_monInClient.PostStatus(metricName, StatusValue.Critical);
|
||||
} else {
|
||||
_monInClient.PostStatus(metricName, StatusValue.Ok);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to post metrics to MonIn, because {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user