-
Notifications
You must be signed in to change notification settings - Fork 70
feat(MessageDb): Replace logging with complete OT metrics #407
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
base: master
Are you sure you want to change the base?
Changes from all commits
9c25a2e
2ab60d3
b8b13c3
e2ad297
7077315
cccf0c8
d59ec1b
3043ae8
28e2653
cf26166
e982ed4
9c9563b
95ac427
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,22 @@ | |
|
|
||
| open System | ||
|
|
||
| open Domain | ||
| open FsCheck.FSharp | ||
| open FSharp.UMX | ||
|
|
||
| module ArbMap = | ||
| let defaultGen<'t> = ArbMap.defaults |> ArbMap.generate<'t> | ||
|
|
||
| type FsCheckGenerators = | ||
| static member SkuId = ArbMap.defaultGen |> Gen.map SkuId |> Arb.fromGen | ||
| static member ContactPreferencesId = | ||
| ArbMap.defaultGen<Guid> | ||
| |> Gen.map (fun x -> sprintf "%[email protected]" (x.ToString("N"))) | ||
| |> Gen.map ContactPreferences.ClientId | ||
| |> Arb.fromGen | ||
| static member RequestId = ArbMap.defaultGen<Guid> |> Gen.map (fun x -> RequestId.parse %x) |> Arb.fromGen | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this line move to L10 and put a copy before L11 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You want two spaces between the Arb an FsCheckGenerators module? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, a blank after the |
||
| type AutoDataAttribute() = | ||
| inherit FsCheck.Xunit.PropertyAttribute(Arbitrary = [|typeof<FsCheckGenerators>|], MaxTest = 1, QuietOnSuccess = true) | ||
|
|
||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,19 +34,22 @@ type private CacheEntry<'state>(initialToken: StreamToken, initialState: 'state, | |
| /// Coordinates having a max of one in-flight request across all staleness-tolerant loads at all times | ||
| // Follows high level flow of AsyncCacheCell.Await - read the comments there, and the AsyncCacheCell tests first! | ||
| member x.ReadThrough(maxAge: TimeSpan, isStale, load: Func<_, _>) = task { | ||
| let act = System.Diagnostics.Activity.Current | ||
| let setCacheHit hit = if act <> null then act.SetTag(Tags.cache_hit, hit) |> ignore | ||
| let cacheEntryValidityCheckTimestamp = System.Diagnostics.Stopwatch.GetTimestamp() | ||
| let isWithinMaxAge cachedValueTimestamp = Stopwatch.TicksToSeconds(cacheEntryValidityCheckTimestamp - cachedValueTimestamp) <= maxAge.TotalSeconds | ||
| let age timestamp = Stopwatch.TicksToSeconds(cacheEntryValidityCheckTimestamp - timestamp) | ||
| if act <> null then act.SetTag(Tags.cache_age, 1000. * age verifiedTimestamp) |> ignore | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't really matter but arguably this should be inside fetchStateConsistently |
||
| let isWithinMaxAge cachedValueTimestamp = age cachedValueTimestamp <= maxAge.TotalSeconds | ||
| let fetchStateConsistently () = struct (cell, tryGet (), isWithinMaxAge verifiedTimestamp) | ||
| match lock x fetchStateConsistently with | ||
| | _, ValueSome cachedValue, true -> | ||
| return cachedValue | ||
| | _, ValueSome cachedValue, true -> setCacheHit true; return cachedValue | ||
| | ourInitialCellState, maybeBaseState, _ -> // If it's not good enough for us, trigger a request (though someone may have beaten us to that) | ||
|
|
||
| setCacheHit false | ||
| // Inspect/await any concurrent attempt to see if it is sufficient for our needs | ||
| match! ourInitialCellState.TryAwaitValid() with | ||
| | ValueSome (fetchCommencedTimestamp, res) when isWithinMaxAge fetchCommencedTimestamp -> return res | ||
| | _ -> | ||
|
|
||
| // .. it wasn't; join the race to dispatch a request (others following us will share our fate via the TryAwaitValid) | ||
| let newInstance = AsyncLazy(fun () -> load.Invoke maybeBaseState) | ||
| let _ = Interlocked.CompareExchange(&cell, newInstance, ourInitialCellState) | ||
|
|
@@ -81,13 +84,12 @@ type Cache private (inner: System.Runtime.Caching.MemoryCache) = | |
| // if there's a non-zero maxAge, concurrent read attempts share the roundtrip (and its fate, if it throws) | ||
| member internal _.Load(key, maxAge, isStale, policy, loadOrReload, ct) = task { | ||
| let loadOrReload maybeBaseState = task { | ||
| let act = System.Diagnostics.Activity.Current | ||
| if act <> null then act.AddCacheHit(ValueOption.isSome maybeBaseState) |> ignore | ||
| let ts = System.Diagnostics.Stopwatch.GetTimestamp() | ||
| let! res = loadOrReload ct maybeBaseState | ||
| return struct (ts, res) } | ||
| if maxAge = TimeSpan.Zero then // Boring algorithm that has each caller independently load/reload the data and then cache it | ||
| let maybeBaseState = tryLoad key | ||
| let act = System.Diagnostics.Activity.Current in act.SetTag(Tags.cache_hit, ValueOption.isSome maybeBaseState) |> ignore | ||
| let! timestamp, res = loadOrReload maybeBaseState | ||
| addOrMergeCacheEntry isStale key policy timestamp res | ||
| return res | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.