@@ -36,7 +36,9 @@ type Governor(log: Serilog.ILogger, buildFailurePolicy: unit -> Polly.PolicyBuil
36
36
// In the general case, it's always possible to write an async expression that honors cancellation
37
37
// If anyone tries to insist on using Pessimistic mode, this should instead by accomplished by explicitly having
38
38
// the inner computation cut the orphan work adrift in the place where the code requires such questionable semantics
39
- | Some cutoff when not cutoff.dryRun -> Some <| Policy.TimeoutAsync( cutoff.timeout)
39
+ | Some cutoff when not cutoff.dryRun ->
40
+ log.Debug( " Establishing TimeoutAsync for {service:l}-{call:l}: {timeout}" , serviceName, callName, cutoff.timeout)
41
+ Some <| Policy.TimeoutAsync( cutoff.timeout)
40
42
| _ -> None
41
43
let logQueuing () = log |> Events.Log.queuing ( serviceName, callName)
42
44
let logDeferral interval concurrencyLimit = log |> Events.Log.deferral ( serviceName, callName, policyName) interval concurrencyLimit
@@ -49,6 +51,7 @@ type Governor(log: Serilog.ILogger, buildFailurePolicy: unit -> Polly.PolicyBuil
49
51
| Some limit ->
50
52
let logRejection ( _ : Context ) : Task = logShedding { dop = limit.dop; queue = limit.queue } ; Task.CompletedTask
51
53
let effectiveLimit = if limit.dryRun then Int32.MaxValue else limit.dop // https://github.com/App-vNext/Polly/issues/496#issuecomment-420183946
54
+ log.Debug( " Establishing BulkheadAsync for {service:l}-{call:l} {effectiveLimit}+{queue}" , serviceName, callName, effectiveLimit, limit.queue)
52
55
Some <| Policy.BulkheadAsync( maxParallelization = effectiveLimit, maxQueuingActions = limit.queue, onBulkheadRejectedAsync = logRejection)
53
56
let logBreaking ( exn : exn ) ( timespan : TimeSpan ) =
54
57
match config with
@@ -71,6 +74,7 @@ type Governor(log: Serilog.ILogger, buildFailurePolicy: unit -> Polly.PolicyBuil
71
74
| None ->
72
75
None
73
76
| Some bc ->
77
+ log.Debug( " Establishing AdvancedCircuitBreakerAsync for {service:l}-{call:l}" , serviceName, callName)
74
78
buildFailurePolicy()
75
79
.AdvancedCircuitBreakerAsync(
76
80
failureThreshold = bc.errorRateThreshold,
@@ -121,7 +125,9 @@ type Governor(log: Serilog.ILogger, buildFailurePolicy: unit -> Polly.PolicyBuil
121
125
/// Execute and/or log failures regarding invocation of a function with the relevant policy applied
122
126
member __.Execute ( inner : Async < 'a >) : Async < 'a > =
123
127
match asyncPolicy with
124
- | None -> inner
128
+ | None ->
129
+ log.Debug( " Policy Execute Raw {service:l}-{call:l}" , serviceName, callName)
130
+ inner
125
131
| Some polly -> async {
126
132
let mutable wasFull = false
127
133
// NB This logging is on a best-effort basis - obviously the guard here has an implied race condition
@@ -161,6 +167,7 @@ type Governor(log: Serilog.ILogger, buildFailurePolicy: unit -> Polly.PolicyBuil
161
167
Async.StartAsTask( inner, cancellationToken= pollyCt)
162
168
let execute = async {
163
169
let! ct = Async.CancellationToken // Grab async cancellation token of this `Execute` call, so cancellation gets propagated into the Polly [wrap]
170
+ log.Debug( " Policy Execute Inner {service:l}-{call:l}" , serviceName, callName)
164
171
try return ! polly.ExecuteAsync( startInnerTask, ct) |> Async.AwaitTaskCorrect
165
172
// TODO find/add a cleaner way to use the Polly API to log when the event fires due to the the circuit being Isolated/Broken
166
173
with LogWhenRejectedFilter jitProcessingInterval -> return ! invalidOp " not possible; Filter always returns None" }
@@ -172,9 +179,11 @@ type Governor(log: Serilog.ILogger, buildFailurePolicy: unit -> Polly.PolicyBuil
172
179
finally
173
180
if not jitProcessingInterval.IsValueCreated then
174
181
let processingInterval = jitProcessingInterval.Force()
175
- match sla, processingInterval.Elapsed with
176
- | _, elapsed when elapsed > timeout && dryRun -> logTimeout config processingInterval
177
- | Some sla, elapsed when elapsed > sla -> logBreach sla processingInterval
182
+ let elapsed = processingInterval.Elapsed
183
+ log.Debug( " Policy Executed in {elapsedMs} {service:l}-{call:l}" , elapsed.TotalMilliseconds, serviceName, callName)
184
+ match sla with
185
+ | _ when elapsed > timeout && dryRun -> logTimeout config processingInterval
186
+ | Some sla when elapsed > sla -> logBreach sla processingInterval
178
187
| _ -> () }
179
188
180
189
/// Diagnostic state
0 commit comments