Skip to content

Commit

Permalink
cardano-tracer: init RTView
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Shevchenko committed May 20, 2022
1 parent 25a0803 commit 9c97b64
Show file tree
Hide file tree
Showing 60 changed files with 6,366 additions and 54 deletions.
16 changes: 10 additions & 6 deletions cardano-tracer/bench/cardano-tracer-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Cardano.Logging hiding (LocalSocket)

import Cardano.Tracer.Configuration
import Cardano.Tracer.Handlers.Logs.TraceObjects (traceObjectsHandler)
import Cardano.Tracer.Handlers.RTView.State.TraceObjects (initSavedTraceObjects)
import Cardano.Tracer.Types (NodeId (..))

main :: IO ()
Expand All @@ -25,19 +26,21 @@ main = do
to100 <- generate 100
to1000 <- generate 1000

savedTO <- initSavedTraceObjects

removePathForcibly root

defaultMain
[ bgroup "cardano-tracer"
[ -- 10 'TraceObject's per request.
bench "Handle TraceObjects LOG, 10" $ whnfIO $ traceObjectsHandler c1 nId lock to10
, bench "Handle TraceObjects JSON, 10" $ whnfIO $ traceObjectsHandler c2 nId lock to10
bench "Handle TraceObjects LOG, 10" $ whnfIO $ traceObjectsHandler c1 nId lock savedTO to10
, bench "Handle TraceObjects JSON, 10" $ whnfIO $ traceObjectsHandler c2 nId lock savedTO to10
-- 100 'TraceObject's per request.
, bench "Handle TraceObjects LOG, 100" $ whnfIO $ traceObjectsHandler c1 nId lock to100
, bench "Handle TraceObjects JSON, 100" $ whnfIO $ traceObjectsHandler c2 nId lock to100
, bench "Handle TraceObjects LOG, 100" $ whnfIO $ traceObjectsHandler c1 nId lock savedTO to100
, bench "Handle TraceObjects JSON, 100" $ whnfIO $ traceObjectsHandler c2 nId lock savedTO to100
-- 1000 'TraceObject's per request.
, bench "Handle TraceObjects LOG, 1000" $ whnfIO $ traceObjectsHandler c1 nId lock to1000
, bench "Handle TraceObjects JSON, 1000" $ whnfIO $ traceObjectsHandler c2 nId lock to1000
, bench "Handle TraceObjects LOG, 1000" $ whnfIO $ traceObjectsHandler c1 nId lock savedTO to1000
, bench "Handle TraceObjects JSON, 1000" $ whnfIO $ traceObjectsHandler c2 nId lock savedTO to1000
]
]
where
Expand All @@ -50,6 +53,7 @@ main = do
, ekgRequestFreq = Nothing
, hasEKG = Nothing
, hasPrometheus = Nothing
, hasRTView = Nothing
, logging = NE.fromList [LoggingParams root FileMode format]
, rotation = Nothing
, verbosity = Nothing
Expand Down
55 changes: 55 additions & 0 deletions cardano-tracer/cardano-tracer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ library
Cardano.Tracer.Acceptors.Server
Cardano.Tracer.Acceptors.Utils

Cardano.Tracer.Handlers.CheckMode

Cardano.Tracer.Handlers.Logs.File
Cardano.Tracer.Handlers.Logs.Journal
Cardano.Tracer.Handlers.Logs.Rotator
Expand All @@ -45,6 +47,51 @@ library
Cardano.Tracer.Handlers.Metrics.Monitoring
Cardano.Tracer.Handlers.Metrics.Prometheus
Cardano.Tracer.Handlers.Metrics.Servers
Cardano.Tracer.Handlers.Metrics.Utils

Cardano.Tracer.Handlers.RTView.Run
Cardano.Tracer.Handlers.RTView.State.Displayed
Cardano.Tracer.Handlers.RTView.State.EraSettings
Cardano.Tracer.Handlers.RTView.State.Errors
Cardano.Tracer.Handlers.RTView.State.Historical
Cardano.Tracer.Handlers.RTView.State.Last
Cardano.Tracer.Handlers.RTView.State.Peers
Cardano.Tracer.Handlers.RTView.State.TraceObjects
Cardano.Tracer.Handlers.RTView.System
Cardano.Tracer.Handlers.RTView.UI.CSS.Bulma
Cardano.Tracer.Handlers.RTView.UI.CSS.Own
Cardano.Tracer.Handlers.RTView.UI.HTML.Node.Column
Cardano.Tracer.Handlers.RTView.UI.HTML.Node.EKG
Cardano.Tracer.Handlers.RTView.UI.HTML.Node.Errors
Cardano.Tracer.Handlers.RTView.UI.HTML.Node.Peers
Cardano.Tracer.Handlers.RTView.UI.HTML.About
Cardano.Tracer.Handlers.RTView.UI.HTML.Body
Cardano.Tracer.Handlers.RTView.UI.HTML.Main
Cardano.Tracer.Handlers.RTView.UI.HTML.NoNodes
Cardano.Tracer.Handlers.RTView.UI.HTML.Notifications
Cardano.Tracer.Handlers.RTView.UI.JS.ChartJS
Cardano.Tracer.Handlers.RTView.UI.JS.Charts
Cardano.Tracer.Handlers.RTView.UI.JS.Utils
Cardano.Tracer.Handlers.RTView.UI.Img.Icons
Cardano.Tracer.Handlers.RTView.UI.Charts
Cardano.Tracer.Handlers.RTView.UI.Theme
Cardano.Tracer.Handlers.RTView.UI.Types
Cardano.Tracer.Handlers.RTView.UI.Utils
Cardano.Tracer.Handlers.RTView.Update.Chain
Cardano.Tracer.Handlers.RTView.Update.EKG
Cardano.Tracer.Handlers.RTView.Update.EraSettings
Cardano.Tracer.Handlers.RTView.Update.Errors
Cardano.Tracer.Handlers.RTView.Update.Historical
Cardano.Tracer.Handlers.RTView.Update.KES
Cardano.Tracer.Handlers.RTView.Update.Leadership
Cardano.Tracer.Handlers.RTView.Update.NodeInfo
Cardano.Tracer.Handlers.RTView.Update.NodeState
Cardano.Tracer.Handlers.RTView.Update.Nodes
Cardano.Tracer.Handlers.RTView.Update.Peers
Cardano.Tracer.Handlers.RTView.Update.Reload
Cardano.Tracer.Handlers.RTView.Update.Resources
Cardano.Tracer.Handlers.RTView.Update.Transactions
Cardano.Tracer.Handlers.RTView.Update.Utils

Cardano.Tracer.CLI
Cardano.Tracer.Configuration
Expand All @@ -60,6 +107,8 @@ library
, blaze-html
, blaze-markup
, bytestring
, cardano-git-rev
, cardano-node
, cborg
, containers
, contra-tracer
Expand All @@ -76,6 +125,7 @@ library
, snap-core
, snap-server
, stm
, string-qq
, text
, threepenny-gui
, time
Expand All @@ -87,6 +137,11 @@ library
if os(linux)
build-depends: libsystemd-journal

if os(windows)
build-depends: Win32
else
build-depends: unix

executable cardano-tracer
import: base, project-config

Expand Down
11 changes: 7 additions & 4 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Cardano.Tracer.Acceptors.Utils (prepareDataPointRequestor,
prepareMetricsStores, removeDisconnectedNode)
import qualified Cardano.Tracer.Configuration as TC
import Cardano.Tracer.Handlers.Logs.TraceObjects (traceObjectsHandler)
import Cardano.Tracer.Handlers.RTView.Run (SavedTraceObjects)
import Cardano.Tracer.Types (AcceptedMetrics, ConnectedNodes, DataPointRequestors)
import Cardano.Tracer.Utils (connIdToNodeId)

Expand All @@ -52,11 +53,12 @@ runAcceptorsClient
)
-> ConnectedNodes
-> AcceptedMetrics
-> SavedTraceObjects
-> DataPointRequestors
-> Lock
-> IO ()
runAcceptorsClient config p (ekgConfig, tfConfig, dpfConfig)
connectedNodes acceptedMetrics dpRequestors currentLogLock =
connectedNodes acceptedMetrics savedTO dpRequestors currentLogLock =
withIOManager $ \iocp ->
doConnectToForwarder
(localSnocket iocp)
Expand All @@ -67,7 +69,7 @@ runAcceptorsClient config p (ekgConfig, tfConfig, dpfConfig)
-- there is no mechanism to disable some of them.
appInitiator
[ (runEKGAcceptorInit ekgConfig connectedNodes acceptedMetrics errorHandler, 1)
, (runTraceObjectsAcceptorInit config tfConfig currentLogLock errorHandler, 2)
, (runTraceObjectsAcceptorInit config tfConfig currentLogLock savedTO errorHandler, 2)
, (runDataPointsAcceptorInit dpfConfig connectedNodes dpRequestors errorHandler, 3)
]
where
Expand Down Expand Up @@ -122,13 +124,14 @@ runTraceObjectsAcceptorInit
:: TC.TracerConfig
-> TF.AcceptorConfiguration TraceObject
-> Lock
-> SavedTraceObjects
-> (ConnectionId LocalAddress -> IO ())
-> ConnectionId LocalAddress
-> RunMiniProtocol 'InitiatorMode LBS.ByteString IO () Void
runTraceObjectsAcceptorInit config tfConfig currentLogLock errorHandler connId =
runTraceObjectsAcceptorInit config tfConfig currentLogLock savedTO errorHandler connId =
acceptTraceObjectsInit
tfConfig
(traceObjectsHandler config (connIdToNodeId connId) currentLogLock)
(traceObjectsHandler config (connIdToNodeId connId) currentLogLock savedTO)
(errorHandler connId)

runDataPointsAcceptorInit
Expand Down
8 changes: 5 additions & 3 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import qualified Trace.Forward.Protocol.TraceObject.Type as TOF
import Cardano.Tracer.Acceptors.Client (runAcceptorsClient)
import Cardano.Tracer.Acceptors.Server (runAcceptorsServer)
import Cardano.Tracer.Configuration
import Cardano.Tracer.Handlers.RTView.Run (SavedTraceObjects)
import Cardano.Tracer.Types (AcceptedMetrics, ConnectedNodes,
DataPointRequestors, ProtocolsBrake)
import Cardano.Tracer.Utils (runInLoop)
Expand All @@ -36,25 +37,26 @@ runAcceptors
:: TracerConfig
-> ConnectedNodes
-> AcceptedMetrics
-> SavedTraceObjects
-> DataPointRequestors
-> ProtocolsBrake
-> Lock
-> IO ()
runAcceptors c@TracerConfig{network, ekgRequestFreq, loRequestNum, verbosity}
connectedNodes acceptedMetrics dpRequestors stopIt currentLogLock =
connectedNodes acceptedMetrics savedTO dpRequestors stopIt currentLogLock =
case network of
AcceptAt (LocalSocket p) ->
-- Run one server that accepts connections from the nodes.
runInLoop
(runAcceptorsServer c p (acceptorsConfigs p) connectedNodes
acceptedMetrics dpRequestors currentLogLock)
acceptedMetrics savedTO dpRequestors currentLogLock)
verbosity p 1
ConnectTo localSocks ->
-- Run N clients that initiate connections to the nodes.
forConcurrently_ (NE.nub localSocks) $ \(LocalSocket p) ->
runInLoop
(runAcceptorsClient c p (acceptorsConfigs p) connectedNodes
acceptedMetrics dpRequestors currentLogLock)
acceptedMetrics savedTO dpRequestors currentLogLock)
verbosity p 1
where
acceptorsConfigs p =
Expand Down
13 changes: 8 additions & 5 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Cardano.Tracer.Acceptors.Utils (prepareDataPointRequestor,
prepareMetricsStores, removeDisconnectedNode)
import qualified Cardano.Tracer.Configuration as TC
import Cardano.Tracer.Handlers.Logs.TraceObjects (traceObjectsHandler)
import Cardano.Tracer.Handlers.RTView.Run (SavedTraceObjects)
import Cardano.Tracer.Types (AcceptedMetrics, ConnectedNodes, DataPointRequestors)
import Cardano.Tracer.Utils (connIdToNodeId)

Expand All @@ -55,11 +56,12 @@ runAcceptorsServer
)
-> ConnectedNodes
-> AcceptedMetrics
-> SavedTraceObjects
-> DataPointRequestors
-> Lock
-> IO ()
runAcceptorsServer config p (ekgConfig, tfConfig, dpfConfig)
connectedNodes acceptedMetrics dpRequestors currentLogLock = withIOManager $ \iocp ->
runAcceptorsServer config p (ekgConfig, tfConfig, dpfConfig) connectedNodes
acceptedMetrics savedTO dpRequestors currentLogLock = withIOManager $ \iocp ->
doListenToForwarder
(localSnocket iocp)
(localAddressFromPath p)
Expand All @@ -69,7 +71,7 @@ runAcceptorsServer config p (ekgConfig, tfConfig, dpfConfig)
-- there is no mechanism to disable some of them.
appResponder
[ (runEKGAcceptor ekgConfig connectedNodes acceptedMetrics errorHandler, 1)
, (runTraceObjectsAcceptor config tfConfig currentLogLock errorHandler, 2)
, (runTraceObjectsAcceptor config tfConfig currentLogLock savedTO errorHandler, 2)
, (runDataPointsAcceptor dpfConfig connectedNodes dpRequestors errorHandler, 3)
]
where
Expand Down Expand Up @@ -129,13 +131,14 @@ runTraceObjectsAcceptor
:: TC.TracerConfig
-> TF.AcceptorConfiguration TraceObject
-> Lock
-> SavedTraceObjects
-> (ConnectionId LocalAddress -> IO ())
-> ConnectionId LocalAddress
-> RunMiniProtocol 'ResponderMode LBS.ByteString IO Void ()
runTraceObjectsAcceptor config tfConfig currentLogLock errorHandler connId =
runTraceObjectsAcceptor config tfConfig currentLogLock savedTO errorHandler connId =
acceptTraceObjectsResp
tfConfig
(traceObjectsHandler config (connIdToNodeId connId) currentLogLock)
(traceObjectsHandler config (connIdToNodeId connId) currentLogLock savedTO)
(errorHandler connId)

runDataPointsAcceptor
Expand Down
27 changes: 17 additions & 10 deletions cardano-tracer/src/Cardano/Tracer/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ module Cardano.Tracer.CLI
import Options.Applicative

-- | CLI parameters required for the tracer.
newtype TracerParams = TracerParams
{ tracerConfig :: FilePath
data TracerParams = TracerParams
{ tracerConfig :: !FilePath
, checkMode :: !Bool
}

-- | Parse CLI parameters for the tracer.
parseTracerParams :: Parser TracerParams
parseTracerParams = TracerParams <$>
strOption
( long "config"
<> short 'c'
<> metavar "FILEPATH"
<> help "Configuration file for cardano-tracer"
<> completer (bashCompleter "file")
)
parseTracerParams = TracerParams
<$> strOption
( long "config"
<> short 'c'
<> metavar "FILEPATH"
<> help "Configuration file for cardano-tracer"
<> completer (bashCompleter "file")
)
<*> flag
False
True
( long "check-mode"
<> help "Run in check mode: shows all accepted stuff"
)
4 changes: 3 additions & 1 deletion cardano-tracer/src/Cardano/Tracer/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ data TracerConfig = TracerConfig
, ekgRequestFreq :: !(Maybe Pico) -- ^ How often to request for EKG-metrics, in seconds.
, hasEKG :: !(Maybe (Endpoint, Endpoint)) -- ^ Endpoint for EKG web-page (list of nodes, monitoring).
, hasPrometheus :: !(Maybe Endpoint) -- ^ Endpoint for Promeheus web-page.
, hasRTView :: !(Maybe Endpoint) -- ^ Endpoint for RTView web-page.
, logging :: !(NonEmpty LoggingParams) -- ^ Logging parameters.
, rotation :: !(Maybe RotationParams) -- ^ Rotation parameters.
, verbosity :: !(Maybe Verbosity) -- ^ Verbosity of the tracer itself.
Expand All @@ -103,7 +104,7 @@ readTracerConfig pathToConfig =
Right _ -> return config

checkMeaninglessValues :: TracerConfig -> Either String ()
checkMeaninglessValues TracerConfig{network, hasEKG, hasPrometheus, logging} =
checkMeaninglessValues TracerConfig{network, hasEKG, hasPrometheus, hasRTView, logging} =
if null problems
then Right ()
else Left $ intercalate ", " problems
Expand All @@ -115,6 +116,7 @@ checkMeaninglessValues TracerConfig{network, hasEKG, hasPrometheus, logging} =
, check "empty logRoot(s)" $ notNull . NE.filter invalidFileMode $ logging
, (check "no host(s) in hasEKG" . nullEndpoints) =<< hasEKG
, (check "no host in hasPrometheus" . nullEndpoint) =<< hasPrometheus
, (check "no host in hasRTView" . nullEndpoint) =<< hasRTView
]

check msg cond = if cond then Just msg else Nothing
Expand Down
42 changes: 42 additions & 0 deletions cardano-tracer/src/Cardano/Tracer/Handlers/CheckMode.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.Tracer.Handlers.CheckMode
( runChecker
) where

import Control.Concurrent.STM.TVar
import Control.Monad (forever, forM_, when)
import qualified Data.Map.Strict as M
import Debug.Trace (traceIO)
import System.Time.Extra (sleep)

import Cardano.Tracer.Handlers.Metrics.Utils
import Cardano.Tracer.Handlers.RTView.State.TraceObjects
import Cardano.Tracer.Types

-- | When 'cardano-tracer' is launched with '--check-mode' flag, it
-- prints out all 'EKG.Metrics' and 'TraceObject's it receives from
-- the node(s). We use it for debug purposes.
runChecker
:: Bool
-> AcceptedMetrics
-> SavedTraceObjects
-> IO ()
runChecker itIsCheckMode acceptedMetrics savedTO =
when itIsCheckMode doRunChecker
where
doRunChecker = forever $ do
allMetrics <- M.toList <$> readTVarIO acceptedMetrics
forM_ allMetrics $ \(nodeId, (ekgStore, _)) -> do
metrics <- getListOfMetrics ekgStore
traceIO "-----------------------"
traceIO $ "All metrics from " <> show nodeId <> ": " <> show metrics
traceIO "-----------------------"

allTraceObjects <- M.toList <$> readTVarIO savedTO
forM_ allTraceObjects $ \(nodeId, savedForNode) -> do
traceIO "***********************"
traceIO $ "All trace objects from " <> show nodeId <> ": " <> show savedForNode
traceIO "***********************"

sleep 1.0
Loading

0 comments on commit 9c97b64

Please sign in to comment.