Skip to content

Commit

Permalink
Make RTView conditional. Separate it behind the `RTVIEW' flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
Icelandjack committed Jul 3, 2024
1 parent 6fa77a9 commit 362ddf0
Show file tree
Hide file tree
Showing 38 changed files with 779 additions and 425 deletions.
6 changes: 5 additions & 1 deletion cardano-tracer/app/cardano-tracer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ main =
tracerInfo :: ParserInfo TracerParams
tracerInfo = info
(parseTracerParams <**> helper <**> versionOption)
(fullDesc <> header "cardano-tracer - the logging and monitoring service for Cardano nodes.")
#if RTVIEW
(fullDesc <> header "cardano-tracer/with RTView - the logging and monitoring service for Cardano nodes.")
#else
(fullDesc <> header "cardano-tracer/without RTView - the logging and monitoring service for Cardano nodes.")
#endif
versionOption = infoOption
(showVersion version)
(long "version" <>
Expand Down
65 changes: 40 additions & 25 deletions cardano-tracer/bench/cardano-tracer-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import Cardano.Logging hiding (LocalSocket)
import Cardano.Tracer.Configuration
import Cardano.Tracer.Environment
import Cardano.Tracer.Handlers.Logs.TraceObjects
#if RTVIEW
import Cardano.Tracer.Handlers.RTView.Run
import Cardano.Tracer.Handlers.RTView.State.Historical
#endif
import Cardano.Tracer.MetaTrace
import Cardano.Tracer.Types
import Cardano.Tracer.Utils

import Control.Concurrent.Extra (newLock)
#if RTVIEW
import Control.Concurrent.STM.TVar (newTVarIO)
#endif
import Control.DeepSeq
import qualified Data.List.NonEmpty as NE
import Data.Time.Clock (UTCTime, getCurrentTime)
Expand All @@ -36,61 +40,72 @@ main = do
connectedNodes <- initConnectedNodes
connectedNodesNames <- initConnectedNodesNames
acceptedMetrics <- initAcceptedMetrics
#if RTVIEW
savedTO <- initSavedTraceObjects

chainHistory <- initBlockchainHistory
resourcesHistory <- initResourcesHistory
txHistory <- initTransactionsHistory
#endif

protocolsBrake <- initProtocolsBrake
dpRequestors <- initDataPointRequestors

currentLogLock <- newLock
currentDPLock <- newLock
#if RTVIEW
eventsQueues <- initEventsQueues Nothing connectedNodesNames dpRequestors currentDPLock

rtViewPageOpened <- newTVarIO False
#endif

tr <- mkTracerTracer $ SeverityF $ Just Warning

let te :: TracerConfig -> HandleRegistry -> TracerEnv
te c r =
TracerEnv
{ teConfig = c
, teConnectedNodes = connectedNodes
, teConnectedNodesNames = connectedNodesNames
, teAcceptedMetrics = acceptedMetrics
, teSavedTO = savedTO
, teBlockchainHistory = chainHistory
, teResourcesHistory = resourcesHistory
, teTxHistory = txHistory
, teCurrentLogLock = currentLogLock
, teCurrentDPLock = currentDPLock
, teEventsQueues = eventsQueues
, teDPRequestors = dpRequestors
, teProtocolsBrake = protocolsBrake
, teRTViewPageOpened = rtViewPageOpened
, teRTViewStateDir = Nothing
, teTracer = tr
, teReforwardTraceObjects = \_-> pure ()
, teRegistry = r
}
let tracerEnv :: TracerConfig -> HandleRegistry -> TracerEnv
tracerEnv c r = TracerEnv
{ teConfig = c
, teConnectedNodes = connectedNodes
, teConnectedNodesNames = connectedNodesNames
, teAcceptedMetrics = acceptedMetrics
, teCurrentLogLock = currentLogLock
, teCurrentDPLock = currentDPLock
, teDPRequestors = dpRequestors
, teProtocolsBrake = protocolsBrake
, teTracer = tr
, teReforwardTraceObjects = \_-> pure ()
, teRegistry = r
, teStateDir = Nothing
}

tracerEnvRTView :: TracerEnvRTView
tracerEnvRTView = TracerEnvRTView
#if RTVIEW
{ teSavedTO = savedTO
, teBlockchainHistory = chainHistory
, teResourcesHistory = resourcesHistory
, teTxHistory = txHistory
, teEventsQueues = eventsQueues
, teRTViewPageOpened = rtViewPageOpened
}
#endif

removePathForcibly root

logTrace "hello"

let -- Handles cleanup between runs, closes handles before
myBench :: TracerConfig -> [TraceObject] -> Benchmarkable
myBench config traceObjects = let

action :: IO TracerEnv
action = te config <$> newRegistry
action = tracerEnv config <$> newRegistry

cleanup :: TracerEnv -> IO ()
cleanup TracerEnv{teRegistry} = clearRegistry teRegistry

benchmark :: TracerEnv -> IO ()
benchmark traceEnv = beforeProgramStops do
traceObjectsHandler traceEnv nId traceObjects
benchmark trEnv = beforeProgramStops do
traceObjectsHandler trEnv tracerEnvRTView nId traceObjects

in
perRunEnvWithCleanup @TracerEnv action cleanup benchmark
Expand Down
80 changes: 47 additions & 33 deletions cardano-tracer/cardano-tracer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ build-type: Simple
extra-doc-files: README.md
CHANGELOG.md

flag rtview
Description: Enable RTView
Manual: True
Default: False

common project-config
default-language: Haskell2010
build-depends: base >= 4.14 && < 5
Expand All @@ -27,8 +32,12 @@ common project-config
, ImportQualifiedPost
, InstanceSigs
, ScopedTypeVariables
, StandaloneKindSignatures
, TypeApplications

if flag(rtview)
CPP-Options: -DRTVIEW=1

ghc-options: -Wall
-Wcompat
-Wincomplete-record-updates
Expand All @@ -42,27 +51,11 @@ common project-config
library
import: project-config

hs-source-dirs: src

exposed-modules: Cardano.Tracer.Acceptors.Client
Cardano.Tracer.Acceptors.Run
Cardano.Tracer.Acceptors.Server
Cardano.Tracer.Acceptors.Utils

Cardano.Tracer.Handlers.Logs.File
Cardano.Tracer.Handlers.Logs.Journal
Cardano.Tracer.Handlers.Logs.Rotator
Cardano.Tracer.Handlers.Logs.TraceObjects
Cardano.Tracer.Handlers.Logs.Utils

Cardano.Tracer.Handlers.Metrics.Monitoring
Cardano.Tracer.Handlers.Metrics.Prometheus
Cardano.Tracer.Handlers.Metrics.Servers
Cardano.Tracer.Handlers.Metrics.Utils

Cardano.Tracer.Handlers.ReForwarder
hs-source-dirs: src

Cardano.Tracer.Handlers.RTView.Notifications.Check
if flag(rtview)
exposed-modules: Cardano.Tracer.Handlers.RTView.Notifications.Check
Cardano.Tracer.Handlers.RTView.Notifications.Email
Cardano.Tracer.Handlers.RTView.Notifications.Send
Cardano.Tracer.Handlers.RTView.Notifications.Settings
Expand All @@ -72,16 +65,11 @@ library

Cardano.Tracer.Handlers.RTView.Run

Cardano.Tracer.Handlers.RTView.SSL.Certs

Cardano.Tracer.Handlers.RTView.State.Displayed
Cardano.Tracer.Handlers.RTView.State.EraSettings
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
Expand Down Expand Up @@ -119,10 +107,27 @@ library
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.Handlers.RTView.Utils

exposed-modules: Cardano.Tracer.Acceptors.Client
Cardano.Tracer.Acceptors.Run
Cardano.Tracer.Acceptors.Server
Cardano.Tracer.Acceptors.Utils

Cardano.Tracer.Handlers.Logs.File
Cardano.Tracer.Handlers.Logs.Journal
Cardano.Tracer.Handlers.Logs.Rotator
Cardano.Tracer.Handlers.Logs.TraceObjects
Cardano.Tracer.Handlers.Logs.Utils

Cardano.Tracer.Handlers.Metrics.Monitoring
Cardano.Tracer.Handlers.Metrics.Prometheus
Cardano.Tracer.Handlers.Metrics.Servers
Cardano.Tracer.Handlers.Metrics.Utils

Cardano.Tracer.Handlers.ReForwarder

Cardano.Tracer.CLI
Cardano.Tracer.Configuration
Cardano.Tracer.Environment
Expand All @@ -131,48 +136,56 @@ library
Cardano.Tracer.Types
Cardano.Tracer.Utils

Cardano.Tracer.Handlers.RTView.SSL.Certs
Cardano.Tracer.Handlers.RTView.State.TraceObjects
Cardano.Tracer.Handlers.RTView.System
Cardano.Tracer.Handlers.RTView.Update.Utils

other-modules: Paths_cardano_tracer
autogen-modules: Paths_cardano_tracer

if flag(rtview)
build-depends:
cardano-git-rev ^>=0.2.2
, cassava
, cryptonite
, mime-mail
, smtp-mail == 0.3.0.0
, threepenny-gui
, vector

build-depends: aeson
, async
, async-extras
, bimap
, blaze-html
, bytestring
, cardano-git-rev ^>=0.2.2
, cardano-node
, cassava
, cborg
, containers
, contra-tracer
, cryptonite
, directory
, ekg
, ekg-core
, ekg-forward ^>= 0.5
, extra
, filepath
, mime-mail
, optparse-applicative
, ouroboros-network ^>= 0.16.1
, ouroboros-network-api
, ouroboros-network-framework
, signal
, smtp-mail == 0.3.0.0
, snap-blaze
, snap-core
, snap-server
, stm
, string-qq
, text
, threepenny-gui
, time
, trace-dispatcher
, trace-forward
, trace-resources
, unordered-containers
, vector
, yaml

if os(linux)
Expand Down Expand Up @@ -412,13 +425,14 @@ benchmark cardano-tracer-bench

main-is: cardano-tracer-bench.hs

if flag(rtview)
build-depends: stm
build-depends: cardano-tracer
, criterion
, directory
, deepseq
, extra
, filepath
, stm
, time
, trace-dispatcher

Expand Down
21 changes: 16 additions & 5 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ module Cardano.Tracer.Acceptors.Client
import Cardano.Logging (TraceObject)
import Cardano.Logging.Version (ForwardingVersion (..), ForwardingVersionData (..),
forwardingCodecCBORTerm, forwardingVersionCodec)
#if RTVIEW
import Cardano.Tracer.Acceptors.Utils (notifyAboutNodeDisconnected,
prepareDataPointRequestor, prepareMetricsStores, removeDisconnectedNode)
#else
import Cardano.Tracer.Acceptors.Utils (
prepareDataPointRequestor, prepareMetricsStores, removeDisconnectedNode)
#endif
import qualified Cardano.Tracer.Configuration as TC
import Cardano.Tracer.Environment
import Cardano.Tracer.Handlers.Logs.TraceObjects (deregisterNodeId, traceObjectsHandler)
Expand Down Expand Up @@ -45,13 +50,14 @@ import Trace.Forward.Run.TraceObject.Acceptor (acceptTraceObjectsInit)

runAcceptorsClient
:: TracerEnv
-> TracerEnvRTView
-> FilePath
-> ( EKGF.AcceptorConfiguration
, TF.AcceptorConfiguration TraceObject
, DPF.AcceptorConfiguration
)
-> IO ()
runAcceptorsClient tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager $ \iocp -> do
runAcceptorsClient tracerEnv tracerEnvRTView p (ekgConfig, tfConfig, dpfConfig) = withIOManager \iocp -> do
traceWith (teTracer tracerEnv) $ TracerSockConnecting p
doConnectToForwarder
(localSnocket iocp)
Expand All @@ -62,7 +68,8 @@ runAcceptorsClient tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager
-- there is no mechanism to disable some of them.
appInitiator
[ (runEKGAcceptorInit tracerEnv ekgConfig errorHandler, 1)
, (runTraceObjectsAcceptorInit tracerEnv tfConfig errorHandler, 2)
-- TODO: Double check if this has anything to do with RTView.
, (runTraceObjectsAcceptorInit tracerEnv tracerEnvRTView tfConfig errorHandler, 2)
, (runDataPointsAcceptorInit tracerEnv dpfConfig errorHandler, 3)
]
where
Expand All @@ -78,7 +85,10 @@ runAcceptorsClient tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager
errorHandler connId = do
deregisterNodeId tracerEnv (connIdToNodeId connId)
removeDisconnectedNode tracerEnv connId
notifyAboutNodeDisconnected tracerEnv connId
-- TODO: Double check if this has anything to do with RTView.
#if RTVIEW
notifyAboutNodeDisconnected tracerEnvRTView connId
#endif

doConnectToForwarder
:: Snocket IO LocalSocket LocalAddress
Expand Down Expand Up @@ -124,16 +134,17 @@ runEKGAcceptorInit tracerEnv ekgConfig errorHandler =

runTraceObjectsAcceptorInit
:: TracerEnv
-> TracerEnvRTView
-> TF.AcceptorConfiguration TraceObject
-> (ConnectionId LocalAddress -> IO ())
-> RunMiniProtocol 'InitiatorMode
(MinimalInitiatorContext LocalAddress)
responderCtx
LBS.ByteString IO () Void
runTraceObjectsAcceptorInit tracerEnv tfConfig errorHandler =
runTraceObjectsAcceptorInit tracerEnv tracerEnvRTView tfConfig errorHandler =
acceptTraceObjectsInit
tfConfig
(traceObjectsHandler tracerEnv . connIdToNodeId . micConnectionId)
(traceObjectsHandler tracerEnv tracerEnvRTView . connIdToNodeId . micConnectionId)
(errorHandler . micConnectionId)

runDataPointsAcceptorInit
Expand Down
Loading

0 comments on commit 362ddf0

Please sign in to comment.