From c5e890ccaeffb92769414b75105b3761865c1f39 Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Wed, 13 Sep 2023 11:04:42 +0100 Subject: [PATCH] Use CreateDynamoStoreClient --- .../Function.fs | 24 +++++++++---------- tools/Propulsion.Tool/Args.fs | 3 +-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Propulsion.DynamoStore.Indexer/Function.fs b/src/Propulsion.DynamoStore.Indexer/Function.fs index 94f54cfd..c9c22dcf 100644 --- a/src/Propulsion.DynamoStore.Indexer/Function.fs +++ b/src/Propulsion.DynamoStore.Indexer/Function.fs @@ -11,7 +11,7 @@ open Serilog type Configuration(?tryGet) = let envVarTryGet = System.Environment.GetEnvironmentVariable >> Option.ofObj let tryGet = defaultArg tryGet envVarTryGet - let get key = match tryGet key with Some value -> value | None -> failwithf "Missing Argument/Environment Variable %s" key + let get key = match tryGet key with Some value -> value | None -> failwith $"Missing Argument/Environment Variable %s{key}" member _.DynamoRegion = tryGet Propulsion.DynamoStore.Lambda.Args.Dynamo.REGION member _.DynamoServiceUrl = get Propulsion.DynamoStore.Lambda.Args.Dynamo.SERVICE_URL @@ -20,18 +20,17 @@ type Configuration(?tryGet) = member _.DynamoIndexTable = get Propulsion.DynamoStore.Lambda.Args.Dynamo.INDEX_TABLE member _.OnlyWarnGap = tryGet Propulsion.DynamoStore.Lambda.Args.Dynamo.ONLY_WARN_GAP |> Option.map bool.Parse -type Store(connector: DynamoStoreConnector, table, dynamoItemSizeCutoffBytes) = - let queryMaxItems = 100 +type Connector(client: DynamoStoreClient, table) = - let storeClient = connector.CreateDynamoDbClient() |> DynamoStoreClient - member val Context = DynamoStoreContext(storeClient, table, maxBytes = dynamoItemSizeCutoffBytes, queryMaxItems = queryMaxItems) + member _.CreateContext(dynamoItemSizeCutoffBytes, ?queryMaxItems) = + DynamoStoreContext(client, table, maxBytes = dynamoItemSizeCutoffBytes, queryMaxItems = defaultArg queryMaxItems 100) - new(c: Configuration, requestTimeout, retries, dynamoItemSizeCutoffBytes) = - let conn = + new(c: Configuration, requestTimeout, retries) = + let connector = match c.DynamoRegion with | Some r -> DynamoStoreConnector(r, requestTimeout, retries) | None -> DynamoStoreConnector(c.DynamoServiceUrl, c.DynamoAccessKey, c.DynamoSecretKey, requestTimeout, retries) - Store(conn, c.DynamoIndexTable, dynamoItemSizeCutoffBytes) + Connector(connector.CreateDynamoStoreClient(), c.DynamoIndexTable) type Function() = @@ -39,16 +38,17 @@ type Function() = // Smaller will trigger more items and reduce read costs for Sources reading fro the tail let itemCutoffKiB = 48 let config = Configuration() - let store = Store(config, requestTimeout = System.TimeSpan.FromSeconds 120., retries = 10, dynamoItemSizeCutoffBytes = itemCutoffKiB * 1024) + let connector = Connector(config, requestTimeout = System.TimeSpan.FromSeconds 120., retries = 10) // TOCONSIDER surface metrics from write activities to prometheus by wiring up Metrics Sink (for now we log them instead) - let removeMetrics (e : Serilog.Events.LogEvent) = e.RemovePropertyIfPresent(Equinox.DynamoStore.Core.Log.PropertyTag) + let removeMetrics (e: Serilog.Events.LogEvent) = e.RemovePropertyIfPresent(Equinox.DynamoStore.Core.Log.PropertyTag) let template = "{Level:u1} {Message} {Properties}{NewLine}{Exception}" let log = LoggerConfiguration() .Enrich.With({ new Serilog.Core.ILogEventEnricher with member _.Enrich(evt, _) = removeMetrics evt }) .WriteTo.Console(outputTemplate = template) .CreateLogger() - let ingester = DynamoStoreIngester(log, store.Context, ?onlyWarnOnGap = config.OnlyWarnGap) + let context = connector.CreateContext(dynamoItemSizeCutoffBytes = itemCutoffKiB * 1024) + let ingester = DynamoStoreIngester(log, context, ?onlyWarnOnGap = config.OnlyWarnGap) - member _.Handle(dynamoEvent : DynamoDBEvent, _context : ILambdaContext) : System.Threading.Tasks.Task = + member _.Handle(dynamoEvent: DynamoDBEvent, _context: ILambdaContext): System.Threading.Tasks.Task = Handler.handle log ingester.Service dynamoEvent diff --git a/tools/Propulsion.Tool/Args.fs b/tools/Propulsion.Tool/Args.fs index d542feb6..9c10df8c 100644 --- a/tools/Propulsion.Tool/Args.fs +++ b/tools/Propulsion.Tool/Args.fs @@ -118,8 +118,7 @@ module Dynamo = x.Endpoint, (let t = x.Timeout in t.TotalSeconds), x.Retries) member x.CreateStoreClient() = x.LogConfiguration() - x.CreateDynamoDbClient() - |> Equinox.DynamoStore.DynamoStoreClient + x.CreateDynamoStoreClient() type Equinox.DynamoStore.DynamoStoreClient with