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 eaae087 commit be4c159
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 @@ -12,6 +12,7 @@ The `Unreleased` section name is replaced by the expected version of next releas
### Changed

- Remove explicit `net461` handling; minimum target now `netstandard 2.1` / `net5.0` [#310](https://github.com/jet/equinox/pull/310)
- `EventStore/SqlStreamStore`: rename `Equinox.XXXStore.Log.Event` -> `Metric` to match `CosmosStore` [#311](https://github.com/jet/equinox/pull/311)

### 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 @@ -12,14 +12,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 @@ -48,7 +48,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 @@ -81,9 +81,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 @@ -230,7 +230,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 @@ -18,13 +18,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 @@ -46,7 +46,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 @@ -76,9 +76,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 @@ -215,7 +215,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 be4c159

Please sign in to comment.