From 4253d3dfc1c0786a85c17231b6aed83286e430a6 Mon Sep 17 00:00:00 2001 From: Diego Diverio Date: Mon, 13 Feb 2023 11:37:15 +0100 Subject: [PATCH] Enable log toggling for Sync operations. --- server/src/Config.hs | 4 ++++ server/src/Core.hs | 1 + server/src/Persistence.hs | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/Config.hs b/server/src/Config.hs index 4b79194..4b340b3 100644 --- a/server/src/Config.hs +++ b/server/src/Config.hs @@ -43,6 +43,8 @@ data Config = Config -- Just indicates that a key is given. , configSentryDSN :: Maybe String , configStorageBackend :: StorageBackend + -- | Enable logging of Sync duration + , configSyncLogging :: Bool } data MetricsConfig = MetricsConfig @@ -101,6 +103,8 @@ configParser environment = Config environ "SENTRY_DSN" <> help "Sentry DSN used for Sentry logging, defaults to the value of the SENTRY_DSN environment variable if present. If no secret is passed, Sentry logging will be disabled.")) <*> storageBackend + <*> switch (long "sync-log" <> + help "Enable logging the duration of Sync operations.") where environ var = foldMap value (lookup var environment) diff --git a/server/src/Core.hs b/server/src/Core.hs index 6d409aa..678a404 100644 --- a/server/src/Core.hs +++ b/server/src/Core.hs @@ -94,6 +94,7 @@ newCore config logger metrics = do , pcJournalFile = journalFile , pcLogger = logger , pcMetrics = metrics + , pcLogSync = configSyncLogging config } for eitherValue $ \value -> do -- create synchronization channels diff --git a/server/src/Persistence.hs b/server/src/Persistence.hs index e3f4885..d0febfd 100644 --- a/server/src/Persistence.hs +++ b/server/src/Persistence.hs @@ -56,6 +56,7 @@ data PersistenceConfig = PersistenceConfig , pcJournalFile :: Maybe FilePath , pcLogger :: Logger , pcMetrics :: Maybe Metrics.IcepeakMetrics + , pcLogSync :: Bool } -- | Get the actual value @@ -161,7 +162,9 @@ syncToBackend File pv = do syncFile pv end <- Clock.getTime Clock.Monotonic let time = Clock.toNanoSecs (Clock.diffTimeSpec end start) `div` 1000000 - logMessage pv $ Text.concat ["It took ", Text.pack $ show time, " ms to synchronize Icepeak on disk."] + if pcLogSync $ pvConfig pv then + logMessage pv $ Text.concat ["It took ", Text.pack $ show time, " ms to synchronize Icepeak on disk."] + else return () syncToBackend Sqlite pv = syncSqliteFile pv -- * SQLite loading and syncing