Skip to content

Commit

Permalink
Merge pull request #93 from channable/dd/sync-log-config
Browse files Browse the repository at this point in the history
Enable log toggling for Sync operations.
  • Loading branch information
diegodiv authored Feb 13, 2023
2 parents 16aebfc + 4253d3d commit 8585d0e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions server/src/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions server/src/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion server/src/Persistence.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ data PersistenceConfig = PersistenceConfig
, pcJournalFile :: Maybe FilePath
, pcLogger :: Logger
, pcMetrics :: Maybe Metrics.IcepeakMetrics
, pcLogSync :: Bool
}

-- | Get the actual value
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8585d0e

Please sign in to comment.