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 Jun 27, 2024
1 parent ae8bc93 commit f013910
Show file tree
Hide file tree
Showing 38 changed files with 782 additions and 406 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
47 changes: 26 additions & 21 deletions cardano-tracer/bench/cardano-tracer-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ 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
Expand Down Expand Up @@ -54,27 +56,30 @@ main = do
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
}
te 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
{ teSavedTO = savedTO
, teBlockchainHistory = chainHistory
, teResourcesHistory = resourcesHistory
, teTxHistory = txHistory
, teEventsQueues = eventsQueues
, teRTViewPageOpened = rtViewPageOpened
}

removePathForcibly root

Expand Down
82 changes: 55 additions & 27 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 @@ -38,29 +47,18 @@ common project-config
-Wpartial-fields
-Wredundant-constraints
-Wunused-packages
-- TODO: temporary
-fno-warn-unused-imports

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
hs-source-dirs: src

Cardano.Tracer.Handlers.ReForwarder
if flag(rtview)
exposed-modules:
-- Cardano.Tracer.Handlers.Metrics.Monitoring

Cardano.Tracer.Handlers.RTView.Notifications.Check
Cardano.Tracer.Handlers.RTView.Notifications.Email
Expand All @@ -72,16 +70,16 @@ library

Cardano.Tracer.Handlers.RTView.Run

Cardano.Tracer.Handlers.RTView.SSL.Certs
-- 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.State.TraceObjects

Cardano.Tracer.Handlers.RTView.System
-- 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 +117,35 @@ 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.Update.Utils

Cardano.Tracer.Handlers.RTView.Utils

-- TODO: temporary
exposed-modules:
Cardano.Tracer.Handlers.RTView.SSL.Certs
Cardano.Tracer.Handlers.RTView.System
Cardano.Tracer.Handlers.RTView.State.TraceObjects


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,42 +154,47 @@ library
Cardano.Tracer.Types
Cardano.Tracer.Utils

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

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
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
12 changes: 6 additions & 6 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ import qualified Trace.Forward.Protocol.TraceObject.Type as TOF
-- There are two "network modes" for acceptors:
-- 1. Server mode, when the tracer accepts connections from any number of nodes.
-- 2. Client mode, when the tracer initiates connections to specified number of nodes.
runAcceptors :: TracerEnv -> IO ()
runAcceptors tracerEnv@TracerEnv{teTracer} = do
runAcceptors :: TracerEnv -> TracerEnvRTView -> IO ()
runAcceptors tracerEnv@TracerEnv{teTracer} tracerEnvRTView = do
traceWith teTracer $ TracerStartedAcceptors network
case network of
AcceptAt (LocalSocket p) ->
-- Run one server that accepts connections from the nodes.
runInLoop
(runAcceptorsServer tracerEnv p $ acceptorsConfigs p)
(runAcceptorsServer tracerEnv tracerEnvRTView p $ acceptorsConfigs p)
verbosity p initialPauseInSec
ConnectTo localSocks ->
-- Run N clients that initiate connections to the nodes.
forConcurrently_ (NE.nub localSocks) $ \(LocalSocket p) ->
runInLoop
(runAcceptorsClient tracerEnv p $ acceptorsConfigs p)
(runAcceptorsClient tracerEnv tracerEnvRTView p $ acceptorsConfigs p)
verbosity p initialPauseInSec
where
TracerConfig{network, ekgRequestFreq, loRequestNum, verbosity} = teConfig tracerEnv
TracerConfig{network, ekgRequestFreq, verbosity} = teConfig tracerEnv

acceptorsConfigs p =
( EKGF.AcceptorConfiguration
Expand All @@ -58,7 +58,7 @@ runAcceptors tracerEnv@TracerEnv{teTracer} = do
, TOF.AcceptorConfiguration
{ TOF.acceptorTracer = mkVerbosity verbosity
, TOF.forwarderEndpoint = p
, TOF.whatToRequest = TOF.NumberOfTraceObjects $ fromMaybe 100 loRequestNum
, TOF.whatToRequest = TOF.NumberOfTraceObjects $ fromMaybe 100 (loRequestNum (teConfig tracerEnv))
, TOF.shouldWeStop = teProtocolsBrake tracerEnv
}
, DPF.AcceptorConfiguration
Expand Down
Loading

0 comments on commit f013910

Please sign in to comment.