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 23, 2022
1 parent 0f6a20d commit ecebefe
Show file tree
Hide file tree
Showing 59 changed files with 6,321 additions and 47 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
53 changes: 53 additions & 0 deletions cardano-tracer/cardano-tracer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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 +105,8 @@ library
, blaze-html
, blaze-markup
, bytestring
, cardano-git-rev
, cardano-node
, cborg
, containers
, contra-tracer
Expand All @@ -76,6 +123,7 @@ library
, snap-core
, snap-server
, stm
, string-qq
, text
, threepenny-gui
, time
Expand All @@ -87,6 +135,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
16 changes: 8 additions & 8 deletions cardano-tracer/src/Cardano/Tracer/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ newtype TracerParams = TracerParams

-- | 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")
)
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
18 changes: 12 additions & 6 deletions cardano-tracer/src/Cardano/Tracer/Handlers/Logs/TraceObjects.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@ module Cardano.Tracer.Handlers.Logs.TraceObjects

import Control.Concurrent.Async (forConcurrently_)
import Control.Concurrent.Extra (Lock)
import Control.Monad.Extra (whenJust)
import qualified Data.List.NonEmpty as NE

import Cardano.Logging (TraceObject)

import Cardano.Tracer.Configuration
import Cardano.Tracer.Handlers.Logs.File (writeTraceObjectsToFile)
import Cardano.Tracer.Handlers.Logs.Journal (writeTraceObjectsToJournal)
import Cardano.Tracer.Handlers.RTView.Run (SavedTraceObjects, saveTraceObjects)
import Cardano.Tracer.Types (NodeId)
import Cardano.Tracer.Utils (showProblemIfAny)

-- | This handler is called periodically by 'TraceObjectForward' protocol
-- from 'trace-forward' library.
traceObjectsHandler
:: TracerConfig -- ^ Tracer configuration.
-> NodeId -- ^ An id of the node 'TraceObject's were received from.
-> Lock -- ^ The lock we use for single-threaded access to the current log.
-> [TraceObject] -- ^ The list of received 'TraceObject's (may be empty).
:: TracerConfig -- ^ Tracer configuration.
-> NodeId -- ^ An id of the node 'TraceObject's were received from.
-> Lock -- ^ The lock we use for single-threaded access to the current log.
-> SavedTraceObjects -- ^ The buffer for accepted 'TraceObject's, used by RTView service.
-> [TraceObject] -- ^ The list of received 'TraceObject's (may be empty).
-> IO ()
traceObjectsHandler _ _ _ [] = return ()
traceObjectsHandler TracerConfig{logging, verbosity} nodeId currentLogLock traceObjects =
traceObjectsHandler _ _ _ _ [] = return ()
traceObjectsHandler TracerConfig{logging, verbosity, hasRTView}
nodeId currentLogLock savedTO traceObjects = do
forConcurrently_ (NE.nub logging) $ \LoggingParams{logMode, logRoot, logFormat} ->
showProblemIfAny verbosity $
case logMode of
FileMode -> writeTraceObjectsToFile nodeId currentLogLock logRoot logFormat traceObjects
JournalMode -> writeTraceObjectsToJournal nodeId traceObjects
whenJust hasRTView . const $
saveTraceObjects savedTO nodeId traceObjects
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Data.Text.Encoding (encodeUtf8)
import qualified Graphics.UI.Threepenny as UI
import Graphics.UI.Threepenny.Core (UI, Element, liftIO, set, (#), (#+))
import System.Remote.Monitoring (forkServerWith, serverThreadId)
import System.Time.Extra (sleep)

import Cardano.Tracer.Configuration (Endpoint (..))
import Cardano.Tracer.Types (AcceptedMetrics, ConnectedNodes, NodeId (..))
Expand All @@ -39,7 +40,9 @@ runMonitoringServer
-> ConnectedNodes
-> AcceptedMetrics
-> IO ()
runMonitoringServer (Endpoint listHost listPort, monitorEP) connectedNodes acceptedMetrics =
runMonitoringServer (Endpoint listHost listPort, monitorEP) connectedNodes acceptedMetrics = do
-- Pause to prevent collision between "Listening"-notifications from servers.
sleep 0.2
UI.startGUI config $ \window -> do
void $ return window # set UI.title "EKG Monitoring Nodes"
void $ mkPageBody window connectedNodes monitorEP acceptedMetrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ runPrometheusServer
-> AcceptedMetrics
-> IO ()
runPrometheusServer (Endpoint host port) connectedNodes acceptedMetrics = forever $ do
-- Pause to prevent collision between "Listening"-notifications from servers.
sleep 0.1
-- If everything is okay, the function 'simpleHttpServe' never returns.
-- But if there is some problem, it never throws an exception, but just stops.
-- So if it stopped - it will be re-started.
Expand Down
Loading

0 comments on commit ecebefe

Please sign in to comment.