Skip to content

Commit

Permalink
Move TraceOptions to cardano-config
Browse files Browse the repository at this point in the history
Add `ccTraceOptions` to `CardanoConfiguration`
Add `pccTraceOptions` to `PartialCardanoConfiguration`
  • Loading branch information
Jimbo4350 committed Oct 14, 2019
1 parent e8585dc commit 0607a9f
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 58 deletions.
1 change: 1 addition & 0 deletions cardano-config/cardano-config.cabal
Expand Up @@ -32,6 +32,7 @@ library
, cardano-prelude-test
, cardano-shell
, cborg
, contra-tracer
, generic-monoid
, iohk-monitoring
, lobemo-backend-aggregation
Expand Down
24 changes: 0 additions & 24 deletions cardano-config/src/Cardano/Config/Logging.hs
Expand Up @@ -7,10 +7,7 @@

module Cardano.Config.Logging
( LoggingLayer (..)
, TraceOptions (..)
, LoggingFlag (..)
, ConsensusTraceOptions
, ProtocolTraceOptions
, LoggingConfiguration (..)
, createLoggingFeature
, loggingCLIConfiguration
Expand Down Expand Up @@ -47,7 +44,6 @@ import Cardano.BM.Data.LogItem ( LOContent (..), LOMeta (..),
import Cardano.BM.Data.Observable
import Cardano.BM.Data.Severity (Severity (..))
import Cardano.BM.Data.SubTrace
import Cardano.BM.Data.Tracer (TracingVerbosity (..))
import qualified Cardano.BM.Observer.Monadic as Monadic
import qualified Cardano.BM.Observer.STM as Stm
import Cardano.BM.Plugin (loadPlugin)
Expand All @@ -57,8 +53,6 @@ import qualified Cardano.BM.Trace as Trace
import Cardano.Shell.Lib (GeneralException (..), doesFileExist)
import Cardano.Shell.Types ( CardanoFeature (..),
CardanoFeatureInit (..), NoDependency (..))
import qualified Ouroboros.Consensus.Node.Tracers as Consensus
import Ouroboros.Consensus.NodeNetwork (ProtocolTracers'(..))

import Cardano.Config.Types (CardanoConfiguration(..), CardanoEnvironment)

Expand All @@ -75,24 +69,6 @@ data LoggingConfiguration = LoggingConfiguration
, recordMetrics :: !Bool
}

-- | Detailed tracing options. Each option enables a tracer
-- which verbosity to the log output.
data TraceOptions = TraceOptions
{ traceVerbosity :: !TracingVerbosity
, traceChainDB :: !Bool
-- ^ By default we use 'readableChainDB' tracer, if on this it will use
-- more verbose tracer
, traceConsensus :: ConsensusTraceOptions
, traceProtocols :: ProtocolTraceOptions
, traceIpSubscription :: !Bool
, traceDnsSubscription :: !Bool
, traceDnsResolver :: !Bool
, traceMux :: !Bool
}

type ConsensusTraceOptions = Consensus.Tracers' () () () (Const Bool)
type ProtocolTraceOptions = ProtocolTracers' () () () (Const Bool)

--------------------------------
-- Layer
--------------------------------
Expand Down
81 changes: 76 additions & 5 deletions cardano-config/src/Cardano/Config/Orphanage.hs
@@ -1,14 +1,85 @@
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Config.Orphanage ()
where
module Cardano.Config.Orphanage
( ConsensusTraceOptions
, ProtocolTraceOptions
, TraceOptions(..)
, traceOptionsDefault
) where

import Cardano.Prelude
import Cardano.Prelude

import Cardano.BM.Data.Tracer (TracingVerbosity (..))
import qualified Ouroboros.Consensus.BlockchainTime as Consensus

import qualified Ouroboros.Consensus.Node.Tracers as ConsensusTracers
import Ouroboros.Consensus.NodeNetwork (ProtocolTracers'(..))

deriving instance Eq Consensus.SlotLength
deriving instance Num Consensus.SlotLength

type ConsensusTraceOptions = ConsensusTracers.Tracers' () () () (Const Bool)
deriving instance Eq ConsensusTraceOptions
deriving instance Show ConsensusTraceOptions

type ProtocolTraceOptions = ProtocolTracers' () () () (Const Bool)
deriving instance Eq ProtocolTraceOptions
deriving instance Show ProtocolTraceOptions

-- | Detailed tracing options. Each option enables a tracer
-- which verbosity to the log output.
data TraceOptions = TraceOptions
{ traceVerbosity :: !TracingVerbosity
, traceChainDB :: !Bool
-- ^ By default we use 'readableChainDB' tracer, if on this it will use
-- more verbose tracer
, traceConsensus :: ConsensusTraceOptions
, traceProtocols :: ProtocolTraceOptions
, traceIpSubscription :: !Bool
, traceDnsSubscription :: !Bool
, traceDnsResolver :: !Bool
, traceMux :: !Bool
} deriving (Eq, Show)

deriving instance Show TracingVerbosity

consensusTraceDefault :: ConsensusTraceOptions
consensusTraceDefault =
ConsensusTracers.Tracers
(Const True)
(Const True)
(Const True)
(Const True)
(Const True)
(Const True)
(Const True)
(Const True)
(Const True)
(Const True)
(Const True)

protocolTraceDefault :: ProtocolTraceOptions
protocolTraceDefault =
ProtocolTracers
(Const True)
(Const True)
(Const True)
(Const True)
(Const True)


traceOptionsDefault :: TraceOptions
traceOptionsDefault =
TraceOptions
{ traceVerbosity = NormalVerbosity
, traceChainDB = True
, traceConsensus = consensusTraceDefault
, traceProtocols = protocolTraceDefault
, traceIpSubscription = True
, traceDnsSubscription = True
, traceDnsResolver = True
, traceMux = True
}
2 changes: 2 additions & 0 deletions cardano-config/src/Cardano/Config/Partial.hs
Expand Up @@ -47,6 +47,7 @@ data PartialCardanoConfiguration = PartialCardanoConfiguration
, pccProtocol :: !(Last Protocol)
, pccViewMode :: !(Last ViewMode)
, pccLogMetrics :: !(Last Bool)
, pccTraceOptions :: !(Last TraceOptions)
, pccCore :: !PartialCore
, pccNTP :: !PartialNTP
, pccUpdate :: !PartialUpdate
Expand Down Expand Up @@ -237,6 +238,7 @@ mkCardanoConfiguration PartialCardanoConfiguration{..} = do
ccProtocol <- mkComplete "ccProtocol" pccProtocol
ccViewMode <- mkComplete "ccViewMode" pccViewMode
ccLogMetrics <- mkComplete "ccLogMetrics" pccLogMetrics
ccTraceOptions <- mkComplete "ccTraceOptions" pccTraceOptions
ccCore <- mkCore pccCore
ccNTP <- mkNTP pccNTP
ccUpdate <- mkUpdate pccUpdate
Expand Down
4 changes: 3 additions & 1 deletion cardano-config/src/Cardano/Config/Presets.hs
Expand Up @@ -9,7 +9,7 @@ import Cardano.Prelude

import Ouroboros.Consensus.NodeId

import Cardano.Config.Orphanage ()
import Cardano.Config.Orphanage (traceOptionsDefault)
import Cardano.Config.Partial ( NodeProtocol (..)
, PartialBlock (..)
, PartialCardanoConfiguration (..)
Expand Down Expand Up @@ -44,6 +44,7 @@ mainnetConfiguration =
, pccProtocol = pure ByronLegacy
, pccViewMode = pure LiveView
, pccLogMetrics = pure True
, pccTraceOptions = pure traceOptionsDefault
, pccSocketDir = pure "./socket/"
, pccCore =
PartialCore
Expand Down Expand Up @@ -163,6 +164,7 @@ devConfiguration =
, pccProtocol = pure ByronLegacy
, pccViewMode = pure LiveView
, pccLogMetrics = pure True
, pccTraceOptions = pure traceOptionsDefault
, pccCore =
PartialCore
{ pcoGenesisFile = pure "testnet-genesis.json"
Expand Down
6 changes: 4 additions & 2 deletions cardano-config/src/Cardano/Config/Types.hs
Expand Up @@ -17,6 +17,7 @@ module Cardano.Config.Types
, BlockVersionData (..)
, LastKnownBlockVersion (..)
, SoftForkRule (..)
, TraceOptions (..)
, TxFeePolicy (..)
, TxSizeLinear (..)
, Protocol (..)
Expand All @@ -38,7 +39,7 @@ import Cardano.Prelude

import qualified Ouroboros.Consensus.BlockchainTime as Consensus

import Cardano.Config.Orphanage ()
import Cardano.Config.Orphanage (TraceOptions(..))
import Cardano.Config.Topology

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -78,7 +79,8 @@ data CardanoConfiguration = CardanoConfiguration
-- ^ The location of the application lock file that is used
-- as a semaphore se we can run just one application
-- instance at a time.

, ccTraceOptions :: !TraceOptions
-- ^ Tracer options
, ccTopologyInfo :: !TopologyInfo
-- ^ The network topology.
, ccNodeAddress :: !NodeAddress
Expand Down
18 changes: 9 additions & 9 deletions cardano-node/app/cardano-node.hs
Expand Up @@ -91,7 +91,7 @@ initializeAllFeatures
-> PartialCardanoConfiguration
-> CardanoEnvironment
-> IO ([CardanoFeature], NodeLayer)
initializeAllFeatures (NodeCLI traceOpts parsedPcc)
initializeAllFeatures (NodeCLI parsedPcc)
partialConfigPreset cardanoEnvironment = do

-- `partialConfigPreset` and `parsedPcc` are merged then checked here using
Expand All @@ -105,7 +105,6 @@ initializeAllFeatures (NodeCLI traceOpts parsedPcc)
(nodeLayer , nodeFeature) <-
createNodeFeature
loggingLayer
traceOpts
cardanoEnvironment
finalConfig

Expand All @@ -119,9 +118,7 @@ initializeAllFeatures (NodeCLI traceOpts parsedPcc)
-------------------------------------------------------------------------------

-- TODO: Condense `NodeCLI` into one big `PartialCardanoConfiguration`
data NodeCLI = NodeCLI
!TraceOptions
!PartialCardanoConfiguration
data NodeCLI = NodeCLI !PartialCardanoConfiguration

-- | The product parser for all the CLI arguments.
nodeCliParser :: Parser NodeCLI
Expand All @@ -143,10 +140,10 @@ nodeCliParser = do
reqNetMagic <- parseRequireNetworkMagic
slotLength <- parseSlotLength

pure $ NodeCLI traceOptions
pure $ NodeCLI
(createPcc dbPath socketDir topInfo nAddr ptcl logConfigFp vMode
logMetrics genPath genHash delCert sKey pbftSigThresh
reqNetMagic slotLength)
reqNetMagic traceOptions slotLength)
where
-- This merges the command line parsed values into one `PartialCardanoconfiguration`.
createPcc
Expand All @@ -164,6 +161,7 @@ nodeCliParser = do
-> Last FilePath
-> Last Double
-> Last RequireNetworkMagic
-> Last TraceOptions
-> Last Consensus.SlotLength
-> PartialCardanoConfiguration
createPcc
Expand All @@ -181,6 +179,7 @@ nodeCliParser = do
sKey
pbftSigThresh
reqNetMagic
traceOptions
slotLength = mempty { pccDBPath = dbPath
, pccNodeAddress = nAddr
, pccSocketDir = socketDir
Expand All @@ -197,12 +196,13 @@ nodeCliParser = do
, pcoRequiresNetworkMagic = reqNetMagic
}
, pccNode = mempty { pnoSlotLength = slotLength }
, pccTraceOptions = traceOptions
}



cliTracingParser :: Parser TraceOptions
cliTracingParser = parseTraceOptions Opt.hidden
cliTracingParser :: Parser (Last TraceOptions)
cliTracingParser = Last . Just <$> parseTraceOptions Opt.hidden

parseNodeAddress :: Parser NodeAddress
parseNodeAddress = NodeAddress <$> parseHostAddr <*> parsePort
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Common/Parsers.hs
Expand Up @@ -33,8 +33,8 @@ import Ouroboros.Consensus.NodeId (NodeId(..), CoreNodeId(..))
import Ouroboros.Consensus.NodeNetwork (ProtocolTracers'(..))
import qualified Ouroboros.Consensus.Node.Tracers as Consensus

import Cardano.Config.Orphanage
import Cardano.Config.Protocol
import Cardano.Config.Logging
import Cardano.Config.Topology

-- Common command line parsers
Expand Down
12 changes: 3 additions & 9 deletions cardano-node/src/Cardano/Node/Features/Node.hs
Expand Up @@ -13,8 +13,6 @@ import Cardano.Config.Types (CardanoConfiguration (..),
import Cardano.Config.Logging (LoggingLayer (..),)
import Cardano.Node.Run
import Cardano.Shell.Types (CardanoFeature (..))
import Cardano.Tracing.Tracers


-------------------------------------------------------------------------------
-- Layer
Expand All @@ -31,12 +29,10 @@ data NodeLayer = NodeLayer

createNodeFeature
:: LoggingLayer
-> TraceOptions
-> CardanoEnvironment
-> CardanoConfiguration
-> IO (NodeLayer, CardanoFeature)
createNodeFeature loggingLayer traceOptions
cardanoEnvironment cardanoConfiguration = do
createNodeFeature loggingLayer cardanoEnvironment cardanoConfiguration = do
-- we parse any additional configuration if there is any
-- We don't know where the user wants to fetch the additional
-- configuration from, it could be from the filesystem, so
Expand All @@ -47,7 +43,6 @@ createNodeFeature loggingLayer traceOptions
cardanoEnvironment
loggingLayer
cardanoConfiguration
traceOptions

-- Construct the cardano feature
let cardanoFeature :: CardanoFeature
Expand All @@ -64,9 +59,8 @@ createNodeFeature loggingLayer traceOptions
:: CardanoEnvironment
-> LoggingLayer
-> CardanoConfiguration
-> TraceOptions
-> IO NodeLayer
createNodeLayer _ logLayer cc traceOpts = do
createNodeLayer _ logLayer cc = do
pure $ NodeLayer
{ nlRunNode = liftIO $ runNode logLayer traceOpts cc
{ nlRunNode = liftIO $ runNode logLayer cc
}
12 changes: 6 additions & 6 deletions cardano-node/src/Cardano/Node/Run.hs
Expand Up @@ -45,8 +45,9 @@ import Cardano.BM.Data.LogItem (LogObject (..))
import Cardano.BM.Data.Tracer (ToLogObject (..),
TracingVerbosity (..))
import Cardano.BM.Trace (appendName)
import Cardano.Config.Types (CardanoConfiguration (..), ViewMode (..))
import Cardano.Config.Logging (LoggingLayer (..))
import Cardano.Config.Orphanage
import Cardano.Config.Types (CardanoConfiguration (..), ViewMode (..))

import Ouroboros.Network.Block
import Ouroboros.Network.Subscription.Dns
Expand Down Expand Up @@ -89,22 +90,21 @@ instance NoUnexpectedThunks Peer where

runNode
:: LoggingLayer
-> TraceOptions
-> CardanoConfiguration
-> IO ()
runNode loggingLayer traceOptions cc = do
runNode loggingLayer cc = do
let !tr = llAppendName loggingLayer "node" (llBasicTrace loggingLayer)
let trace' = appendName (pack $ show $ node (ccTopologyInfo cc)) tr
let tracer = contramap pack $ toLogObject trace'

traceWith tracer $ "tracing verbosity = " ++
case traceVerbosity traceOptions of
NormalVerbosity -> "normal"
case traceVerbosity $ ccTraceOptions cc of
NormalVerbosity -> "normal"
MinimalVerbosity -> "minimal"
MaximalVerbosity -> "maximal"
SomeProtocol p <- fromProtocol cc (ccProtocol cc)

let tracers = mkTracers traceOptions trace'
let tracers = mkTracers (ccTraceOptions cc) trace'

case ccViewMode cc of
SimpleView -> handleSimpleNode p trace' tracers cc
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Tracing/Tracers.hs
Expand Up @@ -60,7 +60,7 @@ import Ouroboros.Network.Subscription

import qualified Ouroboros.Storage.ChainDB as ChainDB

import Cardano.Config.Logging
import Cardano.Config.Orphanage
import Cardano.Tracing.ToObjectOrphans

data Tracers peer blk = Tracers {
Expand Down

0 comments on commit 0607a9f

Please sign in to comment.