Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracing documentation improvements #3500

Merged
merged 6 commits into from Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions Makefile
Expand Up @@ -63,8 +63,28 @@ shell: ## Enter Nix shell, CI mode (workbench run from Nix store)
cli node:
cabal --ghc-options="+RTS -qn8 -A32M -RTS" build cardano-$@

clean:
rm -rf dist-newstyle .stack-work $(shell find . -name '*~' -or -name '*.swp')
trace-documentation:
cabal run -- exe:cardano-node trace-documentation --config 'configuration/cardano/mainnet-config-new-tracing.yaml' --output-file 'doc/new-tracing/tracers_doc_generated.md'

BENCH_REPEATS ?= 3
BENCH_CONFIG ?= both
BENCH_TAG ?= HEAD
BENCH_XARGS ?=

profile-chainsync:
scripts/mainnet-via-fetcher.sh ${BENCH_XARGS} --node-config-${BENCH_CONFIG} --repeats ${BENCH_REPEATS} --nix --profile time --tag ${BENCH_TAG}

profile-chainsync-fast: BENCH_XARGS=--skip-prefetch
profile-chainsync-fast: profile-chainsync

clean-profile proclean:
rm -f *.html *.prof *.hp *.stats *.eventlog

clean: clean-profile
rm -rf logs/ socket/ cluster.*

full-clean: clean
rm -rf db dist-newstyle .stack-work $(shell find . -name '*~' -or -name '*.swp')

cls:
echo -en "\ec"
Expand Down
10 changes: 8 additions & 2 deletions cardano-node/app/cardano-node.hs
Expand Up @@ -20,6 +20,8 @@ import Cardano.Node.Handlers.TopLevel
import Cardano.Node.Parsers (nodeCLIParser, parserHelpHeader, parserHelpOptions,
renderHelpDoc)
import Cardano.Node.Run (runNode)
import Cardano.Node.Tracing.Documentation (TraceDocumentationCmd (..),
parseTraceDocumentationCmd, runTraceDocumentationCmd)

main :: IO ()
main = toplevelExceptionHandler $ do
Expand All @@ -28,15 +30,18 @@ main = toplevelExceptionHandler $ do

case cmd of
RunCmd args -> runRunCommand args
TraceDocumentation tdc -> runTraceDocumentationCmd tdc
VersionCmd -> runVersionCommand

where
p = Opt.prefs Opt.showHelpOnEmpty

opts :: Opt.ParserInfo Command
opts =
Opt.info (fmap RunCmd nodeCLIParser <|> parseVersionCmd
<**> helperBrief "help" "Show this help text" nodeCliHelpMain)
Opt.info (fmap RunCmd nodeCLIParser
<|> fmap TraceDocumentation parseTraceDocumentationCmd
<|> parseVersionCmd
<**> helperBrief "help" "Show this help text" nodeCliHelpMain)

( Opt.fullDesc <>
Opt.progDesc "Start node of the Cardano blockchain."
Expand All @@ -55,6 +60,7 @@ main = toplevelExceptionHandler $ do


data Command = RunCmd PartialNodeConfiguration
| TraceDocumentation TraceDocumentationCmd
| VersionCmd

-- Yes! A --version flag or version command. Either guess is right!
Expand Down
1 change: 1 addition & 0 deletions cardano-node/src/Cardano/Node/Parsers.hs
Expand Up @@ -4,6 +4,7 @@

module Cardano.Node.Parsers
( nodeCLIParser
, parseConfigFile
, parserHelpHeader
, parserHelpOptions
, renderHelpDoc
Expand Down
1 change: 1 addition & 0 deletions cardano-node/src/Cardano/Node/Protocol/Shelley.hs
Expand Up @@ -58,6 +58,7 @@ import Cardano.Tracing.OrphanInstances.Shelley ()
import Cardano.Node.Tracing.Era.HardFork ()
import Cardano.Node.Tracing.Era.Shelley ()
import Cardano.Node.Tracing.Formatting ()
import Cardano.Node.Tracing.Tracers.ChainDB ()

import Cardano.Node.Protocol.Types

Expand Down
4 changes: 4 additions & 0 deletions cardano-node/src/Cardano/Node/TraceConstraints.hs
Expand Up @@ -30,6 +30,8 @@ import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr,
HasTxId, HasTxs (..))
import Ouroboros.Consensus.Protocol.Abstract (ValidationErr)
import Ouroboros.Consensus.Shelley.Ledger.Mempool (GenTx, TxId)
import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
import Ouroboros.Network.Block (StandardHash)


-- | Tracing-related constraints for monitoring purposes.
Expand All @@ -38,6 +40,7 @@ type TraceConstraints blk =
, HasTxs blk
, HasTxId (GenTx blk)
, LedgerQueries blk
, StandardHash blk
, ToJSON (TxId (GenTx blk))
, ToJSON (TxOut (AlonzoEra StandardCrypto))
, ToJSON (PParamsUpdate (AlonzoEra StandardCrypto))
Expand Down Expand Up @@ -66,6 +69,7 @@ type TraceConstraints blk =
, LogFormatting (ApplyTxErr blk)
, LogFormatting (GenTx blk)
, LogFormatting (Header blk)
, LogFormatting (ChainDB.InvalidBlockReason blk)
, LogFormatting (LedgerError blk)
, LogFormatting (OtherHeaderEnvelopeError blk)
, LogFormatting (ValidationErr (BlockProtocol blk))
Expand Down
120 changes: 92 additions & 28 deletions cardano-node/src/Cardano/Node/Tracing/Documentation.hs
@@ -1,18 +1,27 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Node.Tracing.Documentation
( docTracers
( TraceDocumentationCmd (..)
, parseTraceDocumentationCmd
, runTraceDocumentationCmd
, docTracers
) where

import Data.Aeson.Types (ToJSON)
import qualified Data.Text.IO as T
import Network.Mux (MuxTrace (..), WithMuxBearer (..))
import qualified Network.Socket as Socket
import qualified Options.Applicative as Opt

import Cardano.Logging
import Cardano.Logging.Resources
Expand All @@ -38,21 +47,26 @@ import Cardano.Node.Handlers.Shutdown (ShutdownTrace)
import Cardano.Node.Startup
import Cardano.Node.TraceConstraints

import Ouroboros.Consensus.Block.Forging
import Ouroboros.Consensus.BlockchainTime.WallClock.Types (RelativeTime)
import Ouroboros.Consensus.BlockchainTime.WallClock.Util (TraceBlockchainTimeEvent (..))
import Ouroboros.Consensus.Ledger.Query (Query)
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, GenTx, GenTxId, TxId)
import Ouroboros.Consensus.Ledger.SupportsProtocol (LedgerSupportsProtocol)
import Ouroboros.Consensus.Cardano.Block
import Ouroboros.Consensus.Ledger.Inspect
import Ouroboros.Consensus.Ledger.Query (Query, ShowQuery)
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, GenTxId,
LedgerSupportsMempool)
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Mempool.API (TraceEventMempool (..))
import Ouroboros.Consensus.MiniProtocol.BlockFetch.Server
(TraceBlockFetchServerEvent (..))
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client (TraceChainSyncClientEvent)
import Ouroboros.Consensus.MiniProtocol.ChainSync.Server (TraceChainSyncServerEvent)
import Ouroboros.Consensus.MiniProtocol.LocalTxSubmission.Server
(TraceLocalTxSubmissionServerEvent (..))
import Ouroboros.Consensus.Node.NetworkProtocolVersion
import qualified Ouroboros.Consensus.Node.Run as Consensus
import qualified Ouroboros.Consensus.Node.Tracers as Consensus
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
import Ouroboros.Consensus.Shelley.Ledger.Block
import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB

import Ouroboros.Network.Block (Point (..), Tip)
Expand All @@ -76,6 +90,8 @@ import Ouroboros.Network.PeerSelection.RootPeersDNS (TraceLocalRootPee
TracePublicRootPeers (..))
import Ouroboros.Network.Protocol.BlockFetch.Type (BlockFetch)
import Ouroboros.Network.Protocol.ChainSync.Type (ChainSync)
import Ouroboros.Network.Protocol.Handshake.Unversioned (UnversionedProtocol (..),
UnversionedProtocolData (..))
import Ouroboros.Network.Protocol.LocalStateQuery.Type (LocalStateQuery)
import qualified Ouroboros.Network.Protocol.LocalTxSubmission.Type as LTS
import Ouroboros.Network.Protocol.TxSubmission.Type (TxSubmission)
Expand All @@ -90,32 +106,78 @@ import Ouroboros.Network.TxSubmission.Outbound (TraceTxSubmissionOutbo



data TraceDocumentationCmd
= TraceDocumentationCmd
{ tdcConfigFile :: FilePath
, tdcOutput :: FilePath
}

parseTraceDocumentationCmd :: Opt.Parser TraceDocumentationCmd
parseTraceDocumentationCmd =
Opt.subparser
(mconcat
[ Opt.commandGroup "Miscellaneous commands"
, Opt.metavar "trace-documentation"
, Opt.hidden
, Opt.command "trace-documentation" $
Opt.info
(TraceDocumentationCmd
<$> Opt.strOption
( Opt.long "config"
<> Opt.metavar "NODE-CONFIGURATION"
<> Opt.help "Configuration file for the cardano-node"
)
<*> Opt.strOption
( Opt.long "output-file"
<> Opt.metavar "FILE"
<> Opt.help "Generated documentation output file"
)
Opt.<**> Opt.helper)
$ mconcat [ Opt.progDesc "Generate the trace documentation" ]
]
)

deriving instance Generic UnversionedProtocol
deriving instance Generic UnversionedProtocolData

instance ToJSON UnversionedProtocol
instance ToJSON UnversionedProtocolData

runTraceDocumentationCmd
:: TraceDocumentationCmd
-> IO ()
runTraceDocumentationCmd TraceDocumentationCmd{..} = do
docTracers
tdcConfigFile tdcOutput (Proxy @(CardanoBlock StandardCrypto))
(Proxy @(NtN.ConnectionId LocalAddress))
(Proxy @(NtN.ConnectionId NtN.RemoteAddress))

-- Have to repeat the construction of the tracers here,
-- as the tracers are behind old tracer interface after construction in mkDispatchTracers.
-- Can be changed, when old tracers have gone
docTracers :: forall blk t peer peerConn remotePeer resolverError ntnVersion ntnVersionData.
( Show t
, forall result. Show (Query blk result)
, TraceConstraints blk
, LogFormatting (ChainDB.InvalidBlockReason blk)
docTracers :: forall blk peer remotePeer.
( TraceConstraints blk
, InspectLedger blk
, LedgerSupportsMempool blk
, LedgerSupportsProtocol blk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LedgerSupportsProtocol blk is unnecessary.

RunNode blk is pulling in 18 unnecessary constraints. I would consider creating a type synonym for the constraints needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jimbo4350, I've removed what I could, and consolidated the constraints a bit.

..but removing the RunNode constraint is very difficult as of now, because of how tangled things are at the moment.
I've spent some hours on it, and it's just not easy at all.

It'll be far easier to deal with it at the point when we'll be removing the legacy system.

Copy link
Contributor

@Jimbo4350 Jimbo4350 Jan 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me help you 😄

diff --git a/cardano-node/src/Cardano/Node/Tracing/Documentation.hs b/cardano-node/src/Cardano/Node/Tracing/Documentation.hs
index 887705e29..44d19cb3b 100644
--- a/cardano-node/src/Cardano/Node/Tracing/Documentation.hs
+++ b/cardano-node/src/Cardano/Node/Tracing/Documentation.hs
@@ -47,11 +47,15 @@ import           Cardano.Node.Handlers.Shutdown (ShutdownTrace)
 import           Cardano.Node.Startup
 import           Cardano.Node.TraceConstraints
 
+import           Ouroboros.Consensus.Block.Forging
 import           Ouroboros.Consensus.BlockchainTime.WallClock.Types (RelativeTime)
 import           Ouroboros.Consensus.BlockchainTime.WallClock.Util (TraceBlockchainTimeEvent (..))
 import           Ouroboros.Consensus.Cardano.Block
-import           Ouroboros.Consensus.Ledger.Query (Query)
-import           Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, GenTxId)
+import           Ouroboros.Consensus.Ledger.Inspect
+import           Ouroboros.Consensus.Ledger.Query (Query, ShowQuery)
+import           Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, GenTxId,
+                   LedgerSupportsMempool)
+import           Ouroboros.Consensus.Ledger.SupportsProtocol
 import           Ouroboros.Consensus.Mempool.API (TraceEventMempool (..))
 import           Ouroboros.Consensus.MiniProtocol.BlockFetch.Server
                    (TraceBlockFetchServerEvent (..))
@@ -59,6 +63,7 @@ import           Ouroboros.Consensus.MiniProtocol.ChainSync.Client (TraceChainSy
 import           Ouroboros.Consensus.MiniProtocol.ChainSync.Server (TraceChainSyncServerEvent)
 import           Ouroboros.Consensus.MiniProtocol.LocalTxSubmission.Server
                    (TraceLocalTxSubmissionServerEvent (..))
+import           Ouroboros.Consensus.Node.NetworkProtocolVersion
 import qualified Ouroboros.Consensus.Node.Run as Consensus
 import qualified Ouroboros.Consensus.Node.Tracers as Consensus
 import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
@@ -85,8 +90,8 @@ import           Ouroboros.Network.PeerSelection.RootPeersDNS (TraceLocalRootPee
                    TracePublicRootPeers (..))
 import           Ouroboros.Network.Protocol.BlockFetch.Type (BlockFetch)
 import           Ouroboros.Network.Protocol.ChainSync.Type (ChainSync)
-import           Ouroboros.Network.Protocol.Handshake.Unversioned (UnversionedProtocolData (..),
-                   UnversionedProtocol (..))
+import           Ouroboros.Network.Protocol.Handshake.Unversioned (UnversionedProtocol (..),
+                   UnversionedProtocolData (..))
 import           Ouroboros.Network.Protocol.LocalStateQuery.Type (LocalStateQuery)
 import qualified Ouroboros.Network.Protocol.LocalTxSubmission.Type as LTS
 import           Ouroboros.Network.Protocol.TxSubmission.Type (TxSubmission)
@@ -152,11 +157,19 @@ runTraceDocumentationCmd TraceDocumentationCmd{..} = do
 -- Can be changed, when old tracers have gone
 docTracers :: forall blk peer remotePeer.
   ( TraceConstraints blk
+  , InspectLedger blk
+  , LedgerSupportsMempool blk
+  , LedgerSupportsProtocol blk
+  , Consensus.SerialiseNodeToNodeConstraints blk
   , LogFormatting peer
   , LogFormatting remotePeer
-  , Consensus.RunNode blk
+  , Show (BlockNodeToClientVersion blk)
+  , Show (BlockNodeToNodeVersion blk)
   , Show remotePeer
   , Show peer
+  , Show (ForgeStateUpdateError blk)
+  , Show (CannotForge blk)
+  , ShowQuery (BlockQuery blk)
   )
   => FilePath
   -> FilePath

What part in particular was difficult for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jimbo4350, applied your patch -- thanks a lot!

, Consensus.RunNode blk
, Consensus.SerialiseNodeToNodeConstraints blk
, LogFormatting peer
, LogFormatting remotePeer
, Show (BlockNodeToClientVersion blk)
, Show (BlockNodeToNodeVersion blk)
, Show remotePeer
, Show peer
, Show resolverError
, Show peerConn
, Show ntnVersion
, ToJSON ntnVersion
, Show ntnVersionData
, ToJSON ntnVersionData
, Show (ForgeStateUpdateError blk)
, Show (CannotForge blk)
, ShowQuery (BlockQuery blk)
)
=> FilePath
-> FilePath
-> Proxy blk
-> Proxy peer
-> Proxy remotePeer
-> IO ()
docTracers configFileName outputFileName _ = do
docTracers configFileName outputFileName _ _ _ = do
trConfig <- readConfiguration configFileName
let trBase :: Trace IO FormattedMessage = docTracer (Stdout MachineFormat)
trForward :: Trace IO FormattedMessage = docTracer Forwarder
Expand Down Expand Up @@ -161,7 +223,8 @@ docTracers configFileName outputFileName _ = do
shutdownTrDoc <- documentTracer trConfig shutdownTr
(docShutdown :: Documented ShutdownTrace)

-- Peers tracer
-- Peers tracer

peersTr <- mkCardanoTracer
trBase trForward mbTrEKG
"Peers"
Expand Down Expand Up @@ -194,7 +257,7 @@ docTracers configFileName outputFileName _ = do
replayBlockTrDoc <- documentTracer trConfig replayBlockTr
(docReplayedBlock :: Documented ReplayBlockStats)

---- Consensus tracers
-- Consensus tracers

chainSyncClientTr <- mkCardanoTracer
trBase trForward mbTrEKG
Expand Down Expand Up @@ -346,7 +409,7 @@ docTracers configFileName outputFileName _ = do
allPublic
configureTracers trConfig docBlockchainTime [blockchainTimeTr]
blockchainTimeTrDoc <- documentTracer trConfig blockchainTimeTr
(docBlockchainTime :: Documented (TraceBlockchainTimeEvent t))
(docBlockchainTime :: Documented (TraceBlockchainTimeEvent RelativeTime))

-- Node to client

Expand Down Expand Up @@ -477,7 +540,7 @@ docTracers configFileName outputFileName _ = do
(TraceSendRecv
(TxSubmission2 (GenTxId blk) (GenTx blk)))))

-- -- Diffusion
-- Diffusion
dtMuxTr <- mkCardanoTracer
trBase trForward mbTrEKG
"Mux"
Expand Down Expand Up @@ -542,6 +605,7 @@ docTracers configFileName outputFileName _ = do
(docLedgerPeers :: Documented TraceLedgerPeers)

-- DiffusionTracersExtra P2P

localRootPeersTr <- mkCardanoTracer
trBase trForward mbTrEKG
"LocalRootPeers"
Expand All @@ -550,7 +614,7 @@ docTracers configFileName outputFileName _ = do
allPublic
configureTracers trConfig docLocalRootPeers [localRootPeersTr]
localRootPeersTrDoc <- documentTracer trConfig localRootPeersTr
(docLocalRootPeers :: Documented (TraceLocalRootPeers RemoteAddress resolverError))
(docLocalRootPeers :: Documented (TraceLocalRootPeers RemoteAddress SomeException))

publicRootPeersTr <- mkCardanoTracer
trBase trForward mbTrEKG
Expand Down Expand Up @@ -580,7 +644,7 @@ docTracers configFileName outputFileName _ = do
allPublic
configureTracers trConfig docDebugPeerSelection [debugPeerSelectionTr]
debugPeerSelectionTrDoc <- documentTracer trConfig debugPeerSelectionTr
(docDebugPeerSelection :: Documented (DebugPeerSelection Socket.SockAddr peerConn))
(docDebugPeerSelection :: Documented (DebugPeerSelection Socket.SockAddr peer))

debugPeerSelectionResponderTr <- mkCardanoTracer
trBase trForward mbTrEKG
Expand All @@ -590,7 +654,7 @@ docTracers configFileName outputFileName _ = do
allPublic
configureTracers trConfig docDebugPeerSelection [debugPeerSelectionResponderTr]
debugPeerSelectionResponderTrDoc <- documentTracer trConfig debugPeerSelectionResponderTr
(docDebugPeerSelection :: Documented (DebugPeerSelection Socket.SockAddr peerConn))
(docDebugPeerSelection :: Documented (DebugPeerSelection Socket.SockAddr peer))

peerSelectionCountersTr <- mkCardanoTracer
trBase trForward mbTrEKG
Expand Down Expand Up @@ -624,7 +688,7 @@ docTracers configFileName outputFileName _ = do
(docConnectionManager :: Documented
(ConnectionManagerTrace
Socket.SockAddr
(ConnectionHandlerTrace ntnVersion ntnVersionData)))
(ConnectionHandlerTrace UnversionedProtocol UnversionedProtocolData)))

serverTr <- mkCardanoTracer
trBase trForward mbTrEKG
Expand Down Expand Up @@ -658,8 +722,8 @@ docTracers configFileName outputFileName _ = do
(ConnectionManagerTrace
Socket.SockAddr
(ConnectionHandlerTrace
ntnVersion
ntnVersionData)))
UnversionedProtocol
UnversionedProtocolData)))

localServerTr <- mkCardanoTracer
trBase trForward mbTrEKG
Expand Down
1 change: 0 additions & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers.hs
Expand Up @@ -196,7 +196,6 @@ mkDispatchTracers nodeKernel trBase trForward mbTrEKG trDataPoint trConfig enabl

mkConsensusTracers :: forall blk.
( Consensus.RunNode blk
, LogFormatting (ChainDB.InvalidBlockReason blk)
, TraceConstraints blk
, LogFormatting (BlockFetch.TraceLabelPeer
(ConnectionId RemoteAddress) (TraceChainSyncClientEvent blk))
Expand Down
6 changes: 3 additions & 3 deletions doc/New Tracing Quickstart.md
Expand Up @@ -58,7 +58,7 @@ describe next.
# Only show a maximum of 2 of these messages per second
- ns: Node.ChainDB.AddBlockEvent.AddedBlockToQueue
limiterName: AddedBlockToQueueLimiter
limiterFrequency: 2.0
limiterFrequency: 2.0
~~~

The activity of limiters will be written in the traces as well.
Expand All @@ -76,8 +76,8 @@ describe next.
~~~

These are all the backends currently supported. With Stdout you have the
options MachineFormat or HumanFormat. If messages don't support representation
in HumanFormat they are shown in MachineFormat anyway.
options MachineFormat or HumanFormatColoured/HumanFormatUncoloured.
If messages don't support representation in HumanFormat* they are shown in MachineFormat anyway.

Forwarder means that messages are send to cardano-tracer

Expand Down