Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit d598003

Browse files
authored
Merge pull request #2055 from input-output-hk/gromak/csl1822-refine-logging
[CSL-1822] Refine logging
2 parents f3950c5 + 627a2de commit d598003

File tree

26 files changed

+207
-180
lines changed

26 files changed

+207
-180
lines changed

Diff for: auxx/Main.hs

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Formatting (sformat, shown, (%))
1111
import Mockable (Production, currentTime, runProduction)
1212
import qualified Network.Transport.TCP as TCP (TCPAddr (..))
1313
import qualified System.IO.Temp as Temp
14-
import System.Wlog (logInfo)
14+
import System.Wlog (LoggerName, logInfo)
1515

1616
import qualified Pos.Client.CLI as CLI
1717
import Pos.Communication (OutSpecs, WorkerSpec)
@@ -31,7 +31,10 @@ import Pos.WorkMode (EmptyMempoolExt, RealMode)
3131
import AuxxOptions (AuxxAction (..), AuxxOptions (..), AuxxStartMode (..), getAuxxOptions)
3232
import Mode (AuxxContext (..), AuxxMode, CmdCtx (..), realModeToAuxx)
3333
import Plugin (auxxPlugin, rawExec)
34-
import Repl (WithCommandAction(..), withAuxxRepl)
34+
import Repl (WithCommandAction (..), withAuxxRepl)
35+
36+
loggerName :: LoggerName
37+
loggerName = "auxx"
3538

3639
-- 'NodeParams' obtained using 'CLI.getNodeParams' are not perfect for
3740
-- Auxx, so we need to adapt them slightly.
@@ -88,7 +91,7 @@ action opts@AuxxOptions {..} command = do
8891
$ withConfigurations conf configToDict
8992
mode <$ case mode of
9093
Nothing -> printAction "Mode: light"
91-
_ -> printAction "Mode: with-config"
94+
_ -> printAction "Mode: with-config"
9295
Light -> return Nothing
9396
_ -> withConfigurations conf configToDict
9497

@@ -99,7 +102,7 @@ action opts@AuxxOptions {..} command = do
99102
t <- currentTime
100103
logInfo $ sformat ("Current time is "%shown) (Timestamp t)
101104
(nodeParams, tempDbUsed) <-
102-
correctNodeParams opts =<< CLI.getNodeParams cArgs nArgs
105+
correctNodeParams opts =<< CLI.getNodeParams loggerName cArgs nArgs
103106
let
104107
toRealMode :: AuxxMode a -> RealMode EmptyMempoolExt a
105108
toRealMode auxxAction = do
@@ -136,7 +139,7 @@ main = withCompileInfo $(retrieveCompileTimeInfo) $ do
136139
\lp -> lp { lpConsoleLog = Just False }
137140
| otherwise = identity
138141
loggingParams = disableConsoleLog $
139-
CLI.loggingParams "auxx" (aoCommonNodeArgs opts)
142+
CLI.loggingParams loggerName (aoCommonNodeArgs opts)
140143
loggerBracket loggingParams $ do
141144
let runAction a = runProduction $ action opts a
142145
case aoAction opts of

Diff for: block/src/Pos/Block/Network/Announce.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ announceBlock
4343
:: BlockWorkMode ctx m
4444
=> EnqueueMsg m -> MainBlockHeader -> m (Map NodeId (m ()))
4545
announceBlock enqueue header = do
46-
logDebug $ sformat ("Announcing header to others:\n"%build) header
46+
logDebug $ sformat ("Announcing header to others: "%shortHashF)
47+
(headerHash header)
4748
enqueue (MsgAnnounceBlockHeader OriginSender) (\addr _ -> announceBlockDo addr)
4849
where
4950
announceBlockDo

Diff for: block/src/Pos/Block/Network/Logic.hs

+7-6
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,8 @@ handleUnsolicitedHeader
184184
-> m ()
185185
handleUnsolicitedHeader header nodeId = do
186186
logDebug $ sformat
187-
("handleUnsolicitedHeader: single header "%shortHashF%
188-
" was propagated, processing")
189-
hHash
187+
("handleUnsolicitedHeader: single header was propagated, processing:\n"
188+
%build) header
190189
classificationRes <- classifyNewHeader header
191190
-- TODO: should we set 'To' hash to hash of header or leave it unlimited?
192191
case classificationRes of
@@ -399,7 +398,8 @@ addHeaderToBlockRequestQueue
399398
-> Bool -- ^ Was classified as chain continuation
400399
-> m ()
401400
addHeaderToBlockRequestQueue nodeId header continues = do
402-
logDebug $ sformat ("addToBlockRequestQueue, : "%build) header
401+
let hHash = headerHash header
402+
logDebug $ sformat ("addToBlockRequestQueue, : "%shortHashF) hHash
403403
queue <- view (lensOf @BlockRetrievalQueueTag)
404404
lastKnownH <- view (lensOf @LastKnownHeaderTag)
405405
added <- atomically $ do
@@ -409,7 +409,7 @@ addHeaderToBlockRequestQueue nodeId header continues = do
409409
if added
410410
then logDebug $ sformat ("Added headers to block request queue: nodeId="%build%
411411
", header="%build)
412-
nodeId (headerHash header)
412+
nodeId hHash
413413
else logWarning $ sformat ("Failed to add headers from "%build%
414414
" to block retrieval queue: queue is full")
415415
nodeId
@@ -581,7 +581,8 @@ relayBlock enqueue (Right mainBlk) = do
581581
recoveryInProgress >>= \case
582582
True -> logDebug "Not relaying block in recovery mode"
583583
False -> do
584-
logDebug $ sformat ("Calling announceBlock for "%build%".") (mainBlk ^. gbHeader)
584+
logDebug $ sformat ("Calling announceBlock for "%shortHashF%".")
585+
(mainBlk ^. gbHeader . headerHashG)
585586
void $ announceBlock enqueue $ mainBlk ^. gbHeader
586587

587588
----------------------------------------------------------------------------

Diff for: block/src/Pos/Block/Network/Retrieval.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ retrievalWorkerImpl keepAliveTimer SendActions {..} =
126126

127127
-- When we have continuation, we just try to get and apply it.
128128
handleContinues nodeId header = do
129-
logDebug $ "handleContinues: " <> pretty header
129+
let hHash = headerHash header
130+
logDebug $ "handleContinues: " <> pretty hHash
130131
classifyNewHeader header >>= \case
131132
CHContinues ->
132-
void $ getProcessBlocks enqueueMsg nodeId header (headerHash header)
133+
void $ getProcessBlocks enqueueMsg nodeId header hHash
133134
res -> logDebug $
134135
"processContHeader: expected header to " <>
135136
"be continuation, but it's " <> show res
@@ -138,7 +139,7 @@ retrievalWorkerImpl keepAliveTimer SendActions {..} =
138139
-- really recovery mode (server side should send us headers as a
139140
-- proof) and then enter recovery mode.
140141
handleAlternative nodeId header = do
141-
logDebug $ "handleAlternative: " <> pretty header
142+
logDebug $ "handleAlternative: " <> pretty (headerHash header)
142143
classifyNewHeader header >>= \case
143144
CHInvalid _ ->
144145
logError "handleAlternative: invalid header got into retrievalWorker queue"

Diff for: block/src/Pos/Block/Worker.hs

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import qualified Data.List.NonEmpty as NE
1414
import Data.Time.Units (Microsecond)
1515
import Formatting (Format, bprint, build, fixed, int, now, sformat, shown, (%))
1616
import Mockable (delay, fork)
17-
import Serokell.Util (listJson, pairF, sec)
17+
import Serokell.Util (enumerate, listJson, pairF, sec)
1818
import qualified System.Metrics.Label as Label
1919
import System.Wlog (logDebug, logInfo, logWarning)
2020

@@ -71,18 +71,20 @@ blkWorkers
7171
=> Timer -> ([WorkerSpec m], OutSpecs)
7272
blkWorkers keepAliveTimer =
7373
merge $ [ blkCreatorWorker
74-
, blkMetricCheckerWorker
74+
, informerWorker
7575
, retrievalWorker keepAliveTimer
7676
, recoveryTriggerWorker
7777
]
7878
where
7979
merge = mconcatPair . map (first pure)
8080

81-
blkMetricCheckerWorker :: BlockWorkMode ctx m => (WorkerSpec m, OutSpecs)
82-
blkMetricCheckerWorker =
81+
informerWorker :: BlockWorkMode ctx m => (WorkerSpec m, OutSpecs)
82+
informerWorker =
8383
onNewSlotWorker True announceBlockOuts $ \slotId _ ->
84-
recoveryCommGuard "onNewSlot worker, blkMetricCheckerWorker" $
85-
metricWorker slotId
84+
recoveryCommGuard "onNewSlot worker, informerWorker" $ do
85+
tipHeader <- DB.getTipHeader
86+
logDebug $ sformat ("Our tip header: "%build) tipHeader
87+
metricWorker slotId
8688

8789
----------------------------------------------------------------------------
8890
-- Block creation worker
@@ -139,11 +141,9 @@ blockCreator (slotId@SlotId {..}) sendActions = do
139141
-- of them.
140142
dropAround :: Int -> Int -> [a] -> [a]
141143
dropAround p s = take (2*s + 1) . drop (max 0 (p - s))
142-
strLeaders = map (bprint pairF) (zip [0 :: Int ..] $ toList leaders)
143-
if siSlot == minBound
144-
then logInfo $ sformat ("Full slot leaders: "%listJson) strLeaders
145-
else logDebug $ sformat ("Trimmed leaders: "%listJson) $
146-
dropAround (fromIntegral $ fromEnum $ siSlot) 10 strLeaders
144+
strLeaders = map (bprint pairF) (enumerate @Int (toList leaders))
145+
logDebug $ sformat ("Trimmed leaders: "%listJson)
146+
$ dropAround (fromEnum siSlot) 10 strLeaders
147147

148148
ourHeavyPsk <- getPskByIssuer (Left ourPk)
149149
let heavyWeAreIssuer = isJust ourHeavyPsk

Diff for: block/src/Pos/Lrc/Worker.hs

+16-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import qualified Data.HashSet as HS
2222
import Ether.Internal (HasLens (..))
2323
import Formatting (build, ords, sformat, (%))
2424
import Mockable (forConcurrently)
25-
import Serokell.Util.Exceptions ()
2625
import System.Wlog (logDebug, logInfo, logWarning)
2726

2827
import Pos.Block.Logic.Internal (BypassSecurityCheck (..), MonadBlockApply,
2928
applyBlocksUnsafe, rollbackBlocksUnsafe)
3029
import Pos.Block.Slog.Logic (ShouldCallBListener (..))
31-
import Pos.Core (Coin, EpochIndex, EpochOrSlot (..), SharedSeed, StakeholderId,
32-
blkSecurityParam, crucialSlot, epochIndexL, getEpochOrSlot)
30+
import Pos.Core (Coin, EpochIndex, EpochOrSlot (..), SharedSeed, SlotLeaders,
31+
StakeholderId, blkSecurityParam, crucialSlot, epochIndexL,
32+
getEpochOrSlot, slotLeadersF)
3333
import qualified Pos.DB.Block.Load as DB
3434
import qualified Pos.DB.GState.Stakes as GS (getRealStake, getRealTotalStake)
3535
import qualified Pos.GState.SanityCheck as DB (sanityCheckDB)
@@ -206,12 +206,23 @@ issuersComputationDo epochId = do
206206
hm <$ (logWarning $ sformat ("Stake for issuer "%build% " not found") id)
207207
Just stake -> pure $ HM.insert id stake hm
208208

209-
leadersComputationDo :: LrcMode ctx m => EpochIndex -> SharedSeed -> m ()
209+
leadersComputationDo ::
210+
forall ctx m. LrcMode ctx m
211+
=> EpochIndex
212+
-> SharedSeed
213+
-> m ()
210214
leadersComputationDo epochId seed =
211215
unlessM (LrcDB.hasLeaders epochId) $ do
212216
totalStake <- GS.getRealTotalStake
213-
leaders <- runConduitRes $ GS.stakeSource .| followTheSatoshiM seed totalStake
217+
leaders <-
218+
runConduitRes $ GS.stakeSource .| followTheSatoshiM seed totalStake
214219
LrcDB.putLeadersForEpoch epochId leaders
220+
logLeaders leaders
221+
where
222+
logLeaders :: SlotLeaders -> m ()
223+
logLeaders leaders = logInfo $
224+
sformat ("Slot leaders for "%build%" are: "%slotLeadersF)
225+
epochId (toList leaders)
215226

216227
richmenComputationDo
217228
:: forall ctx m.

Diff for: core/Pos/Core/Common/Types.hs

+18-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module Pos.Core.Common.Types
2727

2828
, SharedSeed (..)
2929
, SlotLeaders
30+
, slotLeadersF
3031

3132
-- * Coin
3233
, Coin
@@ -61,8 +62,9 @@ import Data.Data (Data)
6162
import Data.Hashable (Hashable (..))
6263
import qualified Data.Semigroup (Semigroup (..))
6364
import qualified Data.Text.Buildable as Buildable
64-
import Formatting (Format, bprint, build, formatToString, int, (%))
65+
import Formatting (Format, bprint, build, formatToString, int, later, (%))
6566
import qualified PlutusCore.Program as PLCore
67+
import Serokell.Util (enumerate, listChunkedJson, pairBuilder)
6668
import Serokell.Util.Base16 (formatBase16)
6769
import System.Random (Random (..))
6870

@@ -230,6 +232,21 @@ instance Monoid SharedSeed where
230232
-- | 'NonEmpty' list of slot leaders.
231233
type SlotLeaders = NonEmpty StakeholderId
232234

235+
-- | Pretty-printer for slot leaders. Note: it takes list (not
236+
-- 'NonEmpty' as an argument, because one can always convert @NonEmpty
237+
-- a@ to @[a]@, but it also may be convenient to use it with a simple
238+
-- list of slot leaders).
239+
--
240+
-- Example:
241+
-- [
242+
-- (0, 44283ce5), (1, 5f53e01e), (2, 44283ce5), (3, 1a1ff703), (4, 44283ce5), (5, 44283ce5), (6, 281e5ae9), (7, 1a1ff703)
243+
-- (8, 1a1ff703), (9, 5f53e01e), (10, 1a1ff703), (11, 44283ce5), (12, 44283ce5), (13, 5f53e01e), (14, 5f53e01e), (15, 5f53e01e)
244+
-- (16, 44283ce5), (17, 281e5ae9), (18, 281e5ae9), (19, 44283ce5)
245+
-- ]
246+
slotLeadersF :: Format r ([StakeholderId] -> r)
247+
slotLeadersF =
248+
later $ bprint (listChunkedJson 8) . map pairBuilder . enumerate @Int
249+
233250
----------------------------------------------------------------------------
234251
-- Coin
235252
----------------------------------------------------------------------------

Diff for: explorer/src/explorer/Main.hs

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Universum
1414
import Data.Maybe (fromJust)
1515
import Formatting (sformat, shown, (%))
1616
import Mockable (Production, currentTime, runProduction)
17-
import System.Wlog (logInfo)
17+
import System.Wlog (LoggerName, logInfo)
1818

1919
import NodeOptions (ExplorerArgs (..), ExplorerNodeArgs (..), getExplorerNodeOptions)
2020
import Pos.Binary ()
@@ -36,14 +36,17 @@ import Pos.Util (mconcatPair)
3636
import Pos.Util.CompileInfo (HasCompileInfo, retrieveCompileTimeInfo, withCompileInfo)
3737
import Pos.Util.UserSecret (usVss)
3838

39+
loggerName :: LoggerName
40+
loggerName = "node"
41+
3942
----------------------------------------------------------------------------
4043
-- Main action
4144
----------------------------------------------------------------------------
4245

4346
main :: IO ()
4447
main = do
4548
args <- getExplorerNodeOptions
46-
let loggingParams = CLI.loggingParams "node" (enaCommonNodeArgs args)
49+
let loggingParams = CLI.loggingParams loggerName (enaCommonNodeArgs args)
4750
loggerBracket loggingParams . runProduction $ do
4851
CLI.printFlags
4952
logInfo $ "[Attention] Software is built with explorer part"
@@ -57,7 +60,7 @@ action (ExplorerNodeArgs (cArgs@CommonNodeArgs{..}) ExplorerArgs{..}) =
5760
logInfo $ sformat ("System start time is " % shown) systemStart
5861
t <- currentTime
5962
logInfo $ sformat ("Current time is " % shown) (Timestamp t)
60-
currentParams <- getNodeParams cArgs nodeArgs
63+
currentParams <- getNodeParams loggerName cArgs nodeArgs
6164
logInfo $ "Explorer is enabled!"
6265
logInfo $ sformat ("Using configs and genesis:\n"%shown) conf
6366

Diff for: lib/src/Pos/Client/CLI/Params.hs

+8-7
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ import Pos.Update.Params (UpdateParams (..))
2929
import Pos.Util.UserSecret (peekUserSecret)
3030

3131
loggingParams :: LoggerName -> CommonNodeArgs -> LoggingParams
32-
loggingParams tag CommonNodeArgs{..} =
32+
loggingParams defaultName CommonNodeArgs{..} =
3333
LoggingParams
3434
{ lpHandlerPrefix = logPrefix commonArgs
3535
, lpConfigPath = logConfig commonArgs
36-
, lpRunnerTag = tag
36+
, lpDefaultName = defaultName
3737
, lpConsoleLog = Nothing -- no override by default
3838
}
3939

4040
getBaseParams :: LoggerName -> CommonNodeArgs -> BaseParams
41-
getBaseParams loggingTag args@CommonNodeArgs {..} =
42-
BaseParams { bpLoggingParams = loggingParams loggingTag args }
41+
getBaseParams defaultLoggerName args@CommonNodeArgs {..} =
42+
BaseParams { bpLoggingParams = loggingParams defaultLoggerName args }
4343

4444
gtSscParams :: CommonNodeArgs -> VssKeyPair -> BehaviorConfig -> SscParams
4545
gtSscParams CommonNodeArgs {..} vssSK BehaviorConfig{..} =
@@ -65,10 +65,11 @@ getNodeParams ::
6565
, HasConfiguration
6666
, HasSscConfiguration
6767
)
68-
=> CommonNodeArgs
68+
=> LoggerName
69+
-> CommonNodeArgs
6970
-> NodeArgs
7071
-> m NodeParams
71-
getNodeParams cArgs@CommonNodeArgs{..} NodeArgs{..} = do
72+
getNodeParams defaultLoggerName cArgs@CommonNodeArgs{..} NodeArgs{..} = do
7273
(primarySK, userSecret) <-
7374
prepareUserSecret cArgs =<< peekUserSecret (getKeyfilePath cArgs)
7475
npNetworkConfig <- intNetworkConfigOpts networkConfigOpts
@@ -80,7 +81,7 @@ getNodeParams cArgs@CommonNodeArgs{..} NodeArgs{..} = do
8081
, npRebuildDb = rebuildDB
8182
, npSecretKey = primarySK
8283
, npUserSecret = userSecret
83-
, npBaseParams = getBaseParams "node" cArgs
84+
, npBaseParams = getBaseParams defaultLoggerName cArgs
8485
, npJLFile = jlPath
8586
, npReportServers = reportServers commonArgs
8687
, npUpdateParams = UpdateParams

Diff for: lib/src/Pos/Client/CLI/Util.hs

+5-14
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ module Pos.Client.CLI.Util
1212

1313
import Universum
1414

15-
import Control.Lens (zoom, (?=))
1615
import qualified Data.ByteString.Lazy as BSL
1716
import Formatting (sformat, shown, (%))
18-
import System.Wlog (LoggerConfig (..), Severity (Info, Warning), WithLogger, fromScratch,
19-
lcTree, logInfo, ltSeverity, parseLoggerConfig, zoomLogger)
17+
import System.Wlog (LoggerConfig (..), WithLogger, logInfo, parseLoggerConfig,
18+
productionB)
2019
import Text.Parsec (try)
2120
import qualified Text.Parsec.Char as P
2221
import qualified Text.Parsec.Text as P
@@ -51,19 +50,11 @@ attackTargetParser =
5150
(NetworkAddressTarget <$> addrParser)
5251

5352
-- | Default logger config. Will be used if `--log-config` argument is
54-
-- not passed. Corresponds to next logger config:
55-
--
56-
-- > node:
57-
-- > severity: Info
58-
-- > comm:
59-
-- > severity: Warning
60-
--
53+
-- not passed.
6154
defaultLoggerConfig :: LoggerConfig
62-
defaultLoggerConfig = fromScratch $ zoom lcTree $ zoomLogger "node" $ do
63-
ltSeverity ?= Info
64-
zoomLogger "comm" $ ltSeverity ?= Warning
55+
defaultLoggerConfig = productionB
6556

66-
-- | Reads logger config from given path. By default return
57+
-- | Reads logger config from given path. By default returns
6758
-- 'defaultLoggerConfig'.
6859
readLoggerConfig :: MonadIO m => Maybe FilePath -> m LoggerConfig
6960
readLoggerConfig = maybe (return defaultLoggerConfig) parseLoggerConfig

Diff for: lib/src/Pos/Launcher/Param.hs

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ import Pos.Util.UserSecret (UserSecret)
3131

3232
-- | Contains all parameters required for hierarchical logger initialization.
3333
data LoggingParams = LoggingParams
34-
{ lpRunnerTag :: !LoggerName -- ^ Prefix for logger, like "time-slave"
35-
, lpHandlerPrefix :: !(Maybe FilePath) -- ^ Prefix of path for all logs
36-
, lpConfigPath :: !(Maybe FilePath) -- ^ Path to logger configuration
37-
, lpConsoleLog :: !(Maybe Bool) -- ^ Enable console logging (override)
34+
{ lpDefaultName :: !LoggerName
35+
-- ^ Logger name which will be used by default
36+
, lpHandlerPrefix :: !(Maybe FilePath)
37+
-- ^ Prefix of path for all logs
38+
, lpConfigPath :: !(Maybe FilePath)
39+
-- ^ Path to logger configuration
40+
, lpConsoleLog :: !(Maybe Bool)
41+
-- ^ Enable console logging (override)
3842
} deriving (Show)
3943

4044
-- | Contains basic & networking parameters for running node.

0 commit comments

Comments
 (0)