-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGaugeLogMetrics.cs
115 lines (103 loc) · 5.85 KB
/
GaugeLogMetrics.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System.Collections.Concurrent;
using Hudl.Mjolnir.External;
namespace Hudl.Mjolnir.Events
{
public class GaugeLogMetrics : IMetricEvents
{
private IMjolnirLog<GaugeLogMetrics> _diagnosticLog;
private IMjolnirLog<GaugeLogMetrics> _concurrencyExceededLog;
private IMjolnirLog<GaugeLogMetrics> _breakerTrippedLog;
private IMjolnirLog<GaugeLogMetrics> _bulkheadGaugeLog;
private IMjolnirLog<GaugeLogMetrics> _breakerGaugeLog;
private ConcurrentDictionary<string, int> _currentBulkheadsRejected;
public GaugeLogMetrics(IMjolnirLogFactory logFactory)
{
_diagnosticLog = logFactory.CreateLog<GaugeLogMetrics>();
_diagnosticLog.SetLogName($"{nameof(GaugeLogMetrics)}.Diagnostic");
_concurrencyExceededLog = logFactory.CreateLog<GaugeLogMetrics>();
_concurrencyExceededLog.SetLogName($"{nameof(GaugeLogMetrics)}.BulkheadConcurrencyExceeded");
_breakerTrippedLog = logFactory.CreateLog<GaugeLogMetrics>();
_breakerTrippedLog.SetLogName($"{nameof(GaugeLogMetrics)}.BreakerTripped");
_bulkheadGaugeLog = logFactory.CreateLog<GaugeLogMetrics>();
_bulkheadGaugeLog.SetLogName($"{nameof(GaugeLogMetrics)}.BulkheadGauge");
_breakerGaugeLog = logFactory.CreateLog<GaugeLogMetrics>();
_breakerGaugeLog.SetLogName($"{nameof(GaugeLogMetrics)}.BreakerGauge");
_currentBulkheadsRejected = new ConcurrentDictionary<string, int>();
}
public void BreakerFailureCount(string breakerName, string commandName)
{
_diagnosticLog.Debug($"BreakerFailureCount - [Breaker={breakerName}, Command={commandName}]");
}
public void BreakerFixed(string breakerName)
{
var log = $"BreakerFixed - [Breaker={breakerName}]";
_diagnosticLog.Debug(log);
_breakerTrippedLog.Debug(log);
}
public void BreakerGauge(string breakerName, long configuredMinimumOperations, long configuredWindowMillis, int configuredThresholdPercent, long configuredTrippedDurationMillis, bool configuredForceTripped, bool configuredForceFixed, bool isTripped, long windowSuccessCount, long windowFailureCount)
{
var log = $"BreakerGauge - [Breaker={breakerName}, ConfiguredMinimumOperations={configuredMinimumOperations}, ConfiguredWindowMs={configuredWindowMillis}, ConfiguredThresholdPercent={configuredThresholdPercent}, ConfiguredTrippedDurationMs={configuredTrippedDurationMillis}, ConfiguredForceTripped={configuredForceTripped}, ConfiguredForcedFixed={configuredForceFixed}, IsTripped={isTripped}, WindowSuccessCount={windowSuccessCount}, WindowFailureCount={windowFailureCount}]";
_diagnosticLog.Debug(log);
_breakerGaugeLog.Debug(log);
if (isTripped)
{
_breakerTrippedLog.Debug(log);
}
}
public void BreakerSuccessCount(string breakerName, string commandName)
{
_diagnosticLog.Debug($"BreakerSuccessCount - [Breaker={breakerName}, Command={commandName}]");
}
public void BreakerTripped(string breakerName)
{
var log = $"BreakerTripped - [Breaker={breakerName}]";
_diagnosticLog.Debug(log);
_breakerTrippedLog.Debug(log);
}
public void BulkheadGauge(string bulkheadName, string bulkheadType, int maxConcurrent, int countAvailable)
{
var gaugeLog = $"BulkheadGauge - [Bulkhead={bulkheadName}, BulkheadType={bulkheadType}, MaxConcurrent={maxConcurrent}, CountAvailable={countAvailable}]";
_diagnosticLog.Debug(gaugeLog);
_bulkheadGaugeLog.Debug(gaugeLog);
if (countAvailable == 0)
{
_concurrencyExceededLog.Debug(gaugeLog);
}
// Log the current rejections that occurred since the last gauge
if (_currentBulkheadsRejected.TryGetValue(bulkheadName, out int currentCount))
{
if (currentCount > 0)
{
_concurrencyExceededLog.Debug($"BulkheadRejections since last gauge - [Bulkhead={bulkheadName}, BulkheadType={bulkheadType}, MaxConcurrent={maxConcurrent}, CountAvailable={countAvailable}, Rejections={currentCount}]");
// Remove the rejections we've just logged from the current rejection count
_currentBulkheadsRejected.AddOrUpdate(bulkheadName, 0, (b, c) => c - currentCount);
}
}
}
public void CommandInvoked(string commandName, double invokeMillis, double executeMillis, string status, string failureAction)
{
_diagnosticLog.Debug($"CommandInvoked - [Command={commandName}, InvokeMs={invokeMillis}, ExecuteMs={executeMillis}, FailureAction={failureAction}]");
}
public void EnterBulkhead(string bulkheadName, string commandName)
{
_diagnosticLog.Debug($"EnterBulkhead - [Bulkhead={bulkheadName}, Command={commandName}]");
}
public void LeaveBulkhead(string bulkheadName, string commandName)
{
_diagnosticLog.Debug($"LeaveBulkhead - [Bulkhead={bulkheadName}, Command={commandName}]");
}
public void RejectedByBreaker(string breakerName, string commandName)
{
var log = $"RejectedByBreaker - [Breaker={breakerName}, Command={commandName}]";
_diagnosticLog.Debug(log);
_breakerTrippedLog.Debug(log);
}
public void RejectedByBulkhead(string bulkheadName, string commandName)
{
var log = $"RejectedByBulkhead - [Bulkhead={bulkheadName}, Command={commandName}]";
_diagnosticLog.Debug(log);
_concurrencyExceededLog.Debug(log);
_currentBulkheadsRejected.AddOrUpdate(bulkheadName, 1, (bh, current) => ++current);
}
}
}