From a4991dc7afb47aaca3748b4cdacdec0f7b6f5184 Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Mon, 24 Jan 2022 20:15:20 +0000 Subject: [PATCH] Rename Event -> Metric --- CHANGELOG.md | 1 + samples/Store/Integration/LogIntegration.fs | 4 ++-- src/Equinox.EventStore/EventStore.fs | 12 ++++++------ src/Equinox.SqlStreamStore/SqlStreamStore.fs | 12 ++++++------ .../Equinox.EventStore.Integration/Infrastructure.fs | 6 +++--- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 375f04c0c..8833da80c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The `Unreleased` section name is replaced by the expected version of next releas - `CosmosStore`: Only log `bytes` when log level is `Debug` [#305](https://github.com/jet/equinox/pull/305) - `Equinox`: Merge `XXXStoreCategory.Resolve(sn, ?ResolveOption)` and `XXXStoreCategory.FromMemento` as option `LoadOption` parameter on all `Transact` and `Query` methods [#308](https://github.com/jet/equinox/pull/308) - `Equinox`: rename `Decider.TransactAsync` to `Transact` [#308](https://github.com/jet/equinox/pull/308) +- `EventStore/SqlStreamStore`: rename `Equinox.XXXStore.Log.Event` -> `Metric` to match `CosmosStore` [#308](https://github.com/jet/equinox/pull/308) ### Removed ### Fixed diff --git a/samples/Store/Integration/LogIntegration.fs b/samples/Store/Integration/LogIntegration.fs index c8ffd4846..0d49ba769 100644 --- a/samples/Store/Integration/LogIntegration.fs +++ b/samples/Store/Integration/LogIntegration.fs @@ -13,7 +13,7 @@ module EquinoxEsInterop = [] type FlatMetric = { action: string; stream : string; interval: StopwatchInterval; bytes: int; count: int; batches: int option } with override __.ToString() = sprintf "%s-Stream=%s %s-Elapsed=%O" __.action __.stream __.action __.interval.Elapsed - let flatten (evt : Log.Event) : FlatMetric = + let flatten (evt : Log.Metric) : FlatMetric = let action, metric, batches = match evt with | Log.WriteSuccess m -> "AppendToStreamAsync", m, None @@ -66,7 +66,7 @@ type SerilogMetricsExtractor(emit : string -> unit) = let (|EsMetric|CosmosMetric|GenericMessage|) (logEvent : Serilog.Events.LogEvent) = logEvent.Properties |> Seq.tryPick (function - | KeyValue (k, SerilogScalar (:? Equinox.EventStore.Log.Event as m)) -> Some <| Choice1Of3 (k,m) + | KeyValue (k, SerilogScalar (:? Equinox.EventStore.Log.Metric as m)) -> Some <| Choice1Of3 (k,m) | KeyValue (k, SerilogScalar (:? Equinox.CosmosStore.Core.Log.Metric as m)) -> Some <| Choice2Of3 (k,m) | _ -> None) |> Option.defaultValue (Choice3Of3 ()) diff --git a/src/Equinox.EventStore/EventStore.fs b/src/Equinox.EventStore/EventStore.fs index e21663d45..9b07611a4 100755 --- a/src/Equinox.EventStore/EventStore.fs +++ b/src/Equinox.EventStore/EventStore.fs @@ -11,14 +11,14 @@ type Direction = Forward | Backward with module Log = - /// Name of Property used for Event in LogEvents. + /// Name of Property used for Metric in LogEvents. let [] PropertyTag = "esEvt" [] type Measurement = { stream : string; interval : StopwatchInterval; bytes : int; count : int } [] - type Event = + type Metric = | WriteSuccess of Measurement | WriteConflict of Measurement | Slice of Direction * Measurement @@ -47,7 +47,7 @@ module Log = /// Attach a property to the log context to hold the metrics // Sidestep Log.ForContext converting to a string; see https://github.com/serilog/serilog/issues/1124 - let event (value : Event) (log : ILogger) = + let event (value : Metric) (log : ILogger) = let enrich (e : LogEvent) = e.AddPropertyIfAbsent(LogEventProperty(PropertyTag, ScalarValue(value))) log.ForContext({ new Serilog.Core.ILogEventEnricher with member _.Enrich(evt, _) = enrich evt }) @@ -80,9 +80,9 @@ module Log = | :? ScalarValue as x -> Some x.Value | _ -> None - let (|EsMetric|_|) (logEvent : LogEvent) : Event option = + let (|EsMetric|_|) (logEvent : LogEvent) : Metric option = match logEvent.Properties.TryGetValue(PropertyTag) with - | true, SerilogScalar (:? Event as e) -> Some e + | true, SerilogScalar (:? Metric as e) -> Some e | _ -> None type Counter = @@ -229,7 +229,7 @@ module private Read = let reqMetric : Log.Measurement = { stream = streamName; interval = t; bytes = bytes; count = count} let batches = (events.Length - 1) / batchSize + 1 let action = match direction with Direction.Forward -> "LoadF" | Direction.Backward -> "LoadB" - let evt = Log.Event.Batch (direction, batches, reqMetric) + let evt = Log.Metric.Batch (direction, batches, reqMetric) (log |> Log.prop "bytes" bytes |> Log.event evt).Information( "Ges{action:l} stream={stream} count={count}/{batches} version={version}", action, streamName, count, batches, version) diff --git a/src/Equinox.SqlStreamStore/SqlStreamStore.fs b/src/Equinox.SqlStreamStore/SqlStreamStore.fs index 9414b9979..f550d7146 100644 --- a/src/Equinox.SqlStreamStore/SqlStreamStore.fs +++ b/src/Equinox.SqlStreamStore/SqlStreamStore.fs @@ -17,13 +17,13 @@ type Direction = Forward | Backward with module Log = - /// Name of Property used for Event in LogEvents. + /// Name of Property used for Metric in LogEvents. let [] PropertyTag = "esEvt" [] type Measurement = { stream : string; interval : StopwatchInterval; bytes : int; count : int } [] - type Event = + type Metric = | WriteSuccess of Measurement | WriteConflict of Measurement | Slice of Direction * Measurement @@ -45,7 +45,7 @@ module Log = open Serilog.Events /// Attach a property to the log context to hold the metrics // Sidestep Log.ForContext converting to a string; see https://github.com/serilog/serilog/issues/1124 - let event (value : Event) (log : ILogger) = + let event (value : Metric) (log : ILogger) = let enrich (e : LogEvent) = e.AddPropertyIfAbsent(LogEventProperty(PropertyTag, ScalarValue(value))) log.ForContext({ new Serilog.Core.ILogEventEnricher with member _.Enrich(evt, _) = enrich evt }) let withLoggedRetries<'t> retryPolicy (contextLabel : string) (f : ILogger -> Async<'t>) log : Async<'t> = @@ -75,9 +75,9 @@ module Log = let (|SerilogScalar|_|) : LogEventPropertyValue -> obj option = function | :? ScalarValue as x -> Some x.Value | _ -> None - let (|EsMetric|_|) (logEvent : LogEvent) : Event option = + let (|EsMetric|_|) (logEvent : LogEvent) : Metric option = match logEvent.Properties.TryGetValue(PropertyTag) with - | true, SerilogScalar (:? Event as e) -> Some e + | true, SerilogScalar (:? Metric as e) -> Some e | _ -> None type Counter = { mutable count : int64; mutable ms : int64 } @@ -214,7 +214,7 @@ module private Read = let reqMetric : Log.Measurement = { stream = streamName; interval = t; bytes = bytes; count = count} let batches = (events.Length - 1)/batchSize + 1 let action = match direction with Direction.Forward -> "LoadF" | Direction.Backward -> "LoadB" - let evt = Log.Event.Batch (direction, batches, reqMetric) + let evt = Log.Metric.Batch (direction, batches, reqMetric) (log |> Log.prop "bytes" bytes |> Log.event evt).Information( "SqlEs{action:l} stream={stream} count={count}/{batches} version={version}", action, streamName, count, batches, version) diff --git a/tests/Equinox.EventStore.Integration/Infrastructure.fs b/tests/Equinox.EventStore.Integration/Infrastructure.fs index 08e01fca2..eac361c7d 100644 --- a/tests/Equinox.EventStore.Integration/Infrastructure.fs +++ b/tests/Equinox.EventStore.Integration/Infrastructure.fs @@ -56,7 +56,7 @@ module SerilogHelpers = | _ -> None [] type EsAct = Append | AppendConflict | SliceForward | SliceBackward | BatchForward | BatchBackward - let (|EsAction|) (evt : Log.Event) = + let (|EsAction|) (evt : Log.Metric) = match evt with | Log.WriteSuccess _ -> EsAct.Append | Log.WriteConflict _ -> EsAct.AppendConflict @@ -64,9 +64,9 @@ module SerilogHelpers = | Log.Slice (Direction.Backward,_) -> EsAct.SliceBackward | Log.Batch (Direction.Forward,_,_) -> EsAct.BatchForward | Log.Batch (Direction.Backward,_,_) -> EsAct.BatchBackward - let (|EsEvent|_|) (logEvent : LogEvent) : Log.Event option = + let (|EsEvent|_|) (logEvent : LogEvent) : Log.Metric option = logEvent.Properties.Values |> Seq.tryPick (function - | SerilogScalar (:? Log.Event as e) -> Some e + | SerilogScalar (:? Log.Metric as e) -> Some e | _ -> None) let (|HasProp|_|) (name : string) (e : LogEvent) : LogEventPropertyValue option =