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 May 29, 2024
1 parent 9ed9aca commit ddb1936
Show file tree
Hide file tree
Showing 32 changed files with 522 additions and 310 deletions.
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
67 changes: 46 additions & 21 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: True

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

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

Cardano.Tracer.Handlers.RTView.Update.Utils

other-modules: Paths_cardano_tracer
autogen-modules: Paths_cardano_tracer

Expand Down
34 changes: 29 additions & 5 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ 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
-- #if RTVIEW
import Cardano.Tracer.Handlers.Logs.TraceObjects (deregisterNodeId, traceObjectsHandler)
-- #else
-- import Cardano.Tracer.Handlers.Logs.TraceObjects (deregisterNodeId)
-- #endif
import Cardano.Tracer.MetaTrace
import Cardano.Tracer.Utils (connIdToNodeId)
import Ouroboros.Network.Context (MinimalInitiatorContext (..), ResponderContext (..))
Expand Down Expand Up @@ -41,17 +50,22 @@ import System.Metrics.Network.Acceptor (acceptEKGMetricsInit)
import qualified Trace.Forward.Configuration.DataPoint as DPF
import qualified Trace.Forward.Configuration.TraceObject as TF
import Trace.Forward.Run.DataPoint.Acceptor (acceptDataPointsInit)
-- #if RTVIEW
import Trace.Forward.Run.TraceObject.Acceptor (acceptTraceObjectsInit)
-- #endif

runAcceptorsClient
:: TracerEnv
-> TracerEnvRTView
-> FilePath
-> ( EKGF.AcceptorConfiguration
-- #if RTVIEW
, TF.AcceptorConfiguration TraceObject
-- #endif
, 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 +76,10 @@ 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.
-- #if RTVIEW
, (runTraceObjectsAcceptorInit tracerEnv tracerEnvRTView tfConfig errorHandler, 2)
-- #endif
, (runDataPointsAcceptorInit tracerEnv dpfConfig errorHandler, 3)
]
where
Expand All @@ -78,7 +95,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 @@ -122,19 +142,23 @@ runEKGAcceptorInit tracerEnv ekgConfig errorHandler =
(prepareMetricsStores tracerEnv . micConnectionId)
(errorHandler . micConnectionId)

-- TODO: Double check if this has anything to do with RTView.
-- #if RTVIEW
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)
-- #endif

runDataPointsAcceptorInit
:: TracerEnv
Expand Down
16 changes: 10 additions & 6 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,33 @@ import qualified System.Metrics.Configuration as EKGF
import qualified System.Metrics.ReqResp as EKGF

import qualified Trace.Forward.Configuration.DataPoint as DPF
-- #if RTVIEW
import qualified Trace.Forward.Configuration.TraceObject as TOF
import qualified Trace.Forward.Protocol.TraceObject.Type as TOF
-- #endif

-- | Run acceptors for all supported protocols.
--
-- 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 @@ -55,12 +57,14 @@ runAcceptors tracerEnv@TracerEnv{teTracer} = do
, EKGF.whatToRequest = EKGF.GetAllMetrics
, EKGF.shouldWeStop = teProtocolsBrake tracerEnv
}
-- #if RTVIEW
, 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
}
-- #endif
, DPF.AcceptorConfiguration
{ DPF.acceptorTracer = mkVerbosity verbosity
, DPF.forwarderEndpoint = p
Expand Down
Loading

0 comments on commit ddb1936

Please sign in to comment.