Skip to content

Commit

Permalink
Rename Event -> Metric
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Jan 24, 2022
1 parent c67c1f0 commit a4991dc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions samples/Store/Integration/LogIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module EquinoxEsInterop =
[<NoEquality; NoComparison>]
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
Expand Down Expand Up @@ -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 ())
Expand Down
12 changes: 6 additions & 6 deletions src/Equinox.EventStore/EventStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ type Direction = Forward | Backward with

module Log =

/// <summary>Name of Property used for <c>Event</c> in <c>LogEvent</c>s.</summary>
/// <summary>Name of Property used for <c>Metric</c> in <c>LogEvent</c>s.</summary>
let [<Literal>] PropertyTag = "esEvt"

[<NoEquality; NoComparison>]
type Measurement = { stream : string; interval : StopwatchInterval; bytes : int; count : int }

[<NoEquality; NoComparison>]
type Event =
type Metric =
| WriteSuccess of Measurement
| WriteConflict of Measurement
| Slice of Direction * Measurement
Expand Down Expand Up @@ -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 })

Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/Equinox.SqlStreamStore/SqlStreamStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ type Direction = Forward | Backward with

module Log =

/// <summary>Name of Property used for <c>Event</c> in <c>LogEvent</c>s.</summary>
/// <summary>Name of Property used for <c>Metric</c> in <c>LogEvent</c>s.</summary>
let [<Literal>] PropertyTag = "esEvt"

[<NoEquality; NoComparison>]
type Measurement = { stream : string; interval : StopwatchInterval; bytes : int; count : int }
[<NoEquality; NoComparison>]
type Event =
type Metric =
| WriteSuccess of Measurement
| WriteConflict of Measurement
| Slice of Direction * Measurement
Expand All @@ -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> =
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/Equinox.EventStore.Integration/Infrastructure.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ module SerilogHelpers =
| _ -> None
[<RequireQualifiedAccess>]
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
| Log.Slice (Direction.Forward,_) -> EsAct.SliceForward
| 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 =
Expand Down

0 comments on commit a4991dc

Please sign in to comment.